asg_backend/qqbot/ExamplePlugin.cs

67 lines
1.8 KiB
C#
Raw Permalink Normal View History

2024-10-02 17:53:16 +08:00
using asg_form.Controllers;
using Flandre.Core.Common;
using Flandre.Core.Messaging;
using Flandre.Framework.Common;
using Flandre.Framework.Routing;
2024-10-19 00:43:22 +08:00
using Zack.EventBus;
2024-10-02 17:53:16 +08:00
namespace qqbot
{
public sealed class ExamplePlugin : Plugin
{
2024-10-19 00:43:22 +08:00
private IEventBus eventBus;
public ExamplePlugin(IEventBus eventBus)
{
this.eventBus = eventBus;
}
2024-10-02 17:53:16 +08:00
/// <summary>
/// 每次收到消息时触发。
/// </summary>
public override async Task OnMessageReceivedAsync(MessageContext ctx)
{
// 如果消息文本为 "Hello!"
if (ctx.Message.GetText() == "Hello!")
{
// 则发送一条 "World!" 消息作为回复。
await ctx.Bot.SendMessageAsync(ctx.Message, "World!");
}
}
/// <summary>
/// 定义一条指令。<br/>
/// 向机器人发送 "example {num}" 时触发,其中 num 为一个合法的 double 值。
/// </summary>
///
/// <param name="num">
/// 定义一个参数。框架会自动识别参数的类型,并解析用户传入的文本。
/// </param>
///
/// <returns>
/// 指令方法需要返回机器人的回复消息。
/// </returns>
///
/// <example>
/// 发送example 1.28 <br/>
/// 回复1.28 的二次方为 1.6384。
/// </example>
[Command]
public string (string name)
{
try
{
2024-10-19 00:43:22 +08:00
eventBus.Publish("查询选手", name);
2024-10-02 17:53:16 +08:00
2024-10-19 00:43:22 +08:00
return null;
2024-10-02 17:53:16 +08:00
}
catch
{
return "出现错误";
}
}
}
}