feat: 新功能
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 猜成语
|
||||
/// </summary>
|
||||
public class ChineseIdiomsProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 处理群消息
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
string groupMsg = JArray.Parse(json["message"].ToString()).FirstOrDefault(o => o["type"].ToString() == "text"
|
||||
&& !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()) && (o["data"]["text"].ToString().Contains("要道友看表情猜成语")))?["data"]?["text"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(groupMsg)) return false;
|
||||
|
||||
string pattern = @"题目:(.+)";
|
||||
Match match = Regex.Match(groupMsg, pattern);
|
||||
if (match.Success)
|
||||
{
|
||||
string emojiString = match.Groups[1].Value.Trim();
|
||||
Dictionary<string, string> dict = App.GetConfig<Dictionary<string, string>>("猜成语");
|
||||
if (dict?.Count > 0)
|
||||
{
|
||||
foreach (var item in dict)
|
||||
{
|
||||
if (emojiString.Contains(item.Key))
|
||||
{
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "reply",
|
||||
Data = new()
|
||||
{
|
||||
Id = json["message_id"].ToString()
|
||||
}
|
||||
},
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = item.Value
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 猜成语 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 坊市上架命令
|
||||
/// </summary>
|
||||
public class GoodsUpShopProcess
|
||||
{
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
var messageArray = JArray.Parse(json["message"].ToString());
|
||||
string groupMsg = messageArray.FirstOrDefault(o => o["type"].ToString() == "text"
|
||||
&& !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()))?["data"]?["text"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(groupMsg)) return false;
|
||||
|
||||
// 小小药材背包
|
||||
List<string> keyWord = new() { "拥有数量", "坊市数据" };
|
||||
if (keyWord.All(k => groupMsg.Contains(k)))
|
||||
{
|
||||
RedisHelper.Client.Set(json["message_id"].ToString(), groupMsg, 60 * 10);
|
||||
}
|
||||
// 用户查询上架
|
||||
else if (groupMsg.Contains("查价格") || groupMsg.Contains("查上架") && messageArray.Any(o => o["type"].ToString() == "reply"))
|
||||
{
|
||||
string replyId = messageArray.FirstOrDefault(o => o["type"].ToString() == "reply")["data"]["id"].ToString();
|
||||
var goodsStr = RedisHelper.Client.Get(replyId);
|
||||
if (string.IsNullOrEmpty(goodsStr) is false)
|
||||
{
|
||||
bool upCmd = groupMsg.Contains("-f");
|
||||
|
||||
_ = Herbal(groupId, goodsStr, upCmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = "没有查询到缓存,请重新艾特小小查药材背包"
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 坊市上架命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task<bool> Herbal(string groupId, string text, bool upCmd)
|
||||
{
|
||||
List<GoodsInfo> results = [];
|
||||
var lines = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.StartsWith("品级:"))
|
||||
{
|
||||
_ = line.Substring("品级:".Length).Trim();
|
||||
}
|
||||
else if (line.StartsWith("名字:"))
|
||||
{
|
||||
var name = line.Substring("名字:".Length).Trim();
|
||||
// 找到下一行的数量
|
||||
var index = Array.IndexOf(lines, line);
|
||||
if (index + 1 < lines.Length && lines[index + 1].StartsWith("拥有数量:"))
|
||||
{
|
||||
var quantityLine = lines[index + 1];
|
||||
var match = Regex.Match(quantityLine, @"拥有数量:(\d+)");
|
||||
if (match.Success)
|
||||
{
|
||||
var quantity = match.Groups[1].Value;
|
||||
results.Add(new() { Name = name, Num = Convert.ToInt32(quantity) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string msg = "";
|
||||
decimal totalPrice = 0;
|
||||
decimal fee = 0;
|
||||
// 打印结果
|
||||
foreach (var item in results)
|
||||
{
|
||||
var current = RedisHelper.Client.HGet<GoodsInfo>(RedisPrefix.GoodsKey, item.Name);
|
||||
if (current is not null)
|
||||
{
|
||||
int num = item.Num.Value > 10 ? 10 : item.Num.Value;
|
||||
decimal nicePrice = current.Price - 100000;
|
||||
totalPrice += Convert.ToDecimal(nicePrice * num);
|
||||
|
||||
fee += Math.Round(Utils.CalculateFee(nicePrice) * num, 0);
|
||||
|
||||
if (upCmd)
|
||||
{
|
||||
msg += $"确认坊市上架{item.Name} {(int)current.Price - 100000} {num}|";
|
||||
}
|
||||
else
|
||||
{
|
||||
msg += $"确认坊市上架{item.Name} {(int)current.Price - 100000} {num}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(msg) is false)
|
||||
{
|
||||
if (!upCmd)
|
||||
{
|
||||
msg += "\r\n";
|
||||
msg += "使用前请先@小小查看坊市药材,过完一遍以获取最新价格\r\n当前价格为坊市价格-10w\r\n";
|
||||
msg += $"总价值约:{Utils.FormatNumberToChineseUnit(totalPrice)}\r\n";
|
||||
msg += $"手续费约:{Utils.FormatNumberToChineseUnit(fee)}\r\n";
|
||||
msg += $"到账约:{Utils.FormatNumberToChineseUnit(totalPrice - fee)}";
|
||||
}
|
||||
if (msg[^1] == '|') msg = msg[..^1];
|
||||
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = msg
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
}
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 查丹方
|
||||
/// </summary>
|
||||
public class ImmortalElixirProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 处理群消息
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
var messageArray = JArray.Parse(json["message"].ToString());
|
||||
string groupMsg = messageArray.FirstOrDefault(o => o["type"].ToString() == "text"
|
||||
&& !string.IsNullOrWhiteSpace(o["data"]["text"].ToString())
|
||||
&& o["data"]["text"].ToString().Contains("查丹方")
|
||||
)?["data"]?["text"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(groupMsg)) return false;
|
||||
|
||||
var rbotQ = messageArray.FirstOrDefault(o => o["type"].ToString() == "at")?["data"]?["qq"]?.ToString();
|
||||
|
||||
// 判断是否@了机器人
|
||||
if (rbotQ == App.Configuration["QQConfig:RobotQQ"])
|
||||
{
|
||||
// 提取物品名称
|
||||
var goodsName = groupMsg
|
||||
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
||||
.FirstOrDefault(word => word != "查丹方")
|
||||
?.Replace("查丹方", "")?.Trim();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(goodsName))
|
||||
{
|
||||
Dictionary<string, string> dict = App.GetConfig<Dictionary<string, string>>("丹方");
|
||||
if (dict?.Count > 0)
|
||||
{
|
||||
dict.TryGetValue(goodsName, out string doc);
|
||||
if (string.IsNullOrWhiteSpace(doc) is false)
|
||||
{
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = doc
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 查丹方命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@ using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 灵田结算
|
||||
/// </summary>
|
||||
public class LingTianProcess
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
using System.Globalization;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 秘境通知
|
||||
/// </summary>
|
||||
public class MiJingNotifyProcess
|
||||
{
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
var messageArray = JArray.Parse(json["message"].ToString());
|
||||
string groupMsg = messageArray.FirstOrDefault(o => o["type"].ToString() == "text"
|
||||
&& !string.IsNullOrWhiteSpace(o["data"]["text"].ToString())
|
||||
&& (o["data"]["text"].ToString().Contains("进入秘境:") || o["data"]["text"].ToString().Contains("道友已踏入:"))
|
||||
)?["data"]?["text"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(groupMsg)) return false;
|
||||
|
||||
var minutes = ParseMinutes(groupMsg);
|
||||
if (minutes > 0)
|
||||
{
|
||||
var atData = messageArray.FirstOrDefault(o => o["type"].ToString() == "at");
|
||||
if (atData is not null)
|
||||
{
|
||||
ScheduleReminder(groupId, atData["data"]["qq"].ToString(), minutes);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 秘境结束通知 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static void ScheduleReminder(string groupId, string userId, double minutes)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
TimeSpan delay = TimeSpan.FromMinutes(minutes);
|
||||
|
||||
Log.Information($@"{now:yyyy-MM-dd HH:mm:ss} {userId} 触发秘境通知 {minutes}分钟 结束时间: {now.AddMinutes(minutes):yyyy-MM-dd HH:mm:ss}");
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(delay);
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = $"【秘境结算通知】\r\n探索已完成,该结算奖励了!({minutes} 分钟)"
|
||||
}
|
||||
},
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "at",
|
||||
Data = new()
|
||||
{
|
||||
QQ = userId
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
});
|
||||
}
|
||||
|
||||
private static double ParseMinutes(string content)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(content)) return 0;
|
||||
|
||||
var match = Regex.Match(content, @"(花费时间|探索耗时)[::]\s*(\d+(?:\.\d+)?)", RegexOptions.Compiled);
|
||||
if (!match.Success)
|
||||
{
|
||||
match = Regex.Match(content, @"(\d+(?:\.\d+)?)", RegexOptions.Compiled);
|
||||
}
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
if (double.TryParse(match.Groups[2].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out double val))
|
||||
{
|
||||
return (double)val;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user