67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
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 "出现错误";
|
||
}
|
||
|
||
}
|
||
}
|
||
} |