asg_backend/qqbot/ExamplePlugin.cs
2024-10-02 17:53:16 +08:00

63 lines
1.9 KiB
C#
Raw 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;
namespace qqbot
{
public sealed class ExamplePlugin : Plugin
{
/// <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
{
TestDbContext ctx = new TestDbContext();
string msg = "";
var roles = ctx.Roles.Where(a => a.role_name.IndexOf(name) >= 0).ToList();
foreach (var role in roles)
{
msg = $"{msg}\r\n姓名:{role.role_name}\r\n第五人格ID:{role.role_id}\r\n选手id:{role.Id}\r\n阵营:{role.role_lin}\r\n";
}
return msg;
}
catch
{
return "出现错误";
}
}
}
}