public async Task <bool> Accept(MiraiHttpSession session, IGroupMessageEventArgs e) { if (!Config.ApplyedGroups.Contains(e.Sender.Group.Id) || !Utility.SiglePlainMessageChecker(e)) { return(false); } if (((PlainMessage)e.Chain[1]).Message.ToLower() != "accept") { return(false); } var task = Global.currentTask[e.Sender.Group.Id]; if (task == null) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage("当前无挂起的task!")); return(false); } else { if (!Global.acceptList[e.Sender.Group.Id].Add(e.Sender.Id)) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new IMessageBase[] { new PlainMessage("请勿重复确认") }, ((SourceMessage)e.Chain[0]).Id); return(false); } //这个顺序是为了保证即使禁言操作抛出了异常,send group message也能正常输出最后一个同步状态而不用写一个丑陋的try-finally块 await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage($"同步状态{task.CurrentMemberNum + 1}/{task.MemberNumRequired}")); await task.IncreaseCurrentNum(); } return(false); }
public async Task <bool> GroupMessage(MiraiHttpSession session, IGroupMessageEventArgs e) { try { if (e.Chain.Length > 1) { bool isReply = false, isAtSource = false; IMessageBuilder builder = new MessageBuilder(); ReplyMessage(e.Chain, builder, e.Sender.Id, ref isReply); if (isReply) //是否回复消息 { if (isAtSource) //是否@消息源 { await session.SendGroupMessageAsync(e.Sender.Group.Id, builder, Convert.ToInt32(e.Chain[0].ToString())); } else { await session.SendGroupMessageAsync(e.Sender.Group.Id, builder); } } } } catch { } return(false); }
public override void SendGroupMessage(GroupID groupID, string message) { var isCommonMessage = message.Contains("好嘞") || message.Contains("很抱歉, 这个命令可能需要更长的时间来执行.") || message.Contains("I want to buy"); // 这里仅仅为临时方案 if (MiraiConfig.Instance.RenderTextInImage && !isCommonMessage) { var imageMsg = session.UploadPictureAsync(UploadTarget.Group, RenderImage(message)).Result; var regex = new Regex( @"(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$])", RegexOptions.Multiline | RegexOptions.IgnoreCase).Matches(message); if (regex.Count > 0) { session.SendGroupMessageAsync(groupID, imageMsg, new PlainMessage(regex.Connect("\n"))).Wait(); } else { session.SendGroupMessageAsync(groupID, imageMsg).Wait(); } } else { session.SendGroupMessageAsync(groupID, new PlainMessage(message)).Wait(); } }
public static async Task RunTemp(CommandParser.Config args, MiraiHttpSession session, ITempMessageEventArgs e) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new AtMessage(e.Sender.Id), new PlainMessage("\r\n正在保存...")); var user = new User(e.Sender.Id) { Username = args.Username, Password = args.Password }; bool ok = await user.TrySave(); await session.SendGroupMessageAsync(e.Sender.Group.Id, new AtMessage(e.Sender.Id), new PlainMessage(ok ? "\r\n成功更改了配置。" : "抱歉,遇到了错误,请稍后再试。")); }
public async Task <bool> MemberKick(MiraiHttpSession session, IGroupMessageEventArgs e) { if (!Config.ApplyedGroups.Contains(e.Sender.Group.Id)) { return(false); } string?command; bool iscommand = Utility.ProcessCommandSession(e, out command); if (!iscommand) { return(false); } var commandArgs = command.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (commandArgs.Length != 2 || !memberKickCommandList.Contains(commandArgs[0])) { return(false); } long target; if (!long.TryParse(commandArgs[1], out target)) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new IMessageBase[] { new PlainMessage("输入的参数有误") }, ((SourceMessage)e.Chain[0]).Id); return(false); } if (Global.currentTask[e.Sender.Group.Id] != null) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new IMessageBase[] { new AtMessage(e.Sender.Id), new PlainMessage("已有命令注册,请等待被注册命令结束") }); return(false); } Global.currentTask[e.Sender.Group.Id] = new MemberKick(target, e.Sender.Group.Id, session); await Task.Delay(TimeSpan.FromMinutes(2)); if (Global.currentTask[e.Sender.Group.Id] != null) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage("挂起的任务已超时")); } Global.currentTask[e.Sender.Group.Id] = null; return(false); }
internal static async Task <int> CommonSendMessage(long id, bool isGroup, IMessageBase[] chain, int?quote) { if (!MiddlewareCore.OnSend(ref id, ref isGroup, ref chain, ref quote)) { return(0); } if (isGroup) { return(await session.SendGroupMessageAsync(id, chain, quote)); } else { if (BotInfo.HasFriend(id)) { return(await session.SendFriendMessageAsync(id, chain, quote)); } int msgid = 0; long[] tempPath = BotInfo.GetTempPath(id); foreach (var t in tempPath) { try { msgid = await session.SendTempMessageAsync(id, t, chain, quote); break; } catch { } } return(msgid); } }
public async Task <bool> TempMessage(MiraiHttpSession session, ITempMessageEventArgs e) { if (e.Chain.Length != 2 || !(e.Chain[1] is PlainMessage)) { return(false); } var cmd = ((PlainMessage)e.Chain[1]).Message.Split(' ').Where(s => s != string.Empty).ToArray(); if (!CalenderBot.Config.CommandStart.Contains(cmd[0])) { return(false); } var helpMsg = new StringBuilder(); using var writer = new StringWriter(helpMsg); var parser = new Parser(config => config.HelpWriter = writer); await parser.ParseArguments <CommandParser.Default, CommandParser.Config, CommandParser.GenerateCalender>(cmd.Skip(1)) .WithParsedAsync <CommandParser.Config>(async with => await ConfigUser.RunTemp(with, session, e)); if (helpMsg.Length != 0) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new IMessageBase[] { new AtMessage(e.Sender.Id), new PlainMessage("\r\n" + helpMsg.ToString()) }); } return(false); }
public MemberKick(long objectId, long gpid, MiraiHttpSession session) : base(objectId, gpid) { this.session = session; session.SendGroupMessageAsync(GroupId, new IMessageBase[] { new PlainMessage("即将进行对"), new AtMessage(ObjectId), new PlainMessage("的移除操作,该操作需要5名群友进行同步,输入accept来进行确认") }).Wait(); }
public async void DoHandleAsync(MiraiHttpSession session, IMessageBase[] chain, IBaseInfo info, bool isGroupMessage = true) { ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar(); var now = DateTime.Now; var year = calendar.GetYear(now); var month = calendar.GetMonth(now); var day = calendar.GetDayOfMonth(now); var hasLeapMonth = calendar.GetLeapMonth(year) > 0; if (hasLeapMonth) { if (month < 13 && day < 23) { if (month > 1 && day > 15) { return; } } } else { if (month < 12 && day < 23) { if (month > 1 && day > 15) { return; } } } List <IMessageBase> result = new List <IMessageBase>(); IMessageBase img = null; switch (chain.First(m => m.Type == "Plain").ToString()) { case "新年快乐": img = await session.UploadPictureAsync(UploadTarget.Group, "Resources\\NewYear\\NewYearStick.png"); result.Add(img); break; case "新年抽签": string[] lotterise = Directory.GetFiles("Resources\\Lottery"); img = await session.UploadPictureAsync(UploadTarget.Group, lotterise[randomer.Next(0, lotterise.Length - 1)]); result.Add(img); break; default: break; } if (isGroupMessage) { await session.SendGroupMessageAsync(((IGroupMemberInfo)info).Group.Id, result.ToArray()); } else { await session.SendFriendMessageAsync(info.Id, result.ToArray()); } }
public override async Task Act() { Global.currentTask[GroupId] = null; await session.SendGroupMessageAsync(GroupId, new PlainMessage("正在向服务器发送移除请求,请注意,若禁言的对象是机器人本身或权" + "限高于等于机器人的对象,则不会生效")); await session.KickMemberAsync(ObjectId, GroupId); }
public override void SendGroupMessage(GroupID groupID, string message) { var isCommonMessage = message.Contains("好嘞") || message.Contains("很抱歉, 这个命令可能需要更长的时间来执行.") || message.Contains("I want to buy"); session.SendGroupMessageAsync(groupID, new PlainMessage(message)).Wait(); }
public MemberBan(long objectId, long gpid, MiraiHttpSession session, TimeSpan banSpan) : base(objectId, gpid) { BanSpan = banSpan; this.session = session; session.SendGroupMessageAsync(gpid, new IMessageBase[] { new PlainMessage("即将进行对"), new AtMessage(ObjectId), new PlainMessage($"禁言{BanSpan}的禁言操作。该操作需要3" + "名群友的同步确认,2分钟内发送accept进行确认") }).Wait(); }
private async Task SendPictureAsync(MiraiHttpSession session, string path) // 发图 { // 你也可以使用另一个重载 UploadPictureAsync(PictureTarget, Stream) // mirai-api-http 在v1.7.0以下时将使用本地的HttpListener做图片中转 ImageMessage msg = await session.UploadPictureAsync(PictureTarget.Group, path); IMessageBase[] chain = new IMessageBase[] { msg }; // 数组里边可以加上更多的 IMessageBase, 以此达到例如图文并发的情况 await session.SendGroupMessageAsync(0, chain); // 自己填群号, 一般由 IGroupMessageEventArgs 提供 }
public async Task <bool> GroupMessage2(MiraiHttpSession session, IGroupMessageEventArgs e) // 法2: 使用 params IMessageBase[] { IMessageBase plain1 = new PlainMessage($"收到了来自{e.Sender.Name}[{e.Sender.Id}]{{{e.Sender.Permission}}}的群消息:{string.Join(null, (IEnumerable<IMessageBase>)e.Chain)}"); // / 发送者群名片 / / 发送者QQ号 / / 发送者在群内权限 / / 消息链 / IMessageBase plain2 = new PlainMessage("QAQ"); // 在下边的 SendGroupMessageAsync, 你可以串起n个 IMessageBase await session.SendGroupMessageAsync(e.Sender.Group.Id, plain1 /*, plain2, /* etc... */); // 向消息来源群异步发送由以上chain表示的消息 return(false); // 不阻断消息传递。如需阻断请返回true }
public static async Task Run(CommandParser.GenerateCalender args, MiraiHttpSession session, IGroupMessageEventArgs e) { if (++CurrentGenerateRequestNum > 3) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage("目前请求过多。请稍后再试")); CurrentGenerateRequestNum--; return; } if (System.IO.File.Exists(@$ "{Config.RootPath}\Users\{e.Sender.Id}\calender.json"))
public static async Task SendPlainText(this MiraiHttpSession session, IGroupMessageEventArgs e, string text) { var builder = new MessageBuilder(); builder.AddAtMessage(e.Sender.Id); builder.AddPlainMessage(" "); builder.AddPlainMessage(text); await session.SendGroupMessageAsync(e.Sender.Group.Id, builder); }
public async Task <bool> GroupMessage3(MiraiHttpSession session, IGroupMessageEventArgs e) // 法3: 使用 IMessageBuilder { IMessageBuilder builder = new MessageBuilder(); builder.AddPlainMessage($"收到了来自{e.Sender.Name}[{e.Sender.Id}]{{{e.Sender.Permission}}}的群消息:{string.Join(null, (IEnumerable<IMessageBase>)e.Chain)}"); // / 发送者群名片 / / 发送者QQ号 / / 发送者在群内权限 / / 消息链 / // builder.AddPlainMessage("QAQ").AddPlainMessage("QwQ")/* .AddAtMessage(123456) etc... */; // 你甚至可以一开始 new MessageBuilder() 的时候就开始 Chaining await session.SendGroupMessageAsync(e.Sender.Group.Id, builder /*, plain2, /* etc... */); // 向消息来源群异步发送由以上chain表示的消息 return(false); // 不阻断消息传递。如需阻断请返回true }
public async Task <bool> GroupMessage(MiraiHttpSession session, IGroupMessageEventArgs e) { // 临时消息和群消息一致, 不多写例子了 IMessageBase[] chain = new IMessageBase[] { new PlainMessage($"收到了来自{e.Sender.Name}[{e.Sender.Id}]{{{e.Sender.Permission}}}的群消息:{string.Join(null, (IEnumerable<IMessageBase>)e.Chain)}") // / 发送者群名片 / / 发送者QQ号 / / 发送者在群内权限 / / 消息链 / }; await session.SendGroupMessageAsync(e.Sender.Group.Id, chain); // 向消息来源群异步发送由以上chain表示的消息 return(false); // 不阻断消息传递。如需阻断请返回true }
public static async Task Run(CommandParser.Config args, MiraiHttpSession session, IGroupMessageEventArgs e) { if (args.ConfigInGroup == false) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage("警告:未提供命令参数-g的情况下在群内试图配置用户信息。\n" + "为保证账号安全,停止了此操作并尝试撤回了信息。")); await session.RevokeMessageAsync(((SourceMessage)e.Chain[0]).Id); return; } await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage("正在保存...")); var user = new User(e.Sender.Id) { Username = args.Username, Password = args.Password }; bool ok = await user.TrySave(); await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage(ok ? "成功更改了配置。" : "抱歉,遇到了错误,请稍后再试。")); }
private static async Task GetToday(CommandParser.Default args, MiraiHttpSession session, IGroupMessageEventArgs e) { using var reader = new StreamReader($@"{Config.RootPath}\Users\{e.Sender.Id}\calender.json"); string calenderstr = await reader.ReadToEndAsync(); Response response = null; try { response = JsonConvert.DeserializeObject <Response>(calenderstr); } catch (Exception ex) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage($"发生了错误:{ex.Message}")); } var calender = response.data; var today = DateTime.Now.AddDays(args.DaysAfter); var courses = calender .Where(c => c.teachingWeek != null && c.teachingWeek.PadRight(30, '0')[(int)((today - new DateTime(2021, 3, 1)).TotalDays / 7)] == '1' && c.weekDay == ((int)today.DayOfWeek).ToString()); if (courses.Any()) { await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage($"您{(args.DaysAfter == 0 ? "今天" : $"{args.DaysAfter}天后")}的课程列表如下:\r\n{courses.Aggregate("", (lhs, rhs) => lhs + "\r\n" + CourseMessageSender(args, rhs).GetAwaiter().GetResult())}")); }
public async Task <bool> GroupMemberPositiveLeave(MiraiHttpSession session, IGroupMemberPositiveLeaveEventArgs e) { Console.Write("[" + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "] ", Color.Yellow); Console.Write("[LEAVE] ", Color.Firebrick); Console.Write("[" + e.Member.Group.Name + "]: ", Color.Orange); Console.WriteLine(e.Member.Name + "已退群"); if (File.Exists("com.coc.groupadmin\\" + e.Member.Group.Id + "\\" + e.Member.Id + ".bin")) { File.Delete("com.coc.groupadmin\\" + e.Member.Group.Id + "\\" + e.Member.Id + ".bin"); } await session.SendGroupMessageAsync(e.Member.Group.Id, new PlainMessage(e.Member.Name + "已退群!")); return(true); }
#pragma warning disable CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行 protected static async Task OnMessage(MiraiHttpSession session, string message, Source Sender) #pragma warning restore CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行 { if (!booted) { return; } bool isAdmin = AdminQQ == Sender.FromQQ || Configuration.GetConfig <Admin>().hash.Contains(Sender.FromQQ); long ticks = DateTime.Now.Ticks; if (IsIgnore(Sender)) { return; } Action <string> callback = delegate(string s) { try { Utils.Log(LoggerLevel.Debug, $"[{(DateTime.Now.Ticks - ticks) / 10000}ms] sent msg: " + s); if (Sender.FromGroup != 0) { session.SendGroupMessageAsync(Sender.FromGroup, Utils.GetMessageChain(s, p => session.UploadPictureAsync(UploadTarget.Group, p).Result)).Wait(); } else if (!Sender.IsTemp) { session.SendFriendMessageAsync(Sender.FromQQ, Utils.GetMessageChain(s, p => session.UploadPictureAsync(UploadTarget.Temp, p).Result)).Wait(); } else { session.SendTempMessageAsync(Sender.FromQQ, Sender.FromGroup, Utils.GetMessageChain(s, p => session.UploadPictureAsync(UploadTarget.Friend, p).Result)).Wait(); } } catch (Exception e) { Utils.Log(LoggerLevel.Error, "error in msg: " + s + "\n" + e.ToString()); } }; Utils.Log(LoggerLevel.Debug, "recv msg: " + message); Task.Run(() => { instance.OnMessage(message, Sender, isAdmin, callback); }).Start(); }
public async Task <bool> OnAt(MiraiHttpSession session, IGroupMessageEventArgs e) { bool selfAted = e.Chain.Where(msg => msg is AtMessage) .Cast <AtMessage>() .Select(atmsg => atmsg.Target) .Contains(session.QQNumber.Value); if (selfAted) { var imgmsg = await session.UploadPictureAsync(UploadTarget.Group, @"..\..\..\images\kokoaCry.jpg"); await session.SendGroupMessageAsync(e.Sender.Group.Id, new IMessageBase[] { new PlainMessage("检测到您正在at我!主人很懒,不想实" + "现接受at信息调用我的模块,请直接使用文字命令来调用!"), imgmsg }, ((SourceMessage)e.Chain[0]).Id); } return(false); }
public void sendMessage(string msg) { switch (type) { case 0: session.SendFriendMessageAsync(peerid, new IMessageBase[] { new PlainMessage(msg) }).Wait(); break; case 1: session.SendGroupMessageAsync(peerid, new IMessageBase[] { new PlainMessage(msg) }).Wait(); break; case 2: session.SendTempMessageAsync(peerid, tgroup, new IMessageBase[] { new PlainMessage(msg) }).Wait(); break; } }
public async Task <bool> GroupMessage(MiraiHttpSession session, IGroupMessageEventArgs e) { if (e.GetMessage().IsCommand()) { var assembly = Assembly.GetExecutingAssembly(); var fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location); switch (e.GetMessage()) { case "/Help": await session.SendPlainText(e, $"欢迎使用HeliumBot {fileVersion.FileVersion}", "===================", "/Help : 查看帮助", "/Genshin <uid> : 获取指定原神UID的公开信息", "/Genshin <uid> -Avatar : 获取指定原神UID的公开信息,并查看获得的角色", "/GenshinAbyss <uid> : 获取指定原神UID的深渊战绩", "/GenshinAbyss <uid> -Detail : 获取指定原神UID的深渊战绩,并且查看每层每间详情", "/Money : 给作者打钱", "/About : 查看Bot的关于信息"); break; case "/Money": var img = await session.UploadPictureAsync(UploadTarget.Group, await new HttpClient().GetStreamAsync("https://i.loli.net/2021/05/04/fXOm1xnrsBg45Zh.jpg")); await session.SendGroupMessageAsync(e.Sender.Group.Id, img); break; case "/About": await session.SendPlainText(e, $"HeliumBot {fileVersion.FileVersion}", $"Maintain by AHpx(https://github.com/AHpxChina)", $"Based on Mirai-CSharp(https://github.com/Executor-Cheng/Mirai-CSharp)", $"Open source repository on https://github.com/AHpxChina/HeliumBot", $"Acknowledgment:", $"mirai(https://github.com/mamoe/mirai)", $"mirai-api-http(https://github.com/mamoe/mirai-api-http)", $"mirai-console(https://github.com/mamoe/mirai-console)"); break; } } return(false); }
public async void DoHandleAsync(MiraiHttpSession session, IMessageBase[] chain, IBaseInfo info, bool isGroupMessage = true) { logger.LogInformation($"{info.Name} 询问最新活动"); var latestEvent = data.GetLatestEvent(); bool isEventChanged = false; if (int.Parse(latestEvent.Item1) != latestEventId) { latestEventId = int.Parse(latestEvent.Item1); isEventChanged = true; } string message; IMessageBase img; if (isGroupMessage) { img = await session.UploadPictureAsync(UploadTarget.Group, await client.GetEventBannerImagePath(latestEvent.Item1)); } else { img = await session.UploadPictureAsync(UploadTarget.Friend, await client.GetEventBannerImagePath(latestEvent.Item1)); } DateTime endTime = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(latestEvent.Item2.EndAt[0])).LocalDateTime; DateTime startTime = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(latestEvent.Item2.StartAt[0])).LocalDateTime; string eventState = startTime >= DateTime.Now ? $"即将开始,剩余{startTime - DateTime.Now:d\\日h\\小\\时m\\分}" : endTime <= DateTime.Now ? "结束" : $"正在进行,剩余{endTime - DateTime.Now:d\\日h\\小\\时m\\分}"; message = $"活动名称: {latestEvent.Item2.EventName[0]}\n开始时间: {startTime}\n结束时间: {endTime}\n活动状态: {eventState}"; logger.LogInformation($"已查到活动,并回复 {message}"); IMessageBase[] result = new IMessageBase[] { new PlainMessage((isEventChanged ? "发现新活动!\n" : "") + message), img }; if (isGroupMessage) { await session.SendGroupMessageAsync(((IGroupMemberInfo)info).Group.Id, result); } else { await session.SendFriendMessageAsync(info.Id, result); } }
protected static void OnMessage(MiraiHttpSession session, string message, Source Sender) { if (!booted) { return; } long ticks = DateTime.Now.Ticks; Func <string, Task> callback = async s => { try { Utils.Log(LoggerLevel.Debug, $"[{(DateTime.Now.Ticks - ticks) / 10000}ms] sent msg: " + s); if (Sender.FromGroup != 0) { await session.SendGroupMessageAsync(Sender.FromGroup, await Utils.GetMessageChain(s, async p => await session.UploadPictureAsync(UploadTarget.Group, p))); } else if (!Sender.IsTemp) { await session.SendFriendMessageAsync(Sender.FromQQ, await Utils.GetMessageChain(s, async p => await session.UploadPictureAsync(UploadTarget.Temp, p))); } else { await session.SendTempMessageAsync(Sender.FromQQ, Sender.FromGroup, await Utils.GetMessageChain(s, async p => await session.UploadPictureAsync(UploadTarget.Friend, p))); } } catch (Exception e) { Utils.Log(LoggerLevel.Error, "error in msg: " + s + "\n" + e.ToString()); } }; Utils.Log(LoggerLevel.Debug, "recv msg: " + message); Task.Run(() => instance.OnMessage(new HandlerArgs { message = message, Sender = Sender, Callback = callback })); }
public async Task <bool> GroupMessage(MiraiHttpSession session, IGroupMessageEventArgs e) // 法2: 使用 params IMessageBase[] { if (e.Chain[1].Type == "Image") { var source = (SourceMessage)e.Chain[0]; await session.RevokeMessageAsync(source.Id); return(true); } var replyMsg = await GroupMessageHandler(e); if (replyMsg == null || replyMsg.Message == string.Empty) { return(true); } await session.SendGroupMessageAsync(e.Sender.Group.Id, new AtMessage(e.Sender.Id), replyMsg /*, plain2, /* etc... */); // 向消息来源群异步发送由以上chain表示的消息 return(false); // 不阻断消息传递。如需阻断请返回true }
protected static async Task OnMessage(MiraiHttpSession session, string message, Source Sender) { if (!booted) { return; } bool isAdmin = AdminQQ == Sender.FromQQ || Configuration.GetConfig <Admin>().hash.Contains(Sender.FromQQ); if (IsIgnore(Sender)) { return; } ResponseCallback callback = delegate(string s) { try { if (Sender.FromGroup != 0) { session.SendGroupMessageAsync(Sender.FromGroup, Utils.GetMessageChain(s)).Wait(); } else { session.SendFriendMessageAsync(Sender.FromQQ, Utils.GetMessageChain(s)).Wait(); } Utils.Log(LoggerLevel.Debug, "sent msg: " + s); } catch (Exception e) { Utils.Log(LoggerLevel.Error, "error in msg: " + s + "\n" + e.ToString()); } }; Utils.Log(LoggerLevel.Debug, "recv msg: " + message); instance.OnMessage(message, Sender, isAdmin, callback); }
public async Task <bool> GroupMessageRevoked(MiraiHttpSession session, IGroupMessageRevokedEventArgs e) { var record = msgRecord.FirstOrDefault(msg => msg.id == e.MessageId); if (record == null || e.Operator.Id != record.qq) { return(false); } try { await session.SendGroupMessageAsync(record.group, (new IMessageBase[] { new AtMessage(e.Operator.Id, ""), new PlainMessage("尝试撤回一条消息:") }).Concat(record.message).ToArray()); return(true); } catch (Exception e2) { this.Log(LoggerLevel.Error, e2.ToString()); return(false); } }