![]() |
VOOZH | about |
dotnet add package OneBot-CommandRoute --version 3.3.0
NuGet\Install-Package OneBot-CommandRoute -Version 3.3.0
<PackageReference Include="OneBot-CommandRoute" Version="3.3.0" />
<PackageVersion Include="OneBot-CommandRoute" Version="3.3.0" />Directory.Packages.props
<PackageReference Include="OneBot-CommandRoute" />Project file
paket add OneBot-CommandRoute --version 3.3.0
#r "nuget: OneBot-CommandRoute, 3.3.0"
#:package OneBot-CommandRoute@3.3.0
#addin nuget:?package=OneBot-CommandRoute&version=3.3.0Install as a Cake Addin
#tool nuget:?package=OneBot-CommandRoute&version=3.3.0Install as a Cake Tool
appsettings-reverse_ws-example.Development.json 重命名为 appsettings.Development.json。appsettings-reverse_ws-example.json 重命名为 appsettings.json。appsettings-ws-example.Development.json 重命名为 appsettings.Development.json。appsettings-ws-example.json 重命名为 appsettings.json。OneBot.FrameworkDemo.Modules.TestModule。
/// <summary>
/// 再定义一个指令:
///
/// <para>参数不必要按顺序、参数会触发依赖注入</para>
/// </summary>
/// <param name="gid">操作群号</param>
/// <param name="uid">被禁言用户</param>
/// <param name="duration">禁言时长</param>
[Command("mute <gid> <uid> [duration]", Alias = "禁言 <gid> <uid> [duration], 口球 <gid> <uid> [duration],", EventType = EventType.GroupMessage | EventType.PrivateMessage)]
public void MuteInGroupWithGroupId(Group gid, User uid, Duration duration)
{
if (duration == null) duration = new Duration(600);
Console.WriteLine($"禁言 {gid.Id} 群里的 {uid.Id} 用户 {duration.Seconds} 秒。");
}
[Command] 来将本函数定义为一个指令函数。若接收到合适的消息,本方法会被调用。OneBot.FrameworkDemo.Modules.TestModule。
/// <summary>
/// 小程序简单监听方法,
/// 这里是监听了群签到。
/// </summary>
/// <param name="e"></param>
[CQJson("com.tencent.qq.checkin", EventType = EventType.GroupMessage)]
public void CheckInListener(GroupMessageEventArgs e)
{
_logger.LogInformation($"{e.Sender.Id} 签到成功!");
// 当然这里也是可以返回 0 或 1 的。
}
[CQJson] 来将本函数定义为一个小程序监听函数。若接收到合适的消息,本方法会被调用。OneBot.FrameworkDemo.Models.Duration
/// <summary>
/// 实现一个从字符串到 Duration 的隐式转换。
/// 1d2h3m4s -> 1天2小时3分钟4秒
/// </summary>
/// <param name="value">时长</param>
public static implicit operator Duration(string value)
string 到对应的类型的隐式转换即可让指令路由系统支持这个类型的转换。OneBot.FrameworkDemo.Attributes.DemoBeforeCommandAttribute。BeforeCommandAttribute 的子类来实现在解析指令后触发指令前进行拦截。(如实现权限判断和指令冷却时间等)Microsoft.Extensions.DependencyInjection 的一个 Scope 中。可以根据需要添加自己的服务。CommandParameter 指定)。[ParsedArguments] object[] args)。BaseSoraEventArgs、PrivateMessageEventArgs、GroupMessageEventArgs。IServiceScope。OneBotContext。OneBot.FrameworkDemo.Modules.TestModule。
public TestModule(ICommandService commandService, ILogger<TestModule> logger)
{
// 通过构造函数获得指令路由服务对象
// 基本事件处理例子
// 如果你不想要指令路由,可以使用这个方法来注册最原始的事件监听方法
commandService.Event.OnGroupMessage += (context) =>
{
var args = context.WrapSoraEventArgs<GroupMessageEventArgs>();
// 在控制台中复读群里的信息
logger.LogInformation($"{args.SourceGroup.Id} : {args.Sender.Id} : {args.Message.RawText}");
return 0;
// 这里返回 0,表示继续传递该事件给后续的指令或监听。
};
// 全局异常处理事件
commandService.Event.OnException += (context, exception) =>
{
logger.LogError($"{exception.Message}");
};
_logger = logger;
}
OneBot.FrameworkDemo.Middleware.TestMiddlewareint 类型,基本事件返回 int 类型。若返回值为 1 则该事件阻断,不再传递给后续指令或事件监听函数;若返回值为 0 则继续传递。| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 3.3.0 | 343 | 11/19/2022 | |
| 3.2.4 | 250 | 10/29/2022 | |
| 3.2.3 | 300 | 5/10/2022 | |
| 3.2.2 | 311 | 3/4/2022 | |
| 3.2.1 | 528 | 2/1/2022 | |
| 3.2.0 | 536 | 1/30/2022 | |
| 3.1.0 | 514 | 1/22/2022 | |
| 3.0.0 | 554 | 1/19/2022 | |
| 2.0.2 | 514 | 1/17/2022 | |
| 2.0.1 | 645 | 1/17/2022 | 2.0.1 is deprecated because it has critical bugs. |
| 2.0.0 | 532 | 1/17/2022 | |
| 1.5.1 | 393 | 8/18/2021 | |
| 1.5.0 | 350 | 8/15/2021 | |
| 1.4.1 | 364 | 4/16/2021 | |
| 1.4.0 | 411 | 4/8/2021 | |
| 1.3.2 | 521 | 3/15/2021 | |
| 1.3.1 | 586 | 3/15/2021 | |
| 1.3.0 | 929 | 3/15/2021 | 1.3.0 is deprecated because it has critical bugs. |
| 1.2.1 | 548 | 3/9/2021 | |
| 1.2.0 | 548 | 2/26/2021 |