asg_backend/qqbot/ExamplePlugin.cs
2024-10-19 00:43:22 +08:00

67 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using asg_form.Controllers;
using Flandre.Core.Common;
using Flandre.Core.Messaging;
using Flandre.Framework.Common;
using Flandre.Framework.Routing;
using Zack.EventBus;
namespace qqbot
{
public sealed class ExamplePlugin : Plugin
{
private IEventBus eventBus;
public ExamplePlugin(IEventBus eventBus)
{
this.eventBus = eventBus;
}
/// <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
{
eventBus.Publish("查询选手", name);
return null;
}
catch
{
return "出现错误";
}
}
}
}