KaiheilaBot 0.2.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package KaiheilaBot --version 0.2.0
NuGet\Install-Package KaiheilaBot -Version 0.2.0
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="KaiheilaBot" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KaiheilaBot --version 0.2.0
#r "nuget: KaiheilaBot, 0.2.0"
#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 KaiheilaBot as a Cake Addin
#addin nuget:?package=KaiheilaBot&version=0.2.0

// Install KaiheilaBot as a Cake Tool
#tool nuget:?package=KaiheilaBot&version=0.2.0

GitHub license Nuget

开黑啦机器人开发框架

⚠️ 目前仍在开发中,基本可用,不保证稳定性和性能

使用

  1. Nuget 安装

  2. 从开黑啦开发者中心获取机器人 Websocket 模式下的 Token

const token = "Your Token Here";
  1. 实例化 Serilog
var logger = new LoggerConfiguration()
		.MinimumLevel.Debug()
		.WriteTo.Console()
		.CreateLogger();
  1. 实例化 Bot
var khlBot = new Bot(token, logger);

如果未传入 Serilog 实例 logger ,将不会记录和输出日志(不推荐

在实例化之后,你可以调用 KaiheilaBot.Globals 类中的一个静态成员

  • Easy.MessageHub.MessageHub MessageHub 简单的 Pub-Sub 模式消息队列,所有 Event 信令将会发送至此,请参考步骤4
  1. 订阅 MessageHub 处理 Event
var id = Globals.MessageHub.Subscribe<JsonElement>(je =>
{
    logger.Debug(je.ToString());
});

MessageHub 保存 System.Text.Json.JsonElement 类实例,实例为 Websocket 返回的 Event 信令 Json 数据的根元素,请参考 JsonElement Struct (System.Text.Json) | Microsoft Docs 和 [开黑啦开发者文档]([Websocket (kaiheila.cn)](https://developer.kaiheila.cn/doc/websocket#信令[0] EVENT))

  1. 发送 HTTP 请求

在实例化 Bot 之后,你可以使用已封装好的 KaiheilaBot.Core.BotRequest 类发送 Http 请求

var response = await new BotRequest()
        .SetUrl("guild/list")
        .SetMethod(Method.GET)  // BotRequest
        .GetResponse();  // Task<RestResponse>
  • SetUrl(string url) 设置请求地址,已添加基地址:https://www.kaiheila.cn/api/v3
  • SetMethod(Method method) 设置请求方法
  • AddParameter<T>(string parameterName, T parameter) 设置 Parameter
  • AddFile(string filePath) 添加文件,不可与其他设置共用,不需要设置 Parameter, Method 和 Url,将调用 上传媒体文件 接口
  • async Task<RestResponse> GetResponse() (可等待)获取 Response
  1. 运行 Bot
await khlBot.StartApp();

KaiheilaBot.Bot.StartApp() 方法可以接收一个 autoReconnect 参数,默认值为 true,Bot 将在连接超时发生时重新连接,可以传入 false 关闭自动重连,请注意,若收到 Reconnect 信令导致的重新连接不受此参数限制

许可证

本项目使用 MIT 许可证授权

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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