RedProtocolSharp 0.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package RedProtocolSharp --version 0.0.3
NuGet\Install-Package RedProtocolSharp -Version 0.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RedProtocolSharp" Version="0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RedProtocolSharp" Version="0.0.3" />
<PackageReference Include="RedProtocolSharp" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RedProtocolSharp --version 0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RedProtocolSharp, 0.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RedProtocolSharp@0.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RedProtocolSharp&version=0.0.3
#tool nuget:?package=RedProtocolSharp&version=0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
RedProtocolSharp
--基于RedProtocol的C# SDK,应用于某猫
警告:当前RedProtocol与RedProtocolSharp均处于开发阶段,未来结构可能产生较大变化,请做好随时变更代码的准备
介绍
RedProtocolSharp将RedProtocol基础的消息格式进行了封装,并将收到的消息封为Event,可供开发者快速开发Bot框架
功能表
接收源消息
源消息文本解析
源消息图片解析
源消息at解析
源消息回复解析
源消息发送者信息解析
json消息解析(Red尚未提供实现)
发送文本消息
发送图片消息
发送at消息
发送回复消息
发送合并转发消息
发送语音消息
撤回消息
获取Bot自身消息
获取Bot好友列表(Bug)
获取Bot所在某群群员列表(Bug)
踢人
禁言人
全体禁言
已知问题/feature
- GetMemberList返回空数组(打开UI可能可以解决问题)
安装
Nuget搜索RedProtocolSharp安装
或
引入Release下的Dll,并自行安装WebSocketSharp,NewtonSoft.JSON相关依赖(不推荐)
示例
可去Sample查看基础用法,下面的内容可能并不会及时更新
启动Bot
var bot = new Bot("localhost:16530","yourToken");
bot.Start();
注册Logger
bot.Logger.BotLog.OnLogger += BotLogOnHandler;
private static void BotLogOnHandler(BotLogger.Levels levels, string content)
{
Console.WriteLine($"{levels} : {content}");
}
订阅消息
bot.Invoker.OnGroupMessageReceived += InvokerOnOnGroupMessageReceived;
private static void InvokerOnOnGroupMessageReceived(MessageEventArgs e)
{
Console.WriteLine(e.chain.GroupUin);
foreach (var item in e.chain)
{
if (item is TextElement textElement)
{
Console.WriteLine(textElement.content);
}
}
}
发送消息
var reply = await bot.Send
.SetTarget("1919810", ChatTypes.GroupMessage)
.AddText("testMessage")
.AddAt("114514")
.AddPic("test.png")
.SendMessage();
//向群1919810发送内容为testMessage,艾特用户114514,附带图片test.png的消息
撤回消息
//假设上一步发送返回了reply
await bot.Action.Revoke(new []{reply.msgId}, reply.chatTypes, reply.peerUin);
获取Bot自身信息
var selfInfo = bot.Get.SelfInfo();
踢人
await bot.Action.Kick("114514", "1919810", false, "test");
//从群114514踢出用户1919810,不永拒,理由为test
其他操作请自行探索/类比
案例
LlisBot(尚在开发中,暂未提供)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- Newtonsoft.Json (>= 13.0.3)
- WebSocketSharp (>= 1.0.3-rc11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
修改主方法为异步,修改私聊时GroupUin为SenderUin