diff --git a/Lagrange.XocMat/Event/TerrariaMsgReceiveHandler.cs b/Lagrange.XocMat/Event/TerrariaMsgReceiveHandler.cs index b854213..58a9a9f 100644 --- a/Lagrange.XocMat/Event/TerrariaMsgReceiveHandler.cs +++ b/Lagrange.XocMat/Event/TerrariaMsgReceiveHandler.cs @@ -15,6 +15,7 @@ using Lagrange.XocMat.Internal.Socket.PlayerMessage; using Lagrange.XocMat.Internal.Socket.ServerMessage; using Lagrange.XocMat.Net; +using Lagrange.XocMat.Utility; using Microsoft.Extensions.Logging; using ProtoBuf; using System.Reactive.Linq; @@ -253,6 +254,17 @@ internal async void GroupMessageForwardAdapter(BotContext bot, GroupMessageEvent { return; } + var file = args.Chain.GetFile(); + if (file != null && file.FileSize < 1024 * 1024 * 30) + { + foreach(var setting in XocMatSetting.Instance.Servers) + { + if (file.FileUrl != null && setting != null && setting.Groups.Contains(Convert.ToUInt32(args.Chain.GroupUin)) && setting.WaitFile != null) + { + setting.WaitFile.SetResult(await HttpUtils.HttpGetByte(file.FileUrl)); + } + } + } var text = args.Chain.GetText(); if (string.IsNullOrEmpty(text)) return; diff --git a/Lagrange.XocMat/Extensions/MessageChainExt.cs b/Lagrange.XocMat/Extensions/MessageChainExt.cs index b6f9cd3..539860c 100644 --- a/Lagrange.XocMat/Extensions/MessageChainExt.cs +++ b/Lagrange.XocMat/Extensions/MessageChainExt.cs @@ -22,6 +22,6 @@ public static string GetText(this MessageChain chain) public static FileEntity? GetFile(this MessageChain chain) { - return (FileEntity)chain.Where(c => c is FileEntity).First(); + return (FileEntity?)chain.Where(c => c is FileEntity).FirstOrDefault(); } }