QQChannelSharp 1.0.0-beta2

This is a prerelease version of QQChannelSharp.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package QQChannelSharp --version 1.0.0-beta2                
NuGet\Install-Package QQChannelSharp -Version 1.0.0-beta2                
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="QQChannelSharp" Version="1.0.0-beta2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add QQChannelSharp --version 1.0.0-beta2                
#r "nuget: QQChannelSharp, 1.0.0-beta2"                
#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.
// Install QQChannelSharp as a Cake Addin
#addin nuget:?package=QQChannelSharp&version=1.0.0-beta2&prerelease

// Install QQChannelSharp as a Cake Tool
#tool nuget:?package=QQChannelSharp&version=1.0.0-beta2&prerelease                

文档

语雀文档

能力

  • OpenApi拥有错误重试能力
  • 支持机器人本地/远程会话管理器 Remote正在计划中
  • 异步开发: 异步OpenApi, 异步事件处理

<details> <summary>支持的事件</summary>

  • ATMessageEvent - 公域机器人AT消息
  • AudioEvent - 音频事件消息
  • ChannelEvent - 频道事件
  • DirectMessageDeleteEvent - 私信消息删除事件
  • DirectMessageEvent - 私信消息事件
  • ErrorNotifyEvent - WebSocket错误通知事件
  • ForumAuditEvent - 论坛审核事件
  • GuildEvent - 频道事件
  • GuildMemberEvent - 频道成员事件
  • HandlerErrorEvent - 事件处理监听器错误事件
  • InteractionEvent - 互动事件
  • MessageAuditEvent - 消息审核事件
  • MessageDeleteEvent - 消息删除事件
  • MessageEvent - 私域机器人消息事件
  • MessageReactionEvent - 消息表情表态事件
  • PlainEvent - 普通事件
  • PostEvent - 主题帖子事件
  • PublicMessageDeleteEvent - 公域消息撤回事件
  • ReadyEvent - 机器人鉴权成功事件
  • ReplyEvent - 主题帖子回复事件
  • ResumedEvent - 机器人重连成功事件
  • ThreadEvent - 论坛主题事件 </details>

<details> <summary>待实现接口 (V1)</summary>

  • WEBHOOK

</details>


问题反馈

该项目属于测试阶段,如遇bug或者有想法/建议 请打开issue

交流

在使用中有任何疑问可以加入我们的QQ频道


依赖的开源库

RestSharp | .NET HTTPAPI客户端


快速开始

新建一个.NET7 项目,并从 Github 或 Nuget 上导入 QQChannelSharp。

在 Program 中引入必要的命名空间

using QQChannelSharp;
using QQChannelSharp.Interfaces;
using QQChannelSharp.Logger;
using QQChannelSharp.OpenApi;
using QQChannelSharp.Sessions;

设置日志

日志默认会启用输出, 且日志等级为 Info

Log.Configuration
	.EnableConsoleOutput()
    .SetLogLevel(LogLevel.Info);

启动本地会话

在启动本地会话之前,需要创建一个机器人信息和 OpenApi。这些数据将最终传递到一个会话管理器中,用于管理机器人的分片和事件的分发。创建完毕后,您可以通过调用会话管理器中的方法来注册一个类,或直接使用运算符相加将会话管理器事件总线中公开的事件注册为事件处理器。

这边演示最简单的 直接使用+=注册事件

需要更高级的订阅请参考文档: 事件订阅

ChannelBotInfo botInfo = new("AppId", "Token", true); // 设置机器人信息
OpenApiOptions options = new OpenApiOptions(botInfo)  // 设置OpenApi
    .UseRetry(); // 启用重试功能
ISessionManager sessionManager = new LocalSessionManager(botInfo, options); // 创建一个本地会话管理器
sessionManager.EventBus.ATMessageEvent += MessageEvent; // 直接注册一个事件 (@消息)
await sessionManager.StartAndWait(); // 阻塞在此处启动 (会自动计算Intents)

// 消息事件处理器
static async ValueTask MessageEvent(ATMessageEvent message)
{
    // 用于回复消息
    var msg = new MessageBody()
        .Text("你在")
        .Segment(new ChannelSegment(message.Message.ChannelID))
        .Text("发送的纯文本为:" + message.Context.GetText())
        .EndLine()
        .Emoji(EmojiType.WoofWoof, EmojiType.Moe)
        .Segment(Segment.Emoji(4));
    await message.Context.ReplyMessageAsync(msg); // 引用并回复消息
}

完整的代码

using QQChannelSharp;
using QQChannelSharp.Interfaces;
using QQChannelSharp.Logger;
using QQChannelSharp.OpenApi;
using QQChannelSharp.Sessions;

Log.Configuration
	.EnableConsoleOutput() // 启用控制台输出 (默认开启)
    .SetLogLevel(LogLevel.Info); // 设置日志输出等级 (默认Info)

ChannelBotInfo botInfo = new("AppId", "Token", true); // 设置机器人信息
OpenApiOptions options = new OpenApiOptions(botInfo)  // 设置OpenApi
    .UseRetry(); // 启用重试功能
ISessionManager sessionManager = new LocalSessionManager(botInfo, options); // 创建一个本地会话管理器
sessionManager.EventBus.ATMessageEvent += MessageEvent; // 直接注册一个事件 (@消息)
await sessionManager.StartAndWait(); // 阻塞在此处启动 (会自动计算Intents)

// 消息事件处理器
static async ValueTask MessageEvent(ATMessageEvent message)
{
    // 用于回复消息
    var msg = new MessageBody()
        .Text("你在")
        .Segment(new ChannelSegment(message.Message.ChannelID))
        .Text("发送的纯文本为:" + message.Context.GetText())
        .EndLine()
        .Emoji(EmojiType.WoofWoof, EmojiType.Moe)
        .Segment(Segment.Emoji(4));
    await message.Context.ReplyMessageAsync(msg); // 引用并回复消息
}

效果

img

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-beta4 75 11/17/2023
1.0.0-beta3 90 7/12/2023
1.0.0-beta2 82 6/3/2023
1.0.0-beta1 101 3/10/2023