You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.9 KiB
C#
48 lines
1.9 KiB
C#
using System.Text.RegularExpressions;
|
|
using Lagrange.Core.Message;
|
|
using Lagrange.Core.Message.Entity;
|
|
using RoBot.Core.Helper;
|
|
using RoBot.Start.Global;
|
|
using Lagrange.Core.Common.Interface.Api;
|
|
using RoBot.Start.LogConfig;
|
|
|
|
namespace RoBot.Start.Cmd
|
|
{
|
|
/// <summary>
|
|
/// 猜成语
|
|
/// </summary>
|
|
public class ChineseIdiomsCmd
|
|
{
|
|
public static async Task<bool> Execute(MessageChain chain)
|
|
{
|
|
try
|
|
{
|
|
var textEntities = chain.Where(o => o is TextEntity).ToList();
|
|
TextEntity input = textEntities.Cast<TextEntity>().ToList().FirstOrDefault(o => o.Text.Contains("要道友看表情猜成语"));
|
|
if (input is not null)
|
|
{
|
|
string pattern = @"题目:(.+)";
|
|
Match match = Regex.Match(input.Text, pattern);
|
|
if (match.Success)
|
|
{
|
|
string emojiString = match.Groups[1].Value.Trim();
|
|
Dictionary<string, string> dict = AppConfigHelper.GetSection<Dictionary<string, string>>("猜成语");
|
|
if (dict?.Count > 0 && dict.TryGetValue(emojiString, out string val))
|
|
{
|
|
var systemConfig = GlobalConfig.ConfigSetting;
|
|
var bot = GlobalConfig.BotContext;
|
|
var groupMessageChain = MessageBuilder.Group((uint)systemConfig.GroupQQ).Forward(chain).Text(val);
|
|
await bot.SendMessage(groupMessageChain.Build());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 猜成语 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
|
}
|
|
return await Task.FromResult(true);
|
|
}
|
|
}
|
|
}
|