KHLBotSharp.Core 2.0.0.5

dotnet add package KHLBotSharp.Core --version 2.0.0.5
                    
NuGet\Install-Package KHLBotSharp.Core -Version 2.0.0.5
                    
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="KHLBotSharp.Core" Version="2.0.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KHLBotSharp.Core" Version="2.0.0.5" />
                    
Directory.Packages.props
<PackageReference Include="KHLBotSharp.Core" />
                    
Project file
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 KHLBotSharp.Core --version 2.0.0.5
                    
#r "nuget: KHLBotSharp.Core, 2.0.0.5"
                    
#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 KHLBotSharp.Core@2.0.0.5
                    
#: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=KHLBotSharp.Core&version=2.0.0.5
                    
Install as a Cake Addin
#tool nuget:?package=KHLBotSharp.Core&version=2.0.0.5
                    
Install as a Cake Tool

logo

KHLBotSharp

开黑啦机器人运行器,支持多机器人以及插件模式运行

查看官方文档请点击:https://developer.kaiheila.cn/doc/intro

启动器

下载

Websocket使用

如果你的机器人单纯是小型使用,可考虑使用Websocket

  • 启动过一次启动器后,在Profiles\<你的Profile名字>内会拥有一个config.json
  • 还请自行到开黑啦开发者网页注册机器人,选择使用Websocket
  • 回到config.json, 把BotToken粘贴上
  • 保存config.json后,打开启动器即可
  • 可开始测试机器人是否运行正常
  • 如果需要多个机器人运行,则可使用cmd cd到启动器文件夹内,输入下列指令KHLBotSharp -c 你的Profile名字
  • 如果需要只单独运行一个特定的Profile,则使用cmd cd到启动器文件夹内,输入下列指令KHLBotSharp -r 你的Profile名字
  • 暂时不支持Docker以及非Windows,不过如果你想要使用,都可以自行下载源代码Publish

WebHook使用

如果你的机器人可能会大量用户使用,可考虑使用Webhook

  • 启动过一次启动器后,在Profiles\<你的Profile名字>内会拥有一个config.json
  • 还请自行到开黑啦开发者网页注册机器人,选择使用Webhook
  • 回到config.json,把EncryptKeyVerifyToken粘贴上
  • 保存config.json后,打开启动器即可
  • 回到开黑啦开发者网页,在你的机器人Callback Url下粘贴http://你的域名/hook?botName=<你的Profile名字>, 并且上线机器人
  • 可开始测试机器人是否运行正常
  • 现已支持Docker和非Windows,只需要clone下来直接使用即可

欢迎各路大神fork以及修改代码

即将出现的更新:

  • 持续优化以及跟进开黑啦文档

文档

创建插件之前,需要先知道插件监听的事件,框架会自动根据你监听的事件进行自动分类和整合数据。下列是插件可加载的列表:-

消息事件 解释
IGroupCardMessageHandler 频道卡片消息事件
IGroupKMarkdownMessageHandler 频道KMarkdown消息事件
IGroupPictureMessageHandler 频道图片消息事件
IGroupTextMessageHandler 频道文字消息事件
IGroupVideoMessageHandler 频道影片消息事件
IPrivateCardMessageHandler 私聊卡片消息
IPrivateKMarkdownMessageHandler 私聊KMarkdown消息事件
IPrivatePictureMessageHandler 私聊图片消息事件
IPrivateTextMessageHandler 私聊文字消息事件
IPrivateVideoMessageHandler 私聊影片消息
系统事件 解释
IBotExitServerHandler 机器人退出服务器事件
IBotJoinServerHandler 机器人加入服务器事件
ICardMessageButtonClickHandler 卡片消息按钮点击事件
IChannelCreatedHandler 频道创建事件
IChannelMessageRemoveHandler 频道消息撤回事件
IChannelMessageUpdateHandler 频道消息修改事件
IChannelModifyHandler 频道修改事件
IChannelPinnedMessageHandler 频道置顶消息事件
IChannelRemoveHandler 频道删除事件
IChannelRemovePinMessageHandler 频道置顶消息移除事件
IChannelUserAddReactionHandler 频道用户添加表情到消息事件
IChannelUserRemoveReactionHandler 频道用户从消息删除表情事件
IPrivateMessageAddReactionHandler 私聊用户添加表情到消息事件
IPrivateMessageModifyHandler 私聊消息修改事件
IPrivateMessageRemoveHandler 私聊消息撤回事件
IPrivateMessageRemoveReactionHandler 私聊用户从消息删除表情事件
IServerBlacklistUserHandler 服务器添加黑名单事件
IServerMemberModifiedHandler 服务器成员修改昵称事件
IServerMemberOfflineHandler 服务器成员下线事件
IServerMemberOnlineHandler 服务器成员上线事件
IServerNewMemberJoinHandler 服务器新成员加入事件
IServerRemoveBlacklistUserHandler 服务器移除黑名单事件
IServerRemoveHandler 服务器删除事件
IServerRoleAddHandler 服务器添加角色事件
IServerRoleModifyHandler 服务器角色修改事件
IServerRoleRemoveHandler 服务器角色移除事件
IServerUpdateHandler 服务器修改设置事件
IUserExitVoiceChannelHandler 用户离开语音频道事件
IUserInfoChangeHandler 用户个人资料修改事件
IUserJoinVoiceChannelHandler 用户加入语音频道事件

在创建了class后,以下是一些你可以在Ctor内从IServiceProvider获得到的interface

IService 解释
ILogService 日志Service
IKHLHttpService 开黑啦的Http请求指令,例如可发群聊消息,私聊消息等等,属于重要的Service,务必GetService时获取
IBotConfigSettings 获取在当前Profile内的config.ini设置

版本注意:

目前SDK有v1和v2版本,v1将会是维护状态而v2则会是当前版本,v1将会在开黑出版v4 API后全面停更。推荐使用v2 SDK以享受更多最新功能


接下来就是自主编写插件,而插件将会使用到的Http请求则可在这里查看interface代码

  • 插件需要添加KHLBotSharp.Core作为Dependency,打包后此dll不需要复制
  • 当前将会使用IGroupTextMessageHandler作为例子
  • 点击这里查看新版本插件的例子文件(v2.0.0.4 SDK 开始支持),这个插件是复读机
  • Ctor为插件的初始化,在这里你会获得IServiceProvider,源自于Dependency Injection(DI),因此可以进行GetService获取你想使用的东西,但是还请注意,这里并不能让你注册DI,只能获取
  • Handle则是插件的真正运行位置,当收到特定的Event后将会传输到这,再进行处理即可
  • 你可以拥有多个处理相同事件的插件
  • 插件完成后,在启动器文件夹内的Profiles\<你的Profile名字>\Plugins内创建一个与你插件名字一样的文件夹,并且把插件丢到文件夹内,包含你所有其他的Dependency,无需复制KHLBotSharp.Core
  • 打开启动器即可

如果想要注册自己想在Ctor的时候用的一些Service,可以尝试使用IServiceRegister Interface,只需要创建新的class (尽量别跟原本的消息处理事件放一起) 加上interface后,就可以获取个void Register(IServiceCollection services)功能进行注册DI

启动器选择

  • 目前启动器只有NET Core 3.1, 而插件因KHLBotSharp为.NET Standard 2.0因此可支持.NET Framework 4.6.1 以及.NET Core 2.0 以上甚至是最新的.NET 5和6,如果需要(懒得打包)下载可到这里下载.NET Core 3.1版本
  • Websocket启动器也可以自主添加或者修改,相同的插件可支持
  • Webhook启动器也可自主添加或者修改,相同插件可支持
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.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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
2.0.0.5 1,065 1/2/2022
1.0.0.10 1,604 12/3/2021