Skip to content

基於CQHTTP插件的反向WebSocket通道提供服務端SDK層級的封裝

License

Notifications You must be signed in to change notification settings

cqbef/cqhttp.WebSocketReverse.NETCore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cqhttp.WebSocketReverse.NETCore

GitHub Workflow Status NugetVersion NugetDownload

基於CQHTTP插件的反向WebSocket通道提供服務端SDK層級的封裝

應用範例

using cqhttp.WebSocketReverse.NETCore;
using System;
using System.Diagnostics;
using System.Threading.Tasks;

WebSocketServer wss = new WebSocketServer ("ws://0.0.0.0:8889");

CqHttpParse parse = new CqHttpParse(CqHttpApi.SetResult);
CqHttpApi.Timeout = TimeSpan.FromSeconds(10);

wss.OnAuthorizationAsync += async (s, e) =>
{
   await Task.Run(() =>
   {
      Debug.WriteLine(e.Connection.WebSocketConnectionInfo.ClientIpAddress);
      e.Allow();
   });
};
wss.OnReceiveMessageAsync += async (s, e) =>
{
   await parse.Parse(s, e);
};
parse.OnPrivateMessageAsync += async (n, b) =>
{
   var vipinfo = await b.Source.GetVipInfo();
   if(vipinfo?.VipLevel == "普通用户")
   {
      await b.Source.Reply(b.Message);
   }else
   {
      long qqId = 123456789;
      int messageId = await b.Source.SendPrivateMessage($"{b.Sender.NickName}對你說:{b.Message}",qqId);
      if(messageId>0)await b.Source.Reply("已傳達消息");
   }
};

About

基於CQHTTP插件的反向WebSocket通道提供服務端SDK層級的封裝

Topics

Resources

License

Stars

Watchers

Forks