private static void HandleMessage(CommonMessage cm) { bool cmdFlag = false; long groupId = Convert.ToInt64(cm.GroupId); long userId = Convert.ToInt64(cm.UserId); long discussId = Convert.ToInt64(cm.DiscussId); var type = cm.MessageType; string group, sender, message = cm.Message; if (cm.MessageType == MessageType.Private) { group = "私聊"; sender = SessionInfo[cm.Identity].Name; } else if (cm.MessageType == MessageType.Discuss) { group = SessionInfo[cm.Identity].Name; sender = cm.UserId; } else { var userInfo = SessionInfo[cm.Identity]?.GroupInfo?.Members?.FirstOrDefault(i => i.UserId == userId) ?? CqApi.GetGroupMemberInfo(cm.GroupId, cm.UserId).Data; group = SessionInfo?[cm.Identity]?.Name; sender = string.IsNullOrEmpty(userInfo.Card) ? userInfo.Nickname : userInfo.Card; } Message($"({group}) {sender}:\r\n {CqCode.DecodeToString(message)}"); if (cm.Message.Substring(0, 1) == CommandFlag) { if (cm.Message.IndexOf(CommandFlag + "root ", StringComparison.InvariantCulture) == 0) { if (cm.UserId != "2241521134") { SendMessage(new CommonMessageResponse(LoliReply.FakeRoot, cm)); } else { cm.FullCommand = cm.Message.Substring(6, cm.Message.Length - 6); cm.PermissionLevel = PermissionLevel.Root; cmdFlag = true; HandleMessageCmd(cm); } } else if (message.IndexOf(CommandFlag + "sudo ", StringComparison.InvariantCulture) == 0 && type == MessageType.Group) { if (SessionInfo[cm.Identity].GroupInfo.Admins.Count(q => q.UserId == userId) == 0) { SendMessage(new CommonMessageResponse(LoliReply.FakeAdmin, cm)); } else { cm.FullCommand = message.Substring(6, message.Length - 6); cm.PermissionLevel = PermissionLevel.Admin; cmdFlag = true; HandleMessageCmd(cm); } } else { // auto if (SessionInfo[cm.Identity].GroupInfo?.Admins.Count(q => q.UserId == userId) != 0) { cm.PermissionLevel = PermissionLevel.Admin; } if (cm.UserId == "2241521134") { cm.PermissionLevel = PermissionLevel.Root; } cm.FullCommand = message.Substring(1, message.Length - 1); cmdFlag = true; HandleMessageCmd(cm); } } if (!cmdFlag) { SessionReceived?.Invoke(null, new SessionReceivedEventArgs { MessageObj = cm }); } HandleMesasgeApp(cm); Thread.Sleep(Rnd.Next(MinTime, MaxTime)); }
private static void HandleMessage(CommonMessage cm) { long groupId = Convert.ToInt64(cm.GroupId); long userId = Convert.ToInt64(cm.UserId); long discussId = Convert.ToInt64(cm.DiscussId); var type = cm.MessageType; string group, sender, message = cm.Message; switch (cm.MessageType) { case MessageType.Private: group = "私聊"; sender = SessionInfo[cm.Identity].Name; break; case MessageType.Discuss: group = SessionInfo[cm.Identity].Name; sender = cm.UserId; break; default: case MessageType.Group: var userInfo = CqApi.GetGroupMemberInfo(cm.GroupId, cm.UserId); // 有点费时间 group = SessionInfo[cm.Identity].Name; sender = string.IsNullOrEmpty(userInfo.Data.Card) ? userInfo.Data.Nickname : userInfo.Data.Card; break; } Message($"({group}) {sender}:\r\n {CqCode.DecodeToString(message)}"); if (cm.Message.Substring(0, 1) == CommandFlag) { if (cm.Message.IndexOf(CommandFlag + "root ", StringComparison.InvariantCulture) == 0) { if (cm.UserId != "2241521134") { SendMessage(new CommonMessageResponse(LoliReply.FakeRoot, cm)); } else { cm.FullCommand = cm.Message.Substring(6, cm.Message.Length - 6); cm.PermissionLevel = PermissionLevel.Root; HandleMessageCmd(cm); } } else if (message.IndexOf(CommandFlag + "sudo ", StringComparison.InvariantCulture) == 0 && type == MessageType.Group) { if (SessionInfo[cm.Identity].GroupInfo.Admins.Count(q => q.UserId == userId) == 0) { SendMessage(new CommonMessageResponse(LoliReply.FakeAdmin, cm)); } else { cm.FullCommand = message.Substring(6, message.Length - 6); cm.PermissionLevel = PermissionLevel.Admin; HandleMessageCmd(cm); } } else { cm.FullCommand = message.Substring(1, message.Length - 1); HandleMessageCmd(cm); } } HandleMesasgeApp(cm); Thread.Sleep(Rnd.Next(MinTime, MaxTime)); }