public async Task <bool> GroupMessage(MiraiHttpSession session, IGroupMessageEventArgs e) { Stopwatch sw = Stopwatch.StartNew(); if (e.Chain[1] is PlainMessage) { var plain = e.Chain[1] as PlainMessage; lock (Instance.LogLocker) { Console.Write("[" + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "] ", Color.Yellow); Console.Write("[MESSAGE] ", Color.ForestGreen); Console.Write("[" + e.Sender.Group.Name + "]: ", Color.Orange); Console.Write("[" + e.Sender.Name + "]: ", Color.Cyan); Console.WriteLine(plain.Message.Replace("\n", "\\n")); } var data = valuePairs(configType.自动回复); if (data.Keys.Contains(plain.Message)) { if (data[plain.Message].Contains('|')) { var messages = data[plain.Message].Split('|'); Random rnd = new Random(); StringBuilder sb = new StringBuilder(); var lines = messages[rnd.Next(0, messages.Length)].Split('\\'); foreach (var line in lines) { sb.AppendLine(line); } foreach (var message in SplitLongMessage(sb.ToString())) { if (message.Contains("@发送者")) { List <IMessageBase> mb = new List <IMessageBase>(); var splits = message.Split("@发送者"); foreach (var split in splits) { if (string.IsNullOrWhiteSpace(split) || string.IsNullOrEmpty(split)) { continue; } mb.Add(new AtMessage(e.Sender.Id)); mb.Add(new PlainMessage(split)); } await session.SendGroupMessageAsync(e.Sender.Group.Id, mb.ToArray()); } else { await session.SendGroupMessageAsync(e.Sender.Group.Id, new IMessageBase[] { new PlainMessage(message) }); } Thread.Sleep(rnd.Next(1000, 4000)); } } else { StringBuilder sb = new StringBuilder(); var lines = data[plain.Message].Split('\\'); foreach (var line in lines) { sb.AppendLine(line); } Random rnd = new Random(); foreach (var message in SplitLongMessage(sb.ToString())) { if (message.Contains("@发送者")) { List <IMessageBase> mb = new List <IMessageBase>(); var splits = message.Split("@发送者"); foreach (var split in splits) { if (string.IsNullOrWhiteSpace(split) || string.IsNullOrEmpty(split)) { continue; } mb.Add(new AtMessage(e.Sender.Id)); mb.Add(new PlainMessage(split)); } await session.SendGroupMessageAsync(e.Sender.Group.Id, mb.ToArray()); } else { await session.SendGroupMessageAsync(e.Sender.Group.Id, new IMessageBase[] { new PlainMessage(message) }); } Thread.Sleep(rnd.Next(1000, 4000)); } } } else if (plain.Message.StartsWith("/")) { var eventArgs = new ChainEventArgs() { Message = plain.Message, MessageChain = e.Chain, Sender = e.Sender, Session = session }; using GameAPI Member = new GameAPI(eventArgs); Instance.chains[0].SetMember(Member.Member); var result = await Instance.chains[0].GetReply(eventArgs); if (result.Count() > 0) { await session.SendGroupMessageAsync(e.Sender.Group.Id, result.ToArray()); } else if (!Instance.GameEnabled.Any(x => x == e.Sender.Group.Id)) { switch (plain.Message) { case "/拉霸": Member.JackPot(); break; case "/寻宝": Member.FindTreasure(); break; case "/帮助": Member.Help(); break; case "/工作": Member.MemberWork(); break; case "/我": Member.MemberCheck(); break; case "/21点": Member.Member21Point(); break; case "/排名": Member.GetRank(); break; case "/合成A": case "/合成a": Member.Buff("A"); break; case "/合成H": case "/合成h": Member.Buff("H"); break; case "/拍卖场": Member.ListTrade(); break; default: if (plain.Message.StartsWith("/打劫")) { Member.Robber(new ChainEventArgs() { Message = plain.Message, MessageChain = e.Chain, Sender = e.Sender, Session = session }); } else if (plain.Message.StartsWith("/购买")) { Member.Shop(new ChainEventArgs() { Message = plain.Message, MessageChain = e.Chain, Sender = e.Sender, Session = session }); } else if (plain.Message.StartsWith("/技能")) { Member.SkillShop(new ChainEventArgs() { Message = plain.Message, MessageChain = e.Chain, Sender = e.Sender, Session = session }); } else if (plain.Message.StartsWith("/拍卖场购买")) { Member.PurchaseTradeItem(plain.Message); } else if (plain.Message.StartsWith("/拍卖场出售")) { Member.SellTradeItem(plain.Message); } break; } } } sw.Stop(); Logger.Instance.AddLog(LogType.Debug, "消息处理完毕,使用了" + sw.Elapsed.TotalMilliseconds + "毫秒"); return(true); } else { lock (Instance.LogLocker) { Console.Write("[" + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "] ", Color.Yellow); Console.Write("[MESSAGE] ", Color.ForestGreen); Console.Write("[" + e.Sender.Group.Name + "]: ", Color.FloralWhite); Console.Write("[" + e.Sender.Name + "]: ", Color.Cyan); for (int x = 1; x < e.Chain.Length; x++) { Console.Write(e.Chain[x].ToString().Replace("\n", "\\n")); } Console.WriteLine(); } } if (Directory.Exists("Buffer")) { foreach (var file in Directory.GetFiles("Buffer")) { FileInfo info = new FileInfo(file); var alived = DateTime.Now - info.CreationTime; if (alived.TotalDays >= 1) { try { info.Delete(); } catch { Logger.Instance.AddLog(LogType.Error, "缓存文件[" + file + "]无法被删除!"); } } } } sw.Stop(); Logger.Instance.AddLog(LogType.Debug, "消息处理完毕,使用了" + sw.Elapsed.TotalMilliseconds + "毫秒"); return(false); }