Clean up
This commit is contained in:
parent
7a26e8b91e
commit
fbc42d972b
@ -5,11 +5,6 @@ VisualStudioVersion = 16.0.32802.440
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spy", "spy\spy.vcxproj", "{4DE80B82-5F6A-4C4C-9D16-1574308110FA}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp", "cpp\cpp.vcxproj", "{2FC45612-A106-42D1-871F-1DE704095B2C}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{ABFCB647-137F-478B-A73E-F0B1E3ADC215} = {ABFCB647-137F-478B-A73E-F0B1E3ADC215}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdk", "sdk\sdk.vcxproj", "{ABFCB647-137F-478B-A73E-F0B1E3ADC215}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{4DE80B82-5F6A-4C4C-9D16-1574308110FA} = {4DE80B82-5F6A-4C4C-9D16-1574308110FA}
|
||||
@ -27,8 +22,6 @@ Global
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4DE80B82-5F6A-4C4C-9D16-1574308110FA}.Release|x86.ActiveCfg = Release|Win32
|
||||
{4DE80B82-5F6A-4C4C-9D16-1574308110FA}.Release|x86.Build.0 = Release|Win32
|
||||
{2FC45612-A106-42D1-871F-1DE704095B2C}.Release|x86.ActiveCfg = Release|Win32
|
||||
{2FC45612-A106-42D1-871F-1DE704095B2C}.Release|x86.Build.0 = Release|Win32
|
||||
{ABFCB647-137F-478B-A73E-F0B1E3ADC215}.Release|x86.ActiveCfg = Release|Win32
|
||||
{ABFCB647-137F-478B-A73E-F0B1E3ADC215}.Release|x86.Build.0 = Release|Win32
|
||||
{B11ADC6F-20DA-4DEF-A8A0-60374427D4C6}.Release|x86.ActiveCfg = Release|Win32
|
||||
|
177
cpp/cpp.vcxproj
177
cpp/cpp.vcxproj
@ -1,177 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{2fc45612-a106-42d1-871f-1de704095b2c}</ProjectGuid>
|
||||
<RootNamespace>cpp</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<VcpkgUseStatic>true</VcpkgUseStatic>
|
||||
<VcpkgTriplet>x86-windows-static</VcpkgTriplet>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)/spy;$(SolutionDir)/rpc;C:\Tools\vcpkg\installed\x86-windows-static\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>$(OutDir)sdk.lib;iphlpapi.lib;wsock32.lib;ws2_32.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy /y $(OutDir)cpp.exe $(OutDir)out\cpp</Command>
|
||||
</PostBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Message>Copy files</Message>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\rpc\nanopb\pb.h" />
|
||||
<ClInclude Include="..\rpc\nanopb\pb_common.h" />
|
||||
<ClInclude Include="..\rpc\nanopb\pb_decode.h" />
|
||||
<ClInclude Include="..\rpc\nanopb\pb_encode.h" />
|
||||
<ClInclude Include="..\rpc\proto\wcf.pb.h" />
|
||||
<ClInclude Include="..\sdk\sdk.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\rpc\nanopb\pb_common.c" />
|
||||
<ClCompile Include="..\rpc\nanopb\pb_decode.c" />
|
||||
<ClCompile Include="..\rpc\nanopb\pb_encode.c" />
|
||||
<ClCompile Include="..\rpc\proto\wcf.pb.c" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\rpc\proto\wcf.proto" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="nnrpc">
|
||||
<UniqueIdentifier>{985fabc8-364a-4c12-ac0a-b9386288565a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\sdk\sdk.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\rpc\nanopb\pb.h">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\rpc\nanopb\pb_common.h">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\rpc\nanopb\pb_decode.h">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\rpc\nanopb\pb_encode.h">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\rpc\proto\wcf.pb.h">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\rpc\nanopb\pb_common.c">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\rpc\nanopb\pb_decode.c">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\rpc\nanopb\pb_encode.c">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\rpc\proto\wcf.pb.c">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\rpc\proto\wcf.proto">
|
||||
<Filter>nnrpc</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
527
cpp/main.cpp
527
cpp/main.cpp
@ -1,527 +0,0 @@
|
||||
/*
|
||||
RPC Client
|
||||
*/
|
||||
#pragma warning(disable : 4251)
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
#include <memory>
|
||||
#include <signal.h>
|
||||
#include <thread>
|
||||
#if 0
|
||||
#include <grpcpp/grpcpp.h>
|
||||
|
||||
#include "../proto/wcf.grpc.pb.h"
|
||||
#include "../sdk/sdk.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using grpc::Channel;
|
||||
using grpc::ClientContext;
|
||||
using grpc::Status;
|
||||
|
||||
using wcf::Contact;
|
||||
using wcf::Contacts;
|
||||
using wcf::DbField;
|
||||
using wcf::DbNames;
|
||||
using wcf::DbQuery;
|
||||
using wcf::DbRow;
|
||||
using wcf::DbRows;
|
||||
using wcf::DbTable;
|
||||
using wcf::DbTables;
|
||||
using wcf::Empty;
|
||||
using wcf::ImageMsg;
|
||||
using wcf::MsgTypes;
|
||||
using wcf::Response;
|
||||
using wcf::String;
|
||||
using wcf::TextMsg;
|
||||
using wcf::Verification;
|
||||
using wcf::Wcf;
|
||||
using wcf::WxMsg;
|
||||
|
||||
class WcfClient
|
||||
{
|
||||
public:
|
||||
static WcfClient &Instance(string host_port)
|
||||
{
|
||||
static WcfClient instance(grpc::CreateChannel(host_port, grpc::InsecureChannelCredentials()));
|
||||
return instance;
|
||||
}
|
||||
|
||||
~WcfClient()
|
||||
{
|
||||
cout << "~WcfClient()" << endl;
|
||||
this->DisableRecvMsg();
|
||||
WxDestroySDK();
|
||||
}
|
||||
|
||||
int IsLogin()
|
||||
{
|
||||
Empty empty;
|
||||
Response rsp;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
stub_->async()->RpcIsLogin(&context, &empty, &rsp, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "IsLogin rpc failed." << endl;
|
||||
}
|
||||
|
||||
return rsp.status();
|
||||
}
|
||||
|
||||
string GetSelfWxid()
|
||||
{
|
||||
Empty empty;
|
||||
String rsp;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
stub_->async()->RpcGetSelfWxid(&context, &empty, &rsp, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "GetSelfWxid rpc failed." << endl;
|
||||
}
|
||||
|
||||
return rsp.str();
|
||||
}
|
||||
|
||||
void EnableRecvMsg(function<void(WxMsg &)> msg_handle_cb)
|
||||
{
|
||||
class Reader : public grpc::ClientReadReactor<WxMsg>
|
||||
{
|
||||
public:
|
||||
Reader(Wcf::Stub *stub, function<void(WxMsg &)> msg_handle_cb)
|
||||
: msg_handle_cb_(msg_handle_cb)
|
||||
{
|
||||
stub->async()->RpcEnableRecvMsg(&context_, &empty_, this);
|
||||
StartRead(&msg_);
|
||||
StartCall();
|
||||
}
|
||||
|
||||
void OnReadDone(bool ok) override
|
||||
{
|
||||
if (ok) {
|
||||
try {
|
||||
msg_handle_cb_(msg_);
|
||||
} catch (...) {
|
||||
cout << "OnMsg wrong..." << endl;
|
||||
}
|
||||
StartRead(&msg_);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDone(const Status &s) override
|
||||
{
|
||||
unique_lock<mutex> l(mu_);
|
||||
status_ = s;
|
||||
done_ = true;
|
||||
cv_.notify_one();
|
||||
}
|
||||
|
||||
Status Await()
|
||||
{
|
||||
unique_lock<mutex> l(mu_);
|
||||
cv_.wait(l, [this] { return done_; });
|
||||
return move(status_);
|
||||
}
|
||||
|
||||
private:
|
||||
Empty empty_;
|
||||
WxMsg msg_;
|
||||
ClientContext context_;
|
||||
|
||||
mutex mu_;
|
||||
Status status_;
|
||||
bool done_ = false;
|
||||
condition_variable cv_;
|
||||
|
||||
function<void(WxMsg &)> msg_handle_cb_;
|
||||
};
|
||||
|
||||
Reader reader(stub_.get(), msg_handle_cb);
|
||||
Status status = reader.Await();
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "GetMessage rpc failed." << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int DisableRecvMsg()
|
||||
{
|
||||
Empty empty;
|
||||
Response rsp;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
stub_->async()->RpcDisableRecvMsg(&context, &empty, &rsp, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "DisableRecvMsg rpc failed." << endl;
|
||||
}
|
||||
|
||||
return rsp.status();
|
||||
}
|
||||
|
||||
int SendTextMsg(string msg, string receiver, string atusers)
|
||||
{
|
||||
Response rsp;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
TextMsg t_msg;
|
||||
t_msg.set_msg(msg);
|
||||
t_msg.set_receiver(receiver);
|
||||
t_msg.set_aters(atusers);
|
||||
|
||||
stub_->async()->RpcSendTextMsg(&context, &t_msg, &rsp, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "SendTextMsg rpc failed." << endl;
|
||||
rsp.set_status(-999); // TODO: Unify error code
|
||||
}
|
||||
|
||||
return rsp.status();
|
||||
}
|
||||
|
||||
int SendImageMsg(string path, string receiver)
|
||||
{
|
||||
Response rsp;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
ImageMsg i_msg;
|
||||
i_msg.set_path(path);
|
||||
i_msg.set_receiver(receiver);
|
||||
|
||||
stub_->async()->RpcSendImageMsg(&context, &i_msg, &rsp, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "SendImageMsg rpc failed." << endl;
|
||||
rsp.set_status(-999); // TODO: Unify error code
|
||||
}
|
||||
|
||||
return rsp.status();
|
||||
}
|
||||
|
||||
MsgTypes GetMsgTypes(void)
|
||||
{
|
||||
Empty empty;
|
||||
MsgTypes mt;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
stub_->async()->RpcGetMsgTypes(&context, &empty, &mt, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "GetMsgTypes rpc failed." << endl;
|
||||
}
|
||||
|
||||
return mt;
|
||||
}
|
||||
|
||||
Contacts GetContacts(void)
|
||||
{
|
||||
Empty empty;
|
||||
Contacts contacts;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
stub_->async()->RpcGetContacts(&context, &empty, &contacts, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "GetContacts rpc failed." << endl;
|
||||
}
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
DbNames GetDbNames(void)
|
||||
{
|
||||
Empty empty;
|
||||
DbNames names;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
stub_->async()->RpcGetDbNames(&context, &empty, &names, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "GetDbNames rpc failed." << endl;
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
DbTables GetDbTables(string db)
|
||||
{
|
||||
DbTables tables;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
String s_db;
|
||||
s_db.set_str(db);
|
||||
|
||||
stub_->async()->RpcGetDbTables(&context, &s_db, &tables, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "GetDbTables rpc failed." << endl;
|
||||
}
|
||||
|
||||
return tables;
|
||||
}
|
||||
|
||||
DbRows ExecDbQuery(string db, string sql)
|
||||
{
|
||||
DbRows rows;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
DbQuery query;
|
||||
query.set_db(db);
|
||||
query.set_sql(sql);
|
||||
|
||||
stub_->async()->RpcExecDbQuery(&context, &query, &rows, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "ExecDbQuery rpc failed." << endl;
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
int AcceptNewFriend(string v3, string v4)
|
||||
{
|
||||
Response rsp;
|
||||
ClientContext context;
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool done = false;
|
||||
Status status;
|
||||
|
||||
Verification v;
|
||||
v.set_v3(v3);
|
||||
v.set_v4(v4);
|
||||
|
||||
stub_->async()->RpcAcceptNewFriend(&context, &v, &rsp, [&mu, &cv, &done, &status](Status s) {
|
||||
status = std::move(s);
|
||||
std::lock_guard<std::mutex> lock(mu);
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(mu);
|
||||
cv.wait(lock, [&done] { return done; });
|
||||
|
||||
if (!status.ok()) {
|
||||
cout << "ExecDbQuery rpc failed." << endl;
|
||||
rsp.set_status(-999); // TODO: Unify error code
|
||||
}
|
||||
|
||||
return rsp.status();
|
||||
}
|
||||
|
||||
private:
|
||||
unique_ptr<Wcf::Stub> stub_;
|
||||
WcfClient(shared_ptr<Channel> channel)
|
||||
: stub_(Wcf::NewStub(channel))
|
||||
{
|
||||
WxInitSDK();
|
||||
}
|
||||
};
|
||||
|
||||
int OnMsg(WxMsg msg)
|
||||
{
|
||||
cout << "Got Message: \n"
|
||||
<< msg.is_self() << ", " << msg.is_group() << ", " << msg.type() << ", " << msg.id() << ", " << msg.xml()
|
||||
<< ", " << msg.sender() << ", " << msg.roomid() << ", " << msg.content() << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
volatile sig_atomic_t gStop;
|
||||
void handler(int s)
|
||||
{
|
||||
cout << "Ctrl + C" << endl;
|
||||
gStop = 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
signal(SIGINT, handler);
|
||||
|
||||
WcfClient &client = WcfClient::Instance("localhost:10086");
|
||||
|
||||
cout << "IsLogin: " << client.IsLogin() << endl;
|
||||
cout << "Self Wxid: " << client.GetSelfWxid() << endl;
|
||||
|
||||
ret = client.SendTextMsg("来自CPP的消息!", "filehelper", "");
|
||||
cout << "SendTextMsg: " << ret << endl;
|
||||
|
||||
ret = client.SendImageMsg("TEQuant.jpeg", "filehelper");
|
||||
cout << "SendImageMsg: " << ret << endl;
|
||||
|
||||
MsgTypes mts = client.GetMsgTypes();
|
||||
cout << "GetMsgTypes: " << mts.types_size() << endl;
|
||||
map<int32_t, string> m(mts.types().begin(), mts.types().end());
|
||||
for (auto &[k, v] : m) {
|
||||
cout << k << ": " << v << endl;
|
||||
}
|
||||
|
||||
Contacts cnts = client.GetContacts();
|
||||
cout << "GetContacts: " << cnts.contacts().size() << endl;
|
||||
vector<Contact> vcnts(cnts.contacts().begin(), cnts.contacts().end());
|
||||
for (auto &c : vcnts) {
|
||||
string gender = "";
|
||||
if (c.gender() == 1) {
|
||||
gender = "男";
|
||||
} else if (c.gender() == 2) {
|
||||
gender = "女";
|
||||
}
|
||||
cout << c.wxid() << "\t" << c.code() << "\t" << c.name() << "\t" << c.country() << "\t" << c.province() << "\t"
|
||||
<< c.city() << "\t" << gender << endl;
|
||||
}
|
||||
|
||||
DbNames db = client.GetDbNames();
|
||||
cout << "GetDbNames: " << db.names().size() << endl;
|
||||
vector<string> dbs(db.names().begin(), db.names().end());
|
||||
for (auto &name : dbs) {
|
||||
cout << name << endl;
|
||||
}
|
||||
|
||||
DbTables tbls = client.GetDbTables("db");
|
||||
cout << "GetDbTables: " << tbls.tables().size() << endl;
|
||||
vector<DbTable> vtbls(tbls.tables().begin(), tbls.tables().end());
|
||||
for (auto &tbl : vtbls) {
|
||||
cout << tbl.name() << "\n" << tbl.sql() << endl;
|
||||
}
|
||||
|
||||
DbRows r = client.ExecDbQuery("MicroMsg.db", "SELECT * FROM Contact LIMIT 1;");
|
||||
cout << "ExecDbQuery: " << r.rows().size() << endl;
|
||||
vector<DbRow> vrows(r.rows().begin(), r.rows().end());
|
||||
for (auto &row : vrows) {
|
||||
vector<DbField> vfields(row.fields().begin(), row.fields().end());
|
||||
for (auto &field : vfields)
|
||||
cout << field.column() << "[" << field.type() << "]: " << field.content() << endl;
|
||||
}
|
||||
|
||||
// 需要正确的 v3、v4 才能调用
|
||||
// ret = client.AcceptNewFriend("v3", "v4");
|
||||
// cout << "AcceptNewFriend: " << ret << endl;
|
||||
|
||||
function<void(WxMsg &)> cb = OnMsg;
|
||||
thread t1 = thread([&]() { client.EnableRecvMsg(cb); });
|
||||
|
||||
while (!gStop) {
|
||||
Sleep(1000);
|
||||
}
|
||||
|
||||
cout << "Cleanup" << endl;
|
||||
client.DisableRecvMsg();
|
||||
|
||||
system("pause");
|
||||
client.~WcfClient();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
int main() { return 0; }
|
@ -1,13 +0,0 @@
|
||||
# WeChatFerry Java 客户端
|
||||
## 配置环境
|
||||
选择 32 位的 JDK [temurin](https://adoptium.net/zh-CN/temurin/releases)。
|
||||
|
||||
## 重新生成 gRPC 文件
|
||||
[gRPC 文件生成工具](https://repo.maven.apache.org/maven2/io/grpc/protoc-gen-grpc-java/)。
|
||||
```sh
|
||||
cd java/src/main/java/
|
||||
protoc --java_out=. -I=../../../../proto wcf.proto
|
||||
protoc --grpc-java_out=. --plugin=protoc-gen-grpc-java="C:/Tools/bin/protoc-gen-grpc-java-1.49.2-windows-x86_32.exe" -I=../../../../proto wcf.proto
|
||||
```
|
||||
|
||||
`C:/Tools/bin` 为工具存放路径。
|
77
java/pom.xml
77
java/pom.xml
@ -1,77 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.iamteer.wcf</groupId>
|
||||
<artifactId>WeChatFerry</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>kr.motd.maven</groupId>
|
||||
<artifactId>os-maven-plugin</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.xolstice.maven.plugins</groupId>
|
||||
<artifactId>protobuf-maven-plugin</artifactId>
|
||||
<version>0.6.1</version>
|
||||
<configuration>
|
||||
<protocArtifact>com.google.protobuf:protoc:3.21.7:exe:${os.detected.classifier}</protocArtifact>
|
||||
<pluginId>grpc-java</pluginId>
|
||||
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.50.0:exe:${os.detected.classifier}</pluginArtifact>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>compile-custom</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>5.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-netty-shaded</artifactId>
|
||||
<version>1.50.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-protobuf</artifactId>
|
||||
<version>1.50.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-stub</artifactId>
|
||||
<version>1.50.0</version>
|
||||
</dependency>
|
||||
<dependency> <!-- necessary for Java 9+ -->
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>annotations-api</artifactId>
|
||||
<version>6.0.53</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,144 +0,0 @@
|
||||
package com.iamteer.wcf;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
|
||||
public class Client {
|
||||
private interface JnaLibrary extends Library {
|
||||
JnaLibrary INSTANCE = Native.load("sdk", JnaLibrary.class);
|
||||
|
||||
void WxInitSDK();
|
||||
|
||||
void WxDestroySDK();
|
||||
}
|
||||
|
||||
public void InitClient(String hostPort) {
|
||||
JnaLibrary.INSTANCE.WxInitSDK();
|
||||
this.connect(hostPort);
|
||||
}
|
||||
|
||||
public void CleanupClient() {
|
||||
this.DisableRecvMsg();
|
||||
JnaLibrary.INSTANCE.WxDestroySDK();
|
||||
}
|
||||
|
||||
private void connect(String hostPort) {
|
||||
ManagedChannel managedChannel = ManagedChannelBuilder.forTarget(hostPort)
|
||||
.usePlaintext()
|
||||
.build();
|
||||
this.wcfBlokingStub = WcfGrpc.newBlockingStub(managedChannel);
|
||||
this.wcfStub = WcfGrpc.newStub(managedChannel);
|
||||
}
|
||||
|
||||
public int IsLogin() {
|
||||
WcfOuterClass.Empty empty = WcfOuterClass.Empty.newBuilder().build();
|
||||
WcfOuterClass.Response response = this.wcfBlokingStub.rpcIsLogin(empty);
|
||||
return response.getStatus();
|
||||
}
|
||||
|
||||
public String GetSelfWxid() {
|
||||
WcfOuterClass.Empty empty = WcfOuterClass.Empty.newBuilder().build();
|
||||
WcfOuterClass.String rsp = this.wcfBlokingStub.rpcGetSelfWxid(empty);
|
||||
return rsp.getStr();
|
||||
}
|
||||
|
||||
public void EnableRecvMsg() {
|
||||
if (isReceivingMsg) {
|
||||
return;
|
||||
}
|
||||
|
||||
isReceivingMsg = true;
|
||||
WcfOuterClass.Empty empty = WcfOuterClass.Empty.newBuilder().build();
|
||||
this.wcfStub.rpcEnableRecvMsg(empty, new StreamObserver<WcfOuterClass.WxMsg>() {
|
||||
@Override
|
||||
public void onNext(WcfOuterClass.WxMsg value) {
|
||||
System.out.printf("New Message:\n%s", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
System.err.println("EnableRecvMsg Error");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
System.out.println("EnableRecvMsg Complete");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int DisableRecvMsg() {
|
||||
if (!isReceivingMsg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
WcfOuterClass.Empty empty = WcfOuterClass.Empty.newBuilder().build();
|
||||
WcfOuterClass.Response response = this.wcfBlokingStub.rpcDisableRecvMsg(empty);
|
||||
if (response.getStatus() == 0) {
|
||||
isReceivingMsg = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int SendText(String msg, String receiver, String aters) {
|
||||
WcfOuterClass.TextMsg textMsg = WcfOuterClass.TextMsg.newBuilder().setMsg(msg).setReceiver(receiver)
|
||||
.setAters(aters).build();
|
||||
WcfOuterClass.Response response = this.wcfBlokingStub.rpcSendTextMsg(textMsg);
|
||||
return response.getStatus();
|
||||
}
|
||||
|
||||
public int SendImage(String path, String receiver) {
|
||||
WcfOuterClass.ImageMsg imageMsg = WcfOuterClass.ImageMsg.newBuilder().setPath(path).setReceiver(receiver)
|
||||
.build();
|
||||
WcfOuterClass.Response response = this.wcfBlokingStub.rpcSendImageMsg(imageMsg);
|
||||
return response.getStatus();
|
||||
}
|
||||
|
||||
public Map<Integer, String> GetMsgTypes() {
|
||||
WcfOuterClass.Empty empty = WcfOuterClass.Empty.newBuilder().build();
|
||||
WcfOuterClass.MsgTypes msgTypes = this.wcfBlokingStub.rpcGetMsgTypes(empty);
|
||||
return msgTypes.getTypesMap();
|
||||
}
|
||||
|
||||
public List<WcfOuterClass.Contact> GetContacts() {
|
||||
WcfOuterClass.Empty empty = WcfOuterClass.Empty.newBuilder().build();
|
||||
WcfOuterClass.Contacts contacts = this.wcfBlokingStub.rpcGetContacts(empty);
|
||||
return contacts.getContactsList();
|
||||
}
|
||||
|
||||
public List<String> GetDbs() {
|
||||
WcfOuterClass.Empty empty = WcfOuterClass.Empty.newBuilder().build();
|
||||
WcfOuterClass.DbNames dbs = this.wcfBlokingStub.rpcGetDbNames(empty);
|
||||
return dbs.getNamesList();
|
||||
}
|
||||
|
||||
public List<WcfOuterClass.DbTable> GetTables(String db) {
|
||||
WcfOuterClass.String str = WcfOuterClass.String.newBuilder().setStr(db).build();
|
||||
WcfOuterClass.DbTables tables = this.wcfBlokingStub.rpcGetDbTables(str);
|
||||
return tables.getTablesList();
|
||||
}
|
||||
|
||||
public List<WcfOuterClass.DbRow> QuerySql(String db, String sql) {
|
||||
WcfOuterClass.DbQuery query = WcfOuterClass.DbQuery.newBuilder().setDb(db).setSql(sql).build();
|
||||
WcfOuterClass.DbRows rows = this.wcfBlokingStub.rpcExecDbQuery(query);
|
||||
return rows.getRowsList();
|
||||
}
|
||||
|
||||
public int AcceptNewFriend(String v3, String v4) {
|
||||
WcfOuterClass.Verification v = WcfOuterClass.Verification.newBuilder().setV3(v3).setV4(v4).build();
|
||||
WcfOuterClass.Response response = this.wcfBlokingStub.rpcAcceptNewFriend(v);
|
||||
return response.getStatus();
|
||||
}
|
||||
|
||||
private boolean isReceivingMsg = false;
|
||||
private WcfGrpc.WcfBlockingStub wcfBlokingStub;
|
||||
private WcfGrpc.WcfStub wcfStub;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package com.iamteer.wcf;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String hostPort = "localhost:10086";
|
||||
Client client = new Client();
|
||||
client.InitClient(hostPort);
|
||||
System.out.println("Connecting to " + hostPort);
|
||||
|
||||
int status = client.IsLogin();
|
||||
System.out.println(status);
|
||||
|
||||
String wxid = client.GetSelfWxid();
|
||||
System.out.println(wxid);
|
||||
|
||||
client.EnableRecvMsg(); // Receive Message
|
||||
|
||||
Map<Integer, String> msgTypes = client.GetMsgTypes();
|
||||
Iterator<Map.Entry<Integer, String>> iterTypes = msgTypes.entrySet().iterator();
|
||||
while (iterTypes.hasNext()) {
|
||||
Map.Entry<Integer, String> entry = iterTypes.next();
|
||||
System.out.println(entry.getKey() + ": " + entry.getValue());
|
||||
}
|
||||
|
||||
List<WcfOuterClass.Contact> contacts = client.GetContacts();
|
||||
Iterator<WcfOuterClass.Contact> iterContacts = contacts.iterator();
|
||||
while (iterContacts.hasNext()) {
|
||||
WcfOuterClass.Contact contact = iterContacts.next();
|
||||
System.out.println(contact);
|
||||
}
|
||||
|
||||
List<String> dbs = client.GetDbs();
|
||||
Iterator<String> iterDbs = dbs.iterator();
|
||||
while (iterDbs.hasNext()) {
|
||||
String db = iterDbs.next();
|
||||
System.out.println(db);
|
||||
}
|
||||
|
||||
List<WcfOuterClass.DbTable> tables = client.GetTables("MicroMsg.db");
|
||||
Iterator<WcfOuterClass.DbTable> iterTables = tables.iterator();
|
||||
while (iterTables.hasNext()) {
|
||||
WcfOuterClass.DbTable table = iterTables.next();
|
||||
System.out.println(table);
|
||||
}
|
||||
|
||||
List<WcfOuterClass.DbRow> rows = client.QuerySql("MicroMsg.db", "SELECT * FROM Contact LIMIT 1;");
|
||||
Iterator<WcfOuterClass.DbRow> iterRows = rows.iterator();
|
||||
while (iterRows.hasNext()) {
|
||||
WcfOuterClass.DbRow row = iterRows.next();
|
||||
System.out.println(row);
|
||||
}
|
||||
|
||||
// status = client.AcceptNewFriend("v3", "v4"); // 需要真实的数据
|
||||
// System.out.println(status);
|
||||
|
||||
Thread.sleep(1000);
|
||||
client.CleanupClient();
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 39 KiB |
@ -1,45 +0,0 @@
|
||||
{
|
||||
"name": "WeChatFerryNodejs",
|
||||
"version": "1.0.0",
|
||||
"description": "WeChatFerry nodejs demo",
|
||||
"main": "./src/index.ts",
|
||||
"author": "radiocom@qq.com",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"prebuild": "eslint --fix src",
|
||||
"start": "npx ts-node src/index.ts",
|
||||
"proto:build": "npx grpc_tools_node_protoc --js_out=import_style=commonjs,binary:./proto/ --grpc_out=./proto/ --plugin=protoc-gen-grpc=\"node_modules/grpc-tools/bin/grpc_node_plugin.exe\" --proto_path=./proto wcf.proto",
|
||||
"proto:types": ".\\node_modules\\grpc-tools\\bin\\protoc.exe --plugin=protoc-gen-ts=\".\\node_modules\\.bin\\protoc-gen-ts.cmd\" --ts_out=./proto/ -I ./proto wcf.proto"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.7.2",
|
||||
"ffi-decorators": "^0.4.0",
|
||||
"ffi-napi": "^4.0.3",
|
||||
"grpc": "^1.24.11",
|
||||
"net": "^1.0.2",
|
||||
"readline": "^1.3.0",
|
||||
"ref-napi": "^3.0.3",
|
||||
"ref-struct-di": "^1.1.1",
|
||||
"ref-union-di": "^1.0.1",
|
||||
"stock-api": "^2.0.5",
|
||||
"tslog": "^3.3.4",
|
||||
"typed-emitter": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ffi-napi": "^4.0.6",
|
||||
"@types/node": "^18.11.2",
|
||||
"@typescript-eslint/eslint-plugin": "^5.40.1",
|
||||
"@typescript-eslint/parser": "^5.40.1",
|
||||
"eslint": "^8.25.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-header": "^3.1.1",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-unused-imports": "^2.0.0",
|
||||
"grpc-tools": "^1.11.3",
|
||||
"grpc_tools_node_protoc_ts": "^5.3.2",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tslib": "^2.4.0",
|
||||
"typescript": "^4.8.4"
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
module.exports = {
|
||||
tabWidth: 2,
|
||||
singleQuote: true,
|
||||
printWidth: 120,
|
||||
endOfLine: 'lf',
|
||||
};
|
||||
|
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.protoIndex = void 0;
|
||||
require("./wcf_grpc_pb");
|
||||
require("./wcf_pb");
|
||||
const protoIndex = () => {
|
||||
};
|
||||
exports.protoIndex = protoIndex;
|
@ -1,5 +0,0 @@
|
||||
import './wcf_grpc_pb';
|
||||
import './wcf_pb';
|
||||
|
||||
export const protoIndex:any = ():void => {
|
||||
};
|
@ -1,88 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package wcf;
|
||||
option java_package = "com.iamteer.wcf";
|
||||
|
||||
service Wcf {
|
||||
rpc RpcIsLogin(Empty) returns (Response) {}
|
||||
rpc RpcGetSelfWxid(Empty) returns (String) {}
|
||||
rpc RpcEnableRecvMsg(Empty) returns (stream WxMsg) {}
|
||||
rpc RpcDisableRecvMsg(Empty) returns (Response) {}
|
||||
rpc RpcSendTextMsg(TextMsg) returns (Response) {}
|
||||
rpc RpcSendImageMsg(ImageMsg) returns (Response) {}
|
||||
rpc RpcGetMsgTypes(Empty) returns (MsgTypes) {}
|
||||
rpc RpcGetContacts(Empty) returns (Contacts) {}
|
||||
rpc RpcGetDbNames(Empty) returns (DbNames) {}
|
||||
rpc RpcGetDbTables(String) returns (DbTables) {}
|
||||
rpc RpcExecDbQuery(DbQuery) returns (DbRows) {}
|
||||
rpc RpcAcceptNewFriend(Verification) returns (Response) {}
|
||||
}
|
||||
|
||||
message Empty {}
|
||||
|
||||
message WxMsg {
|
||||
bool is_self = 1; // 是否自己发送的
|
||||
bool is_group = 2; // 是否群消息
|
||||
int32 type = 3; // 消息类型
|
||||
string id = 4; // 消息 id
|
||||
string xml = 5; // 消息 xml
|
||||
string sender = 6; // 消息发送者
|
||||
string roomid = 7; // 群 id(如果是群消息的话)
|
||||
string content = 8; // 消息内容
|
||||
}
|
||||
|
||||
message Response {
|
||||
int32 status = 1; // 状态码
|
||||
}
|
||||
|
||||
message TextMsg {
|
||||
string msg = 1; // 要发送的消息内容
|
||||
string receiver = 2; // 消息接收人,当为群时可@
|
||||
string aters = 3; // 要@的人列表,逗号分隔
|
||||
}
|
||||
|
||||
message ImageMsg {
|
||||
string path = 1; // 要发送的图片的路径
|
||||
string receiver = 2; // 消息接收人
|
||||
}
|
||||
|
||||
message MsgTypes { map<int32, string> types = 1; }
|
||||
|
||||
message Contact {
|
||||
string wxid = 1; // 微信 id
|
||||
string code = 2; // 微信号
|
||||
string name = 3; // 微信昵称
|
||||
string country = 4; // 国家
|
||||
string province = 5; // 省/州
|
||||
string city = 6; // 城市
|
||||
int32 gender = 7; // 性别
|
||||
}
|
||||
message Contacts { repeated Contact contacts = 1; }
|
||||
|
||||
message DbNames { repeated string names = 1; }
|
||||
|
||||
message String { string str = 1; }
|
||||
|
||||
message DbTable {
|
||||
string name = 1; // 表名
|
||||
string sql = 2; // 建表 SQL
|
||||
}
|
||||
message DbTables { repeated DbTable tables = 1; }
|
||||
|
||||
message DbQuery {
|
||||
string db = 1; // 目标数据库
|
||||
string sql = 2; // 查询 SQL
|
||||
}
|
||||
|
||||
message DbField {
|
||||
int32 type = 1; // 字段类型
|
||||
string column = 2; // 字段名称
|
||||
bytes content = 3; // 字段内容
|
||||
}
|
||||
message DbRow { repeated DbField fields = 1; }
|
||||
message DbRows { repeated DbRow rows = 1; }
|
||||
|
||||
message Verification {
|
||||
string v3 = 1;
|
||||
string v4 = 2;
|
||||
}
|
226
nodejs/proto/wcf_grpc_pb.d.ts
vendored
226
nodejs/proto/wcf_grpc_pb.d.ts
vendored
@ -1,226 +0,0 @@
|
||||
// package: wcf
|
||||
// file: wcf.proto
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
import * as grpc from "grpc";
|
||||
import * as wcf_pb from "./wcf_pb";
|
||||
|
||||
interface IWcfService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
|
||||
rpcIsLogin: IWcfService_IRpcIsLogin;
|
||||
rpcGetSelfWxid: IWcfService_IRpcGetSelfWxid;
|
||||
rpcEnableRecvMsg: IWcfService_IRpcEnableRecvMsg;
|
||||
rpcDisableRecvMsg: IWcfService_IRpcDisableRecvMsg;
|
||||
rpcSendTextMsg: IWcfService_IRpcSendTextMsg;
|
||||
rpcSendImageMsg: IWcfService_IRpcSendImageMsg;
|
||||
rpcGetMsgTypes: IWcfService_IRpcGetMsgTypes;
|
||||
rpcGetContacts: IWcfService_IRpcGetContacts;
|
||||
rpcGetDbNames: IWcfService_IRpcGetDbNames;
|
||||
rpcGetDbTables: IWcfService_IRpcGetDbTables;
|
||||
rpcExecDbQuery: IWcfService_IRpcExecDbQuery;
|
||||
rpcAcceptNewFriend: IWcfService_IRpcAcceptNewFriend;
|
||||
}
|
||||
|
||||
interface IWcfService_IRpcIsLogin extends grpc.MethodDefinition<wcf_pb.Empty, wcf_pb.Response> {
|
||||
path: "/wcf.Wcf/RpcIsLogin";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.Empty>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.Empty>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.Response>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.Response>;
|
||||
}
|
||||
interface IWcfService_IRpcGetSelfWxid extends grpc.MethodDefinition<wcf_pb.Empty, wcf_pb.String> {
|
||||
path: "/wcf.Wcf/RpcGetSelfWxid";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.Empty>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.Empty>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.String>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.String>;
|
||||
}
|
||||
interface IWcfService_IRpcEnableRecvMsg extends grpc.MethodDefinition<wcf_pb.Empty, wcf_pb.WxMsg> {
|
||||
path: "/wcf.Wcf/RpcEnableRecvMsg";
|
||||
requestStream: false;
|
||||
responseStream: true;
|
||||
requestSerialize: grpc.serialize<wcf_pb.Empty>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.Empty>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.WxMsg>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.WxMsg>;
|
||||
}
|
||||
interface IWcfService_IRpcDisableRecvMsg extends grpc.MethodDefinition<wcf_pb.Empty, wcf_pb.Response> {
|
||||
path: "/wcf.Wcf/RpcDisableRecvMsg";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.Empty>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.Empty>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.Response>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.Response>;
|
||||
}
|
||||
interface IWcfService_IRpcSendTextMsg extends grpc.MethodDefinition<wcf_pb.TextMsg, wcf_pb.Response> {
|
||||
path: "/wcf.Wcf/RpcSendTextMsg";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.TextMsg>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.TextMsg>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.Response>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.Response>;
|
||||
}
|
||||
interface IWcfService_IRpcSendImageMsg extends grpc.MethodDefinition<wcf_pb.ImageMsg, wcf_pb.Response> {
|
||||
path: "/wcf.Wcf/RpcSendImageMsg";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.ImageMsg>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.ImageMsg>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.Response>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.Response>;
|
||||
}
|
||||
interface IWcfService_IRpcGetMsgTypes extends grpc.MethodDefinition<wcf_pb.Empty, wcf_pb.MsgTypes> {
|
||||
path: "/wcf.Wcf/RpcGetMsgTypes";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.Empty>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.Empty>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.MsgTypes>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.MsgTypes>;
|
||||
}
|
||||
interface IWcfService_IRpcGetContacts extends grpc.MethodDefinition<wcf_pb.Empty, wcf_pb.Contacts> {
|
||||
path: "/wcf.Wcf/RpcGetContacts";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.Empty>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.Empty>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.Contacts>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.Contacts>;
|
||||
}
|
||||
interface IWcfService_IRpcGetDbNames extends grpc.MethodDefinition<wcf_pb.Empty, wcf_pb.DbNames> {
|
||||
path: "/wcf.Wcf/RpcGetDbNames";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.Empty>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.Empty>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.DbNames>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.DbNames>;
|
||||
}
|
||||
interface IWcfService_IRpcGetDbTables extends grpc.MethodDefinition<wcf_pb.String, wcf_pb.DbTables> {
|
||||
path: "/wcf.Wcf/RpcGetDbTables";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.String>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.String>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.DbTables>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.DbTables>;
|
||||
}
|
||||
interface IWcfService_IRpcExecDbQuery extends grpc.MethodDefinition<wcf_pb.DbQuery, wcf_pb.DbRows> {
|
||||
path: "/wcf.Wcf/RpcExecDbQuery";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.DbQuery>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.DbQuery>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.DbRows>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.DbRows>;
|
||||
}
|
||||
interface IWcfService_IRpcAcceptNewFriend extends grpc.MethodDefinition<wcf_pb.Verification, wcf_pb.Response> {
|
||||
path: "/wcf.Wcf/RpcAcceptNewFriend";
|
||||
requestStream: false;
|
||||
responseStream: false;
|
||||
requestSerialize: grpc.serialize<wcf_pb.Verification>;
|
||||
requestDeserialize: grpc.deserialize<wcf_pb.Verification>;
|
||||
responseSerialize: grpc.serialize<wcf_pb.Response>;
|
||||
responseDeserialize: grpc.deserialize<wcf_pb.Response>;
|
||||
}
|
||||
|
||||
export const WcfService: IWcfService;
|
||||
|
||||
export interface IWcfServer {
|
||||
rpcIsLogin: grpc.handleUnaryCall<wcf_pb.Empty, wcf_pb.Response>;
|
||||
rpcGetSelfWxid: grpc.handleUnaryCall<wcf_pb.Empty, wcf_pb.String>;
|
||||
rpcEnableRecvMsg: grpc.handleServerStreamingCall<wcf_pb.Empty, wcf_pb.WxMsg>;
|
||||
rpcDisableRecvMsg: grpc.handleUnaryCall<wcf_pb.Empty, wcf_pb.Response>;
|
||||
rpcSendTextMsg: grpc.handleUnaryCall<wcf_pb.TextMsg, wcf_pb.Response>;
|
||||
rpcSendImageMsg: grpc.handleUnaryCall<wcf_pb.ImageMsg, wcf_pb.Response>;
|
||||
rpcGetMsgTypes: grpc.handleUnaryCall<wcf_pb.Empty, wcf_pb.MsgTypes>;
|
||||
rpcGetContacts: grpc.handleUnaryCall<wcf_pb.Empty, wcf_pb.Contacts>;
|
||||
rpcGetDbNames: grpc.handleUnaryCall<wcf_pb.Empty, wcf_pb.DbNames>;
|
||||
rpcGetDbTables: grpc.handleUnaryCall<wcf_pb.String, wcf_pb.DbTables>;
|
||||
rpcExecDbQuery: grpc.handleUnaryCall<wcf_pb.DbQuery, wcf_pb.DbRows>;
|
||||
rpcAcceptNewFriend: grpc.handleUnaryCall<wcf_pb.Verification, wcf_pb.Response>;
|
||||
}
|
||||
|
||||
export interface IWcfClient {
|
||||
rpcIsLogin(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcIsLogin(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcIsLogin(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcGetSelfWxid(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.String) => void): grpc.ClientUnaryCall;
|
||||
rpcGetSelfWxid(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.String) => void): grpc.ClientUnaryCall;
|
||||
rpcGetSelfWxid(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.String) => void): grpc.ClientUnaryCall;
|
||||
rpcEnableRecvMsg(request: wcf_pb.Empty, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<wcf_pb.WxMsg>;
|
||||
rpcEnableRecvMsg(request: wcf_pb.Empty, metadata?: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<wcf_pb.WxMsg>;
|
||||
rpcDisableRecvMsg(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcDisableRecvMsg(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcDisableRecvMsg(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcSendTextMsg(request: wcf_pb.TextMsg, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcSendTextMsg(request: wcf_pb.TextMsg, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcSendTextMsg(request: wcf_pb.TextMsg, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcSendImageMsg(request: wcf_pb.ImageMsg, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcSendImageMsg(request: wcf_pb.ImageMsg, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcSendImageMsg(request: wcf_pb.ImageMsg, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcGetMsgTypes(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.MsgTypes) => void): grpc.ClientUnaryCall;
|
||||
rpcGetMsgTypes(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.MsgTypes) => void): grpc.ClientUnaryCall;
|
||||
rpcGetMsgTypes(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.MsgTypes) => void): grpc.ClientUnaryCall;
|
||||
rpcGetContacts(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.Contacts) => void): grpc.ClientUnaryCall;
|
||||
rpcGetContacts(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Contacts) => void): grpc.ClientUnaryCall;
|
||||
rpcGetContacts(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Contacts) => void): grpc.ClientUnaryCall;
|
||||
rpcGetDbNames(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbNames) => void): grpc.ClientUnaryCall;
|
||||
rpcGetDbNames(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbNames) => void): grpc.ClientUnaryCall;
|
||||
rpcGetDbNames(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbNames) => void): grpc.ClientUnaryCall;
|
||||
rpcGetDbTables(request: wcf_pb.String, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbTables) => void): grpc.ClientUnaryCall;
|
||||
rpcGetDbTables(request: wcf_pb.String, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbTables) => void): grpc.ClientUnaryCall;
|
||||
rpcGetDbTables(request: wcf_pb.String, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbTables) => void): grpc.ClientUnaryCall;
|
||||
rpcExecDbQuery(request: wcf_pb.DbQuery, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbRows) => void): grpc.ClientUnaryCall;
|
||||
rpcExecDbQuery(request: wcf_pb.DbQuery, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbRows) => void): grpc.ClientUnaryCall;
|
||||
rpcExecDbQuery(request: wcf_pb.DbQuery, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbRows) => void): grpc.ClientUnaryCall;
|
||||
rpcAcceptNewFriend(request: wcf_pb.Verification, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcAcceptNewFriend(request: wcf_pb.Verification, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
rpcAcceptNewFriend(request: wcf_pb.Verification, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
}
|
||||
|
||||
export class WcfClient extends grpc.Client implements IWcfClient {
|
||||
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
|
||||
public rpcIsLogin(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcIsLogin(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcIsLogin(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetSelfWxid(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.String) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetSelfWxid(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.String) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetSelfWxid(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.String) => void): grpc.ClientUnaryCall;
|
||||
public rpcEnableRecvMsg(request: wcf_pb.Empty, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<wcf_pb.WxMsg>;
|
||||
public rpcEnableRecvMsg(request: wcf_pb.Empty, metadata?: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<wcf_pb.WxMsg>;
|
||||
public rpcDisableRecvMsg(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcDisableRecvMsg(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcDisableRecvMsg(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcSendTextMsg(request: wcf_pb.TextMsg, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcSendTextMsg(request: wcf_pb.TextMsg, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcSendTextMsg(request: wcf_pb.TextMsg, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcSendImageMsg(request: wcf_pb.ImageMsg, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcSendImageMsg(request: wcf_pb.ImageMsg, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcSendImageMsg(request: wcf_pb.ImageMsg, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetMsgTypes(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.MsgTypes) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetMsgTypes(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.MsgTypes) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetMsgTypes(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.MsgTypes) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetContacts(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.Contacts) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetContacts(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Contacts) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetContacts(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Contacts) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetDbNames(request: wcf_pb.Empty, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbNames) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetDbNames(request: wcf_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbNames) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetDbNames(request: wcf_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbNames) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetDbTables(request: wcf_pb.String, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbTables) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetDbTables(request: wcf_pb.String, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbTables) => void): grpc.ClientUnaryCall;
|
||||
public rpcGetDbTables(request: wcf_pb.String, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbTables) => void): grpc.ClientUnaryCall;
|
||||
public rpcExecDbQuery(request: wcf_pb.DbQuery, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbRows) => void): grpc.ClientUnaryCall;
|
||||
public rpcExecDbQuery(request: wcf_pb.DbQuery, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbRows) => void): grpc.ClientUnaryCall;
|
||||
public rpcExecDbQuery(request: wcf_pb.DbQuery, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.DbRows) => void): grpc.ClientUnaryCall;
|
||||
public rpcAcceptNewFriend(request: wcf_pb.Verification, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcAcceptNewFriend(request: wcf_pb.Verification, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
public rpcAcceptNewFriend(request: wcf_pb.Verification, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: wcf_pb.Response) => void): grpc.ClientUnaryCall;
|
||||
}
|
@ -1,286 +0,0 @@
|
||||
// GENERATED CODE -- DO NOT EDIT!
|
||||
|
||||
'use strict';
|
||||
var grpc = require('grpc');
|
||||
var wcf_pb = require('./wcf_pb.js');
|
||||
|
||||
function serialize_wcf_Contacts(arg) {
|
||||
if (!(arg instanceof wcf_pb.Contacts)) {
|
||||
throw new Error('Expected argument of type wcf.Contacts');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_Contacts(buffer_arg) {
|
||||
return wcf_pb.Contacts.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_DbNames(arg) {
|
||||
if (!(arg instanceof wcf_pb.DbNames)) {
|
||||
throw new Error('Expected argument of type wcf.DbNames');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_DbNames(buffer_arg) {
|
||||
return wcf_pb.DbNames.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_DbQuery(arg) {
|
||||
if (!(arg instanceof wcf_pb.DbQuery)) {
|
||||
throw new Error('Expected argument of type wcf.DbQuery');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_DbQuery(buffer_arg) {
|
||||
return wcf_pb.DbQuery.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_DbRows(arg) {
|
||||
if (!(arg instanceof wcf_pb.DbRows)) {
|
||||
throw new Error('Expected argument of type wcf.DbRows');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_DbRows(buffer_arg) {
|
||||
return wcf_pb.DbRows.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_DbTables(arg) {
|
||||
if (!(arg instanceof wcf_pb.DbTables)) {
|
||||
throw new Error('Expected argument of type wcf.DbTables');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_DbTables(buffer_arg) {
|
||||
return wcf_pb.DbTables.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_Empty(arg) {
|
||||
if (!(arg instanceof wcf_pb.Empty)) {
|
||||
throw new Error('Expected argument of type wcf.Empty');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_Empty(buffer_arg) {
|
||||
return wcf_pb.Empty.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_ImageMsg(arg) {
|
||||
if (!(arg instanceof wcf_pb.ImageMsg)) {
|
||||
throw new Error('Expected argument of type wcf.ImageMsg');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_ImageMsg(buffer_arg) {
|
||||
return wcf_pb.ImageMsg.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_MsgTypes(arg) {
|
||||
if (!(arg instanceof wcf_pb.MsgTypes)) {
|
||||
throw new Error('Expected argument of type wcf.MsgTypes');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_MsgTypes(buffer_arg) {
|
||||
return wcf_pb.MsgTypes.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_Response(arg) {
|
||||
if (!(arg instanceof wcf_pb.Response)) {
|
||||
throw new Error('Expected argument of type wcf.Response');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_Response(buffer_arg) {
|
||||
return wcf_pb.Response.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_String(arg) {
|
||||
if (!(arg instanceof wcf_pb.String)) {
|
||||
throw new Error('Expected argument of type wcf.String');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_String(buffer_arg) {
|
||||
return wcf_pb.String.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_TextMsg(arg) {
|
||||
if (!(arg instanceof wcf_pb.TextMsg)) {
|
||||
throw new Error('Expected argument of type wcf.TextMsg');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_TextMsg(buffer_arg) {
|
||||
return wcf_pb.TextMsg.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_Verification(arg) {
|
||||
if (!(arg instanceof wcf_pb.Verification)) {
|
||||
throw new Error('Expected argument of type wcf.Verification');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_Verification(buffer_arg) {
|
||||
return wcf_pb.Verification.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
function serialize_wcf_WxMsg(arg) {
|
||||
if (!(arg instanceof wcf_pb.WxMsg)) {
|
||||
throw new Error('Expected argument of type wcf.WxMsg');
|
||||
}
|
||||
return Buffer.from(arg.serializeBinary());
|
||||
}
|
||||
|
||||
function deserialize_wcf_WxMsg(buffer_arg) {
|
||||
return wcf_pb.WxMsg.deserializeBinary(new Uint8Array(buffer_arg));
|
||||
}
|
||||
|
||||
|
||||
var WcfService = exports.WcfService = {
|
||||
rpcIsLogin: {
|
||||
path: '/wcf.Wcf/RpcIsLogin',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.Empty,
|
||||
responseType: wcf_pb.Response,
|
||||
requestSerialize: serialize_wcf_Empty,
|
||||
requestDeserialize: deserialize_wcf_Empty,
|
||||
responseSerialize: serialize_wcf_Response,
|
||||
responseDeserialize: deserialize_wcf_Response,
|
||||
},
|
||||
rpcGetSelfWxid: {
|
||||
path: '/wcf.Wcf/RpcGetSelfWxid',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.Empty,
|
||||
responseType: wcf_pb.String,
|
||||
requestSerialize: serialize_wcf_Empty,
|
||||
requestDeserialize: deserialize_wcf_Empty,
|
||||
responseSerialize: serialize_wcf_String,
|
||||
responseDeserialize: deserialize_wcf_String,
|
||||
},
|
||||
rpcEnableRecvMsg: {
|
||||
path: '/wcf.Wcf/RpcEnableRecvMsg',
|
||||
requestStream: false,
|
||||
responseStream: true,
|
||||
requestType: wcf_pb.Empty,
|
||||
responseType: wcf_pb.WxMsg,
|
||||
requestSerialize: serialize_wcf_Empty,
|
||||
requestDeserialize: deserialize_wcf_Empty,
|
||||
responseSerialize: serialize_wcf_WxMsg,
|
||||
responseDeserialize: deserialize_wcf_WxMsg,
|
||||
},
|
||||
rpcDisableRecvMsg: {
|
||||
path: '/wcf.Wcf/RpcDisableRecvMsg',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.Empty,
|
||||
responseType: wcf_pb.Response,
|
||||
requestSerialize: serialize_wcf_Empty,
|
||||
requestDeserialize: deserialize_wcf_Empty,
|
||||
responseSerialize: serialize_wcf_Response,
|
||||
responseDeserialize: deserialize_wcf_Response,
|
||||
},
|
||||
rpcSendTextMsg: {
|
||||
path: '/wcf.Wcf/RpcSendTextMsg',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.TextMsg,
|
||||
responseType: wcf_pb.Response,
|
||||
requestSerialize: serialize_wcf_TextMsg,
|
||||
requestDeserialize: deserialize_wcf_TextMsg,
|
||||
responseSerialize: serialize_wcf_Response,
|
||||
responseDeserialize: deserialize_wcf_Response,
|
||||
},
|
||||
rpcSendImageMsg: {
|
||||
path: '/wcf.Wcf/RpcSendImageMsg',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.ImageMsg,
|
||||
responseType: wcf_pb.Response,
|
||||
requestSerialize: serialize_wcf_ImageMsg,
|
||||
requestDeserialize: deserialize_wcf_ImageMsg,
|
||||
responseSerialize: serialize_wcf_Response,
|
||||
responseDeserialize: deserialize_wcf_Response,
|
||||
},
|
||||
rpcGetMsgTypes: {
|
||||
path: '/wcf.Wcf/RpcGetMsgTypes',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.Empty,
|
||||
responseType: wcf_pb.MsgTypes,
|
||||
requestSerialize: serialize_wcf_Empty,
|
||||
requestDeserialize: deserialize_wcf_Empty,
|
||||
responseSerialize: serialize_wcf_MsgTypes,
|
||||
responseDeserialize: deserialize_wcf_MsgTypes,
|
||||
},
|
||||
rpcGetContacts: {
|
||||
path: '/wcf.Wcf/RpcGetContacts',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.Empty,
|
||||
responseType: wcf_pb.Contacts,
|
||||
requestSerialize: serialize_wcf_Empty,
|
||||
requestDeserialize: deserialize_wcf_Empty,
|
||||
responseSerialize: serialize_wcf_Contacts,
|
||||
responseDeserialize: deserialize_wcf_Contacts,
|
||||
},
|
||||
rpcGetDbNames: {
|
||||
path: '/wcf.Wcf/RpcGetDbNames',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.Empty,
|
||||
responseType: wcf_pb.DbNames,
|
||||
requestSerialize: serialize_wcf_Empty,
|
||||
requestDeserialize: deserialize_wcf_Empty,
|
||||
responseSerialize: serialize_wcf_DbNames,
|
||||
responseDeserialize: deserialize_wcf_DbNames,
|
||||
},
|
||||
rpcGetDbTables: {
|
||||
path: '/wcf.Wcf/RpcGetDbTables',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.String,
|
||||
responseType: wcf_pb.DbTables,
|
||||
requestSerialize: serialize_wcf_String,
|
||||
requestDeserialize: deserialize_wcf_String,
|
||||
responseSerialize: serialize_wcf_DbTables,
|
||||
responseDeserialize: deserialize_wcf_DbTables,
|
||||
},
|
||||
rpcExecDbQuery: {
|
||||
path: '/wcf.Wcf/RpcExecDbQuery',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.DbQuery,
|
||||
responseType: wcf_pb.DbRows,
|
||||
requestSerialize: serialize_wcf_DbQuery,
|
||||
requestDeserialize: deserialize_wcf_DbQuery,
|
||||
responseSerialize: serialize_wcf_DbRows,
|
||||
responseDeserialize: deserialize_wcf_DbRows,
|
||||
},
|
||||
rpcAcceptNewFriend: {
|
||||
path: '/wcf.Wcf/RpcAcceptNewFriend',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: wcf_pb.Verification,
|
||||
responseType: wcf_pb.Response,
|
||||
requestSerialize: serialize_wcf_Verification,
|
||||
requestDeserialize: deserialize_wcf_Verification,
|
||||
responseSerialize: serialize_wcf_Response,
|
||||
responseDeserialize: deserialize_wcf_Response,
|
||||
},
|
||||
};
|
||||
|
||||
exports.WcfClient = grpc.makeGenericClientConstructor(WcfService);
|
421
nodejs/proto/wcf_pb.d.ts
vendored
421
nodejs/proto/wcf_pb.d.ts
vendored
@ -1,421 +0,0 @@
|
||||
// package: wcf
|
||||
// file: wcf.proto
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
import * as jspb from "google-protobuf";
|
||||
|
||||
export class Empty extends jspb.Message {
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): Empty.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: Empty): Empty.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: Empty, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): Empty;
|
||||
static deserializeBinaryFromReader(message: Empty, reader: jspb.BinaryReader): Empty;
|
||||
}
|
||||
|
||||
export namespace Empty {
|
||||
export type AsObject = {
|
||||
}
|
||||
}
|
||||
|
||||
export class WxMsg extends jspb.Message {
|
||||
getIsSelf(): boolean;
|
||||
setIsSelf(value: boolean): WxMsg;
|
||||
getIsGroup(): boolean;
|
||||
setIsGroup(value: boolean): WxMsg;
|
||||
getType(): number;
|
||||
setType(value: number): WxMsg;
|
||||
getId(): string;
|
||||
setId(value: string): WxMsg;
|
||||
getXml(): string;
|
||||
setXml(value: string): WxMsg;
|
||||
getSender(): string;
|
||||
setSender(value: string): WxMsg;
|
||||
getRoomid(): string;
|
||||
setRoomid(value: string): WxMsg;
|
||||
getContent(): string;
|
||||
setContent(value: string): WxMsg;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): WxMsg.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: WxMsg): WxMsg.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: WxMsg, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): WxMsg;
|
||||
static deserializeBinaryFromReader(message: WxMsg, reader: jspb.BinaryReader): WxMsg;
|
||||
}
|
||||
|
||||
export namespace WxMsg {
|
||||
export type AsObject = {
|
||||
isSelf: boolean,
|
||||
isGroup: boolean,
|
||||
type: number,
|
||||
id: string,
|
||||
xml: string,
|
||||
sender: string,
|
||||
roomid: string,
|
||||
content: string,
|
||||
}
|
||||
}
|
||||
|
||||
export class Response extends jspb.Message {
|
||||
getStatus(): number;
|
||||
setStatus(value: number): Response;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): Response.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: Response): Response.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: Response, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): Response;
|
||||
static deserializeBinaryFromReader(message: Response, reader: jspb.BinaryReader): Response;
|
||||
}
|
||||
|
||||
export namespace Response {
|
||||
export type AsObject = {
|
||||
status: number,
|
||||
}
|
||||
}
|
||||
|
||||
export class TextMsg extends jspb.Message {
|
||||
getMsg(): string;
|
||||
setMsg(value: string): TextMsg;
|
||||
getReceiver(): string;
|
||||
setReceiver(value: string): TextMsg;
|
||||
getAters(): string;
|
||||
setAters(value: string): TextMsg;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): TextMsg.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: TextMsg): TextMsg.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: TextMsg, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): TextMsg;
|
||||
static deserializeBinaryFromReader(message: TextMsg, reader: jspb.BinaryReader): TextMsg;
|
||||
}
|
||||
|
||||
export namespace TextMsg {
|
||||
export type AsObject = {
|
||||
msg: string,
|
||||
receiver: string,
|
||||
aters: string,
|
||||
}
|
||||
}
|
||||
|
||||
export class ImageMsg extends jspb.Message {
|
||||
getPath(): string;
|
||||
setPath(value: string): ImageMsg;
|
||||
getReceiver(): string;
|
||||
setReceiver(value: string): ImageMsg;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): ImageMsg.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: ImageMsg): ImageMsg.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: ImageMsg, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): ImageMsg;
|
||||
static deserializeBinaryFromReader(message: ImageMsg, reader: jspb.BinaryReader): ImageMsg;
|
||||
}
|
||||
|
||||
export namespace ImageMsg {
|
||||
export type AsObject = {
|
||||
path: string,
|
||||
receiver: string,
|
||||
}
|
||||
}
|
||||
|
||||
export class MsgTypes extends jspb.Message {
|
||||
|
||||
getTypesMap(): jspb.Map<number, string>;
|
||||
clearTypesMap(): void;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): MsgTypes.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: MsgTypes): MsgTypes.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: MsgTypes, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): MsgTypes;
|
||||
static deserializeBinaryFromReader(message: MsgTypes, reader: jspb.BinaryReader): MsgTypes;
|
||||
}
|
||||
|
||||
export namespace MsgTypes {
|
||||
export type AsObject = {
|
||||
|
||||
typesMap: Array<[number, string]>,
|
||||
}
|
||||
}
|
||||
|
||||
export class Contact extends jspb.Message {
|
||||
getWxid(): string;
|
||||
setWxid(value: string): Contact;
|
||||
getCode(): string;
|
||||
setCode(value: string): Contact;
|
||||
getName(): string;
|
||||
setName(value: string): Contact;
|
||||
getCountry(): string;
|
||||
setCountry(value: string): Contact;
|
||||
getProvince(): string;
|
||||
setProvince(value: string): Contact;
|
||||
getCity(): string;
|
||||
setCity(value: string): Contact;
|
||||
getGender(): number;
|
||||
setGender(value: number): Contact;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): Contact.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: Contact): Contact.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: Contact, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): Contact;
|
||||
static deserializeBinaryFromReader(message: Contact, reader: jspb.BinaryReader): Contact;
|
||||
}
|
||||
|
||||
export namespace Contact {
|
||||
export type AsObject = {
|
||||
wxid: string,
|
||||
code: string,
|
||||
name: string,
|
||||
country: string,
|
||||
province: string,
|
||||
city: string,
|
||||
gender: number,
|
||||
}
|
||||
}
|
||||
|
||||
export class Contacts extends jspb.Message {
|
||||
clearContactsList(): void;
|
||||
getContactsList(): Array<Contact>;
|
||||
setContactsList(value: Array<Contact>): Contacts;
|
||||
addContacts(value?: Contact, index?: number): Contact;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): Contacts.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: Contacts): Contacts.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: Contacts, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): Contacts;
|
||||
static deserializeBinaryFromReader(message: Contacts, reader: jspb.BinaryReader): Contacts;
|
||||
}
|
||||
|
||||
export namespace Contacts {
|
||||
export type AsObject = {
|
||||
contactsList: Array<Contact.AsObject>,
|
||||
}
|
||||
}
|
||||
|
||||
export class DbNames extends jspb.Message {
|
||||
clearNamesList(): void;
|
||||
getNamesList(): Array<string>;
|
||||
setNamesList(value: Array<string>): DbNames;
|
||||
addNames(value: string, index?: number): string;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): DbNames.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: DbNames): DbNames.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: DbNames, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): DbNames;
|
||||
static deserializeBinaryFromReader(message: DbNames, reader: jspb.BinaryReader): DbNames;
|
||||
}
|
||||
|
||||
export namespace DbNames {
|
||||
export type AsObject = {
|
||||
namesList: Array<string>,
|
||||
}
|
||||
}
|
||||
|
||||
export class String extends jspb.Message {
|
||||
getStr(): string;
|
||||
setStr(value: string): String;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): String.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: String): String.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: String, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): String;
|
||||
static deserializeBinaryFromReader(message: String, reader: jspb.BinaryReader): String;
|
||||
}
|
||||
|
||||
export namespace String {
|
||||
export type AsObject = {
|
||||
str: string,
|
||||
}
|
||||
}
|
||||
|
||||
export class DbTable extends jspb.Message {
|
||||
getName(): string;
|
||||
setName(value: string): DbTable;
|
||||
getSql(): string;
|
||||
setSql(value: string): DbTable;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): DbTable.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: DbTable): DbTable.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: DbTable, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): DbTable;
|
||||
static deserializeBinaryFromReader(message: DbTable, reader: jspb.BinaryReader): DbTable;
|
||||
}
|
||||
|
||||
export namespace DbTable {
|
||||
export type AsObject = {
|
||||
name: string,
|
||||
sql: string,
|
||||
}
|
||||
}
|
||||
|
||||
export class DbTables extends jspb.Message {
|
||||
clearTablesList(): void;
|
||||
getTablesList(): Array<DbTable>;
|
||||
setTablesList(value: Array<DbTable>): DbTables;
|
||||
addTables(value?: DbTable, index?: number): DbTable;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): DbTables.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: DbTables): DbTables.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: DbTables, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): DbTables;
|
||||
static deserializeBinaryFromReader(message: DbTables, reader: jspb.BinaryReader): DbTables;
|
||||
}
|
||||
|
||||
export namespace DbTables {
|
||||
export type AsObject = {
|
||||
tablesList: Array<DbTable.AsObject>,
|
||||
}
|
||||
}
|
||||
|
||||
export class DbQuery extends jspb.Message {
|
||||
getDb(): string;
|
||||
setDb(value: string): DbQuery;
|
||||
getSql(): string;
|
||||
setSql(value: string): DbQuery;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): DbQuery.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: DbQuery): DbQuery.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: DbQuery, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): DbQuery;
|
||||
static deserializeBinaryFromReader(message: DbQuery, reader: jspb.BinaryReader): DbQuery;
|
||||
}
|
||||
|
||||
export namespace DbQuery {
|
||||
export type AsObject = {
|
||||
db: string,
|
||||
sql: string,
|
||||
}
|
||||
}
|
||||
|
||||
export class DbField extends jspb.Message {
|
||||
getType(): number;
|
||||
setType(value: number): DbField;
|
||||
getColumn(): string;
|
||||
setColumn(value: string): DbField;
|
||||
getContent(): Uint8Array | string;
|
||||
getContent_asU8(): Uint8Array;
|
||||
getContent_asB64(): string;
|
||||
setContent(value: Uint8Array | string): DbField;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): DbField.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: DbField): DbField.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: DbField, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): DbField;
|
||||
static deserializeBinaryFromReader(message: DbField, reader: jspb.BinaryReader): DbField;
|
||||
}
|
||||
|
||||
export namespace DbField {
|
||||
export type AsObject = {
|
||||
type: number,
|
||||
column: string,
|
||||
content: Uint8Array | string,
|
||||
}
|
||||
}
|
||||
|
||||
export class DbRow extends jspb.Message {
|
||||
clearFieldsList(): void;
|
||||
getFieldsList(): Array<DbField>;
|
||||
setFieldsList(value: Array<DbField>): DbRow;
|
||||
addFields(value?: DbField, index?: number): DbField;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): DbRow.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: DbRow): DbRow.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: DbRow, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): DbRow;
|
||||
static deserializeBinaryFromReader(message: DbRow, reader: jspb.BinaryReader): DbRow;
|
||||
}
|
||||
|
||||
export namespace DbRow {
|
||||
export type AsObject = {
|
||||
fieldsList: Array<DbField.AsObject>,
|
||||
}
|
||||
}
|
||||
|
||||
export class DbRows extends jspb.Message {
|
||||
clearRowsList(): void;
|
||||
getRowsList(): Array<DbRow>;
|
||||
setRowsList(value: Array<DbRow>): DbRows;
|
||||
addRows(value?: DbRow, index?: number): DbRow;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): DbRows.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: DbRows): DbRows.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: DbRows, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): DbRows;
|
||||
static deserializeBinaryFromReader(message: DbRows, reader: jspb.BinaryReader): DbRows;
|
||||
}
|
||||
|
||||
export namespace DbRows {
|
||||
export type AsObject = {
|
||||
rowsList: Array<DbRow.AsObject>,
|
||||
}
|
||||
}
|
||||
|
||||
export class Verification extends jspb.Message {
|
||||
getV3(): string;
|
||||
setV3(value: string): Verification;
|
||||
getV4(): string;
|
||||
setV4(value: string): Verification;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): Verification.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: Verification): Verification.AsObject;
|
||||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
|
||||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
|
||||
static serializeBinaryToWriter(message: Verification, writer: jspb.BinaryWriter): void;
|
||||
static deserializeBinary(bytes: Uint8Array): Verification;
|
||||
static deserializeBinaryFromReader(message: Verification, reader: jspb.BinaryReader): Verification;
|
||||
}
|
||||
|
||||
export namespace Verification {
|
||||
export type AsObject = {
|
||||
v3: string,
|
||||
v4: string,
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,20 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
export class Context {}
|
||||
|
||||
export class Interaction {
|
||||
constructor(input: string) {
|
||||
this.input = input;
|
||||
this.options = {};
|
||||
}
|
||||
input: string;
|
||||
output?: string;
|
||||
options: any;
|
||||
}
|
||||
|
||||
export interface Command {
|
||||
name: string;
|
||||
follow: (interaction: Interaction) => number;
|
||||
run: (ctx: Context, interaction: Interaction) => string | Promise<string>;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import { log } from '../utils/log';
|
||||
import { Interaction, Command, Context } from './base-command';
|
||||
import rsp from './rock-scissors-paper';
|
||||
import stock from './stock';
|
||||
|
||||
let commands: Command[] = [rsp, stock];
|
||||
|
||||
export const handleCommand = async (ctx: Context, input: string): Promise<string> => {
|
||||
const interaction = new Interaction(input);
|
||||
const choice = commands
|
||||
.map((c) => {
|
||||
return { score: c.follow(interaction), command: c };
|
||||
})
|
||||
?.sort((a, b) => {
|
||||
return a.score - b.score;
|
||||
})
|
||||
?.filter((x) => x.score > 0)
|
||||
?.pop();
|
||||
|
||||
if (!choice) {
|
||||
log.debug('no command found');
|
||||
return '';
|
||||
}
|
||||
const reply = await choice.command.run(ctx, interaction);
|
||||
return reply;
|
||||
};
|
@ -1,38 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import { log } from '../utils/log';
|
||||
import { Interaction, Command, Context } from './base-command';
|
||||
|
||||
function RandomNum(max: number): number {
|
||||
return Math.floor(Math.random() * (max + 1));
|
||||
}
|
||||
|
||||
const keywords = ['rock', 'paper', 'scissors'];
|
||||
|
||||
export default {
|
||||
name: 'rock-scissors-paper',
|
||||
follow: (interaction: Interaction): number => {
|
||||
const i = keywords.find((k) => {
|
||||
return interaction.input.includes(k);
|
||||
});
|
||||
log.debug(`rock-scissors-paper follow-up: ${i}`);
|
||||
interaction.options.pick = i ?? undefined;
|
||||
return i ? 1 : 0;
|
||||
},
|
||||
run: (ctx: Context, interaction: Interaction): string => {
|
||||
const pick: string = interaction.options.pick as string;
|
||||
|
||||
const playerPick = keywords.findIndex((x) => x == pick);
|
||||
const botPick = RandomNum(2);
|
||||
|
||||
let result = 'tied';
|
||||
|
||||
if (playerPick == botPick) result = 'Tied';
|
||||
else if (playerPick == 0 && botPick == 2) result = 'Win';
|
||||
else if ((playerPick - botPick) % 3 == 1) result = 'Win';
|
||||
else result = 'Lose';
|
||||
|
||||
const content = `You picked **${pick}** and I picked **${keywords[botPick]}**, You **${result}**`;
|
||||
return content;
|
||||
}
|
||||
} as Command;
|
@ -1,28 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import { stocks } from 'stock-api';
|
||||
import { Interaction, Command, Context } from './base-command';
|
||||
|
||||
function getPrice(code: string): Promise<string> {
|
||||
return stocks.tencent.getStocks([code]).then((res) => {
|
||||
return JSON.stringify(res[0]);
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'stock',
|
||||
follow: (interaction: Interaction): number => {
|
||||
let match = /(S[HZ]\d{6})/.exec(interaction.input);
|
||||
if (match) {
|
||||
let stock = match && match[0];
|
||||
interaction.options.stock = stock;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
run: async (ctx: Context, interaction: Interaction): Promise<string> => {
|
||||
const pick: string = interaction.options.stock as string;
|
||||
const content = await getPrice(pick);
|
||||
return content;
|
||||
}
|
||||
} as Command;
|
@ -1,57 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import * as readline from 'readline';
|
||||
import { stdin as input } from 'node:process';
|
||||
import { WxMsg } from '../proto/wcf_pb';
|
||||
import { log } from './utils/log';
|
||||
import { handleCommand } from './commands';
|
||||
import { Context } from './commands/base-command';
|
||||
import { SDK } from './wcf/win32';
|
||||
import { WCF } from './wcf';
|
||||
import { portAvailable, sleep } from './utils/misic';
|
||||
|
||||
let ctx = new Context();
|
||||
|
||||
(async () => {
|
||||
if (await portAvailable(10086)) {
|
||||
log.debug(`Call SDK to inject.`);
|
||||
const sdk = new SDK();
|
||||
sdk.WxInitSDK();
|
||||
}
|
||||
|
||||
// wait util WCF is ready
|
||||
while (!(await portAvailable(10086))) {
|
||||
await sleep(1000);
|
||||
}
|
||||
|
||||
log.debug(`Connect to gRPC and wait for login.`);
|
||||
const wcf = new WCF();
|
||||
while (!(await wcf.IsLogin())) {
|
||||
await sleep(1000);
|
||||
}
|
||||
|
||||
wcf.on('message', async (msg: WxMsg) => {
|
||||
const txt = msg.getContent();
|
||||
log.debug(txt, msg.getIsSelf());
|
||||
if (!msg.getIsSelf()) {
|
||||
const reply = await handleCommand(ctx, txt);
|
||||
if (msg.getIsGroup()) {
|
||||
wcf.SendTextMsg(msg.getRoomid(), reply);
|
||||
} else {
|
||||
wcf.SendTextMsg(msg.getSender(), reply);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
wcf.EnableReceiveMsg();
|
||||
})();
|
||||
|
||||
const std = readline.createInterface({ input });
|
||||
std.on('line', async (line) => {
|
||||
const reply = await handleCommand(ctx, line);
|
||||
log.debug(`reply: ${reply}`);
|
||||
if (line === 'exit') {
|
||||
std.close();
|
||||
}
|
||||
});
|
@ -1,11 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import { Logger } from 'tslog';
|
||||
|
||||
export const log: Logger = new Logger({
|
||||
name: 'main',
|
||||
displayLoggerName: false,
|
||||
overwriteConsole: true,
|
||||
dateTimePattern: 'monthday hour:minute:second'
|
||||
});
|
@ -1,20 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
export function portAvailable(port: number): Promise<boolean> {
|
||||
const net = require('net');
|
||||
return new Promise((resolve, _reject) => {
|
||||
let server = net.createServer().listen(port);
|
||||
server.on('listening', function () {
|
||||
server.close();
|
||||
resolve(true);
|
||||
});
|
||||
server.on('error', function (err: any) {
|
||||
if (err.code == 'EADDRINUSE') {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
@ -1,55 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import EventEmitter from 'events';
|
||||
import TypedEmitter from 'typed-emitter';
|
||||
import * as grpc from 'grpc';
|
||||
import { WcfClient, IWcfClient } from '../../proto/wcf_grpc_pb';
|
||||
import { Empty, TextMsg, WxMsg } from '../../proto/wcf_pb';
|
||||
|
||||
type MessageEvents = {
|
||||
error: (error: Error) => void;
|
||||
message: (msg: WxMsg) => void;
|
||||
};
|
||||
|
||||
export class WCF extends (EventEmitter as new () => TypedEmitter<MessageEvents>) {
|
||||
client: IWcfClient;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.client = new WcfClient(`localhost:10086`, grpc.credentials.createInsecure());
|
||||
}
|
||||
|
||||
async IsLogin(): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
const request = new Empty();
|
||||
this.client.rpcIsLogin(request, (err, ret) => {
|
||||
if (err) reject(err);
|
||||
else resolve(ret.getStatus() !== 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async EnableReceiveMsg() {
|
||||
let stream = this.client.rpcEnableRecvMsg(new Empty());
|
||||
stream.on('data', (d) => {
|
||||
this.emit('message', d);
|
||||
});
|
||||
stream.on('error', (err) => {
|
||||
this.emit('error', err);
|
||||
});
|
||||
}
|
||||
|
||||
async SendTextMsg(to: string, msg: string): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
const request = new TextMsg();
|
||||
request.setReceiver(to);
|
||||
request.setMsg(msg);
|
||||
|
||||
this.client.rpcSendTextMsg(request, (err, ret) => {
|
||||
if (err) reject(err);
|
||||
else resolve(ret.getStatus() !== 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import { Library, Method, never } from 'ffi-decorators';
|
||||
|
||||
@Library({ libPath: './sdk.dll' })
|
||||
export class SDK {
|
||||
@Method({ types: ['int', []] })
|
||||
WxInitSDK(): number {
|
||||
return never();
|
||||
}
|
||||
|
||||
@Method({ types: ['int', []] })
|
||||
WxDestroySDK(): number {
|
||||
return never();
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: inject spy.dll directly in ts code.
|
@ -1,103 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
"experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||
"emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user