|
|
|
|
@ -2,20 +2,17 @@
|
|
|
|
|
using Lagrange.Core.Common.Interface;
|
|
|
|
|
using Lagrange.Core.Common.Interface.Api;
|
|
|
|
|
using Lagrange.Core.Message;
|
|
|
|
|
using Lagrange.Core.Message.Entity;
|
|
|
|
|
using RoBot.Core.ConstValue;
|
|
|
|
|
using RoBot.Core.Redis;
|
|
|
|
|
using RoBot.Goods.Dto;
|
|
|
|
|
using RoBot.Goods.Service;
|
|
|
|
|
using RoBot.Core.Helper;
|
|
|
|
|
using RoBot.Start.Cmd;
|
|
|
|
|
using RoBot.Start.Device;
|
|
|
|
|
using RoBot.Start.Dto.ConfigDto;
|
|
|
|
|
using RoBot.Start.Global;
|
|
|
|
|
using RoBot.Start.Keystore;
|
|
|
|
|
using RoBot.Start.LogConfig;
|
|
|
|
|
using RoBot.Start.Message;
|
|
|
|
|
using RoBot.Start.RoBotConfig;
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
|
|
|
|
|
new RedisHelper();
|
|
|
|
|
|
|
|
|
|
// 登录状态
|
|
|
|
|
bool LoginSuccess = false;
|
|
|
|
|
@ -57,6 +54,7 @@ bot.Invoker.OnBotLogEvent += (sender, e) =>
|
|
|
|
|
RecordLog = false;
|
|
|
|
|
LoginSuccess = true;
|
|
|
|
|
_ = KeystoreConfig.SaveBotKeystore(bot.UpdateKeystore());
|
|
|
|
|
LoadLoginConfig();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -82,88 +80,32 @@ if ((args.Length > 0 && args[0] == "qr") || !ReLogin)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await bot.LoginByPassword();
|
|
|
|
|
LoadLoginConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task<bool> HandleGroupMessage(MessageChain chain)
|
|
|
|
|
{
|
|
|
|
|
// 判断是否是“@消息 + 文本”
|
|
|
|
|
if (chain.Count == 2 &&
|
|
|
|
|
chain.FirstOrDefault(e => e is MentionEntity) is MentionEntity mention &&
|
|
|
|
|
chain.FirstOrDefault(e => e is TextEntity) is TextEntity text)
|
|
|
|
|
{
|
|
|
|
|
// 判断是否@了机器人
|
|
|
|
|
if (mention.Uin == systemConfig.BotQQ)
|
|
|
|
|
{
|
|
|
|
|
string inputText = text.Text?.Trim();
|
|
|
|
|
|
|
|
|
|
// 判断是否包含“查价格”
|
|
|
|
|
if (!string.IsNullOrEmpty(inputText) && inputText.Contains("查价格"))
|
|
|
|
|
{
|
|
|
|
|
// 提取物品名称
|
|
|
|
|
var goodsName = inputText
|
|
|
|
|
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
|
|
|
|
.FirstOrDefault(word => word != "查价格")
|
|
|
|
|
?.Replace("查价格", "")?.Trim();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(goodsName))
|
|
|
|
|
{
|
|
|
|
|
var goodsInfo = RedisHelper.Client.HGet<GoodsInfo>(RedisPrefix.GoodsKey, goodsName);
|
|
|
|
|
|
|
|
|
|
if (goodsInfo is not null)
|
|
|
|
|
{
|
|
|
|
|
await bot.SendMsg((uint)systemConfig.GroupQQ,
|
|
|
|
|
$"物品:{goodsInfo.Name}\n价格:{goodsInfo.Price}万\n收录时间:{goodsInfo.LastUpdateTime:yyyy-MM-dd HH:mm:ss}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await bot.SendMsg((uint)systemConfig.GroupQQ, "未收录");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await bot.SendMsg((uint)systemConfig.GroupQQ, "请输入要查询的物品名称,例如:查价格 七星草");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 坊市生成上架命令
|
|
|
|
|
await QueryGoodsUpShopPriceCmd.Execute(chain);
|
|
|
|
|
|
|
|
|
|
// 保存或更新物品价格
|
|
|
|
|
await InertOrUpdateGoodsCmd.Execute(chain);
|
|
|
|
|
|
|
|
|
|
// 查看物品信息命令 价格/数据更新时间
|
|
|
|
|
await QueryGoodsInfoPriceCmd.Execute(chain);
|
|
|
|
|
|
|
|
|
|
foreach (var item in chain)
|
|
|
|
|
{
|
|
|
|
|
// 艾特消息
|
|
|
|
|
if (item is MentionEntity me)
|
|
|
|
|
{
|
|
|
|
|
Logs.Write($"提及用户的 Uin {me.Uin} 提及用户的 Uid {me.Uid} 提及用户的昵称{me.Name}");
|
|
|
|
|
}
|
|
|
|
|
// 文本消息
|
|
|
|
|
else if (item is TextEntity)
|
|
|
|
|
{
|
|
|
|
|
TextEntity txe = item as TextEntity;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(txe.Text) is false)
|
|
|
|
|
{
|
|
|
|
|
Logs.Write(txe.Text);
|
|
|
|
|
if (txe.Text.Contains("不鼓励不保障"))
|
|
|
|
|
{
|
|
|
|
|
GoodsService.AnalysisGoodsText(txe.Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 回复消息
|
|
|
|
|
else if (item is ForwardEntity)
|
|
|
|
|
{
|
|
|
|
|
ForwardEntity frd = item as ForwardEntity;
|
|
|
|
|
|
|
|
|
|
Logs.Write($"回复的目标消息 Seq {frd.Sequence} 发送者 Uid {frd.Uid} 回复的目标消息的发送者 Uin{frd.TargetUin}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 合并转发消息
|
|
|
|
|
else if (item is MultiMsgEntity)
|
|
|
|
|
{
|
|
|
|
|
MultiMsgEntity mme = item as MultiMsgEntity;
|
|
|
|
|
|
|
|
|
|
//Logs.Write($"回复的目标消息 Seq {frd.Sequence} 发送者 Uid {frd.Uid} 回复的目标消息的发送者 Uin{frd.TargetUin}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
|
{
|
|
|
|
|
_ = new RedisHelper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoadLoginConfig()
|
|
|
|
|
{
|
|
|
|
|
GlobalConfig.ConfigSetting = systemConfig;
|
|
|
|
|
GlobalConfig.KeystoreInfo = _keyStore;
|
|
|
|
|
GlobalConfig.BotDeviceInfo = _deviceInfo;
|
|
|
|
|
GlobalConfig.BotContext = bot;
|
|
|
|
|
}
|