feat:新增妖塔成语,需要在appsettings配置
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ namespace RoBot.Start.Cmd
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 坊市上架命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 坊市上架命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace RoBot.Start.Cmd
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 保存或更新物品价格 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 保存或更新物品价格 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace RoBot.Start.Cmd
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 灵田结算查价格 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 灵田结算查价格 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
|
||||
@@ -53,17 +53,13 @@ namespace RoBot.Start.Cmd
|
||||
await bot.SendMsg((uint)systemConfig.GroupQQ, "未收录");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await bot.SendMsg((uint)systemConfig.GroupQQ, "请输入要查询的物品名称,例如:查价格 七星草");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 查看物品信息命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 查看物品信息命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace RoBot.Start.Cmd
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 悬赏令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 悬赏令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user