feat:新增悬赏令
This commit is contained in:
+10
-3
@@ -2,6 +2,11 @@
|
|||||||
{
|
{
|
||||||
public class Utils
|
public class Utils
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 格式化数字为中文单位
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static string FormatNumberToChineseUnit(decimal number)
|
public static string FormatNumberToChineseUnit(decimal number)
|
||||||
{
|
{
|
||||||
if (number >= 100000000) // 亿
|
if (number >= 100000000) // 亿
|
||||||
@@ -20,6 +25,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析中文数字
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="chineseNumber"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static decimal ParseChineseNumber(string chineseNumber)
|
public static decimal ParseChineseNumber(string chineseNumber)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(chineseNumber))return 0;
|
if (string.IsNullOrWhiteSpace(chineseNumber))return 0;
|
||||||
@@ -59,8 +69,5 @@
|
|||||||
|
|
||||||
return amount * rate;
|
return amount * rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ namespace RoBot.Start.Cmd
|
|||||||
{
|
{
|
||||||
string desc = convertList[0].Text;
|
string desc = convertList[0].Text;
|
||||||
|
|
||||||
if (desc.Contains("拥有药材") || (desc.Contains("名字") && desc.Contains("拥有数量")))
|
if (desc.Contains("拥有药材") ||
|
||||||
|
desc.Contains("的丹药背包") ||
|
||||||
|
(desc.Contains("名字") && desc.Contains("拥有数量"))
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_ = Herbal(desc);
|
_ = Herbal(desc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,154 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Lagrange.Core.Message;
|
||||||
|
using Lagrange.Core.Message.Entity;
|
||||||
|
using RoBot.Core;
|
||||||
|
using RoBot.Core.ConstValue;
|
||||||
|
using RoBot.Core.Helper;
|
||||||
|
using RoBot.Start.Dto.Wanted;
|
||||||
|
using RoBot.Start.Global;
|
||||||
|
using RoBot.Start.Message;
|
||||||
|
using RoBot.Start.Service.Dto;
|
||||||
|
|
||||||
|
namespace RoBot.Start.Cmd
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 悬赏令
|
||||||
|
/// </summary>
|
||||||
|
public class WantedPriceCmd
|
||||||
|
{
|
||||||
|
public static async Task<bool> Execute(MessageChain chain)
|
||||||
|
{
|
||||||
|
var textEntities = chain.Where(o => o is TextEntity).ToList();
|
||||||
|
List<TextEntity> convertList = textEntities.Cast<TextEntity>().ToList().Where(o => o.Text.Contains("道友的个人悬赏令") || o.Text.Contains("天机悬赏令")).ToList();
|
||||||
|
|
||||||
|
foreach (var item in convertList)
|
||||||
|
{
|
||||||
|
List<WantedTaskInfo> wantedTasks = new();
|
||||||
|
if (item.Text.Contains("个人悬赏令"))
|
||||||
|
{
|
||||||
|
wantedTasks = await SingleWanted(item.Text);
|
||||||
|
}
|
||||||
|
else if (item.Text.Contains("天机悬赏令"))
|
||||||
|
{
|
||||||
|
wantedTasks = await SpecialWanted(item.Text);
|
||||||
|
}
|
||||||
|
if (wantedTasks.Count > 0)
|
||||||
|
{
|
||||||
|
var systemConfig = GlobalConfig.ConfigSetting;
|
||||||
|
var bot = GlobalConfig.BotContext;
|
||||||
|
|
||||||
|
string msg = "";
|
||||||
|
List<(int Id, decimal Price)> prices = new();
|
||||||
|
foreach (var want in wantedTasks)
|
||||||
|
{
|
||||||
|
msg += $"✨悬赏令 {want.Id} 奖励:{want.ExtraReward.Item}\r\n";
|
||||||
|
msg += $"🎁修为:{Utils.FormatNumberToChineseUnit(want.BaseReward)}\r\n";
|
||||||
|
var goodsInfo = RedisHelper.Client.HGet<GoodsInfo>(RedisPrefix.GoodsKey, want.ExtraReward.Item);
|
||||||
|
if (goodsInfo is not null)
|
||||||
|
{
|
||||||
|
msg += $"💵坊市价格:{goodsInfo.ShowPriceDesc}\r\n";
|
||||||
|
|
||||||
|
prices.Add((want.Id, goodsInfo.Price));
|
||||||
|
}
|
||||||
|
//msg += $"炼金价格:\r\n";
|
||||||
|
msg += $"\r\n";
|
||||||
|
}
|
||||||
|
var maxWanted = wantedTasks.MaxBy(o => o.BaseReward);
|
||||||
|
|
||||||
|
msg += "━━━━━━━━━━━━━━━\r\n";
|
||||||
|
msg += $"✨最高修为:悬赏令 {maxWanted.Id} ({Utils.FormatNumberToChineseUnit(maxWanted.BaseReward)})\r\n";
|
||||||
|
if (prices.Count > 0)
|
||||||
|
{
|
||||||
|
var maxPrice = prices.MaxBy(o => o.Price);
|
||||||
|
msg += $"💰最高价格:悬赏令 {maxPrice.Id} ({Utils.FormatNumberToChineseUnit(maxPrice.Price)})";
|
||||||
|
}
|
||||||
|
await bot.SendMsg((uint)systemConfig.GroupQQ, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return await Task.FromResult(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 个人悬赏令
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static async Task<List<WantedTaskInfo>> SingleWanted(string message)
|
||||||
|
{
|
||||||
|
List<WantedTaskInfo> result = new();
|
||||||
|
|
||||||
|
// 解析任务信息
|
||||||
|
var taskRegex = new Regex(
|
||||||
|
@"(?<id>\d+)、(?<name>.*?),
|
||||||
|
完成几率(?<rate>\d+),
|
||||||
|
基础报酬(?<reward>\d+)修为,
|
||||||
|
预计需(?<duration>\d+分钟),
|
||||||
|
可能额外获得:(?<grade>[^::]+):(?<item>[^!!]+)!?",
|
||||||
|
RegexOptions.IgnorePatternWhitespace);
|
||||||
|
|
||||||
|
foreach (Match match in taskRegex.Matches(message))
|
||||||
|
{
|
||||||
|
result.Add(new()
|
||||||
|
{
|
||||||
|
Id = int.Parse(match.Groups["id"].Value),
|
||||||
|
Name = match.Groups["name"].Value.Trim(),
|
||||||
|
SuccessRate = match.Groups["rate"].Value + "%",
|
||||||
|
BaseReward = long.Parse(match.Groups["reward"].Value),
|
||||||
|
Duration = match.Groups["duration"].Value,
|
||||||
|
ExtraReward = new ExtraReward
|
||||||
|
{
|
||||||
|
Grade = match.Groups["grade"].Value.Trim(),
|
||||||
|
Item = match.Groups["item"].Value.Trim()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return await Task.FromResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 天机悬赏令
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static async Task<List<WantedTaskInfo>> SpecialWanted(string message)
|
||||||
|
{
|
||||||
|
List<WantedTaskInfo> result = new();
|
||||||
|
|
||||||
|
var blockRegex = new Regex(
|
||||||
|
@"悬赏(?<idCN>[壹贰叁肆伍陆柒捌玖拾])·(?<name>[^\n\r]+)\s+" +
|
||||||
|
@".*?成功率:(?<rate>\d+)%\s+" +
|
||||||
|
@".*?预计耗时:(?<duration>[\d一二三四五六七八九十]+分钟)\s+" +
|
||||||
|
@".*?基础奖励(?<reward>\d+)修为\s+" +
|
||||||
|
@".*?额外机缘:(?<grade>[^「」]+)「(?<item>[^」]+)」",
|
||||||
|
RegexOptions.Multiline);
|
||||||
|
|
||||||
|
foreach (Match match in blockRegex.Matches(message))
|
||||||
|
{
|
||||||
|
string idCN = match.Groups["idCN"].Value;
|
||||||
|
result.Add(new()
|
||||||
|
{
|
||||||
|
Id = ChineseNumberMap.ContainsKey(idCN) ? ChineseNumberMap[idCN] : 0,
|
||||||
|
Name = match.Groups["name"].Value.Trim(),
|
||||||
|
SuccessRate = match.Groups["rate"].Value + "%",
|
||||||
|
Duration = match.Groups["duration"].Value.Trim(),
|
||||||
|
BaseReward = long.Parse(match.Groups["reward"].Value),
|
||||||
|
ExtraReward = new ExtraReward
|
||||||
|
{
|
||||||
|
Grade = match.Groups["grade"].Value.Trim(),
|
||||||
|
Item = match.Groups["item"].Value.Trim()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return await Task.FromResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, int> ChineseNumberMap = new()
|
||||||
|
{
|
||||||
|
{ "壹", 1 }, { "贰", 2 }, { "叁", 3 }, { "肆", 4 }, { "伍", 5 },
|
||||||
|
{ "陆", 6 }, { "柒", 7 }, { "捌", 8 }, { "玖", 9 }, { "拾", 10 }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
namespace RoBot.Start.Dto.Wanted
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 悬赏令信息
|
||||||
|
/// </summary>
|
||||||
|
public class WantedTaskInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 序号
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 任务名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 成功几率
|
||||||
|
/// </summary>
|
||||||
|
public string SuccessRate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修为值
|
||||||
|
/// </summary>
|
||||||
|
public long BaseReward { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 需要时间
|
||||||
|
/// </summary>
|
||||||
|
public string Duration { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 额外奖励
|
||||||
|
/// </summary>
|
||||||
|
public ExtraReward ExtraReward { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 额外奖励
|
||||||
|
/// </summary>
|
||||||
|
public class ExtraReward
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 奖励等级
|
||||||
|
/// </summary>
|
||||||
|
public string Grade { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 奖励物品
|
||||||
|
/// </summary>
|
||||||
|
public string Item { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,6 +53,7 @@ bot.Invoker.OnBotLogEvent += (sender, e) =>
|
|||||||
{
|
{
|
||||||
RecordLog = false;
|
RecordLog = false;
|
||||||
LoginSuccess = true;
|
LoginSuccess = true;
|
||||||
|
Logs.Write($"Login success: {bot.BotUin} {bot.BotName}");
|
||||||
_ = KeystoreConfig.SaveBotKeystore(bot.UpdateKeystore());
|
_ = KeystoreConfig.SaveBotKeystore(bot.UpdateKeystore());
|
||||||
LoadLoginConfig();
|
LoadLoginConfig();
|
||||||
}
|
}
|
||||||
@@ -85,6 +86,9 @@ else
|
|||||||
|
|
||||||
async Task<bool> HandleGroupMessage(MessageChain chain)
|
async Task<bool> HandleGroupMessage(MessageChain chain)
|
||||||
{
|
{
|
||||||
|
// 悬赏令查价
|
||||||
|
await WantedPriceCmd.Execute(chain);
|
||||||
|
|
||||||
// 坊市生成上架命令
|
// 坊市生成上架命令
|
||||||
await QueryGoodsUpShopPriceCmd.Execute(chain);
|
await QueryGoodsUpShopPriceCmd.Execute(chain);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user