public override async Task ExecuteAsync(List <string> command, List <BaseMessage> originMessage, MessageSourceType sourceType, UserInfo qq, Group group, GroupMember member) { await Task.Yield(); var fromQQ = 0L; var toGroup = 0L; //var message = ""; if (sourceType != MessageSourceType.Group) { return; } fromQQ = member.QQ; toGroup = member.GroupNumber; var permit = member.PermitType; if (!command.Any()) { if (!GroupRepeatConfig.TryGetValue(toGroup, out var config)) { MessageManager.SendTextMessage(MessageSourceType.Group, "当前群尚未开启复读功能", fromQQ, toGroup); } else { MessageManager.SendTextMessage(MessageSourceType.Group, $"当前复读概率:{config.Percent}%", fromQQ, toGroup); } return; } if (command[0].Equals("on", StringComparison.CurrentCultureIgnoreCase)) { if (permit == PermitType.None) { MessageManager.SendTextMessage(MessageSourceType.Group, "只有群主或管理员才有权限开启复读功能", fromQQ, toGroup); return; } RepeatConfig config; if (command.Count == 1) { config = new RepeatConfig(); } else { if (int.TryParse(command[1], out var percent)) { config = new RepeatConfig { Percent = percent > 100 ? 100 : percent }; } else { config = new RepeatConfig(); } } UpdateGroupRepeatConfig(toGroup, config); MessageManager.SendTextMessage(MessageSourceType.Group, $"复读已开启,复读概率:{config.Percent}%", fromQQ, toGroup); } else if (command[0].Equals("off", StringComparison.CurrentCultureIgnoreCase)) { if (permit == PermitType.None) { MessageManager.SendTextMessage(MessageSourceType.Group, "只有群主或管理员才有权限关闭复读功能", fromQQ, toGroup); return; } UpdateGroupRepeatConfig(toGroup, null); MessageManager.SendTextMessage(MessageSourceType.Group, "复读已关闭", fromQQ, toGroup); } else if (command[0].Equals("repeat", StringComparison.CurrentCultureIgnoreCase) && command.Count > 1) { MessageManager.SendMessage(MessageSourceType.Group, originMessage, fromQQ, toGroup); } }
public override async Task ExecuteAsync(List <string> command, List <BaseMessage> originMessage, MessageSourceType sourceType, UserInfo qq, Group group, GroupMember member) { var fromQQ = 0L; var toGroup = 0L; //var message = ""; if (sourceType != MessageSourceType.Group) { return; } fromQQ = member.QQ; toGroup = member.GroupNumber; var permit = member.PermitType; if (!command.Any()) { if (!GroupShaDiaoTuConfig.TryGetValue(toGroup, out var config)) { MessageManager.SendTextMessage(MessageSourceType.Group, "当前群尚未开启沙雕图功能", fromQQ, toGroup); } else { MessageManager.SendTextMessage(MessageSourceType.Group, $"当前沙雕图概率:{config.Percent}%", fromQQ, toGroup); } return; } if (command[0].Equals("on", StringComparison.CurrentCultureIgnoreCase)) { if (permit == PermitType.None) { MessageManager.SendTextMessage(MessageSourceType.Group, "只有群主或管理员才有权限开启沙雕图功能", fromQQ, toGroup); return; } ShaDiaoTuConfig config; if (command.Count == 1) { config = new ShaDiaoTuConfig(); } else { if (int.TryParse(command[1], out var percent)) { config = new ShaDiaoTuConfig { Percent = percent > 100 ? 100 : percent }; } else { config = new ShaDiaoTuConfig(); } } UpdateGroupShaDiaoTuConfig(toGroup, config); MessageManager.SendTextMessage(MessageSourceType.Group, $"随机沙雕图已开启,发图概率:{config.Percent}%", fromQQ, toGroup); } else if (command[0].Equals("off", StringComparison.CurrentCultureIgnoreCase)) { if (permit == PermitType.None) { MessageManager.SendTextMessage(MessageSourceType.Group, "只有群主或管理员才有权限关闭沙雕图功能", fromQQ, toGroup); return; } UpdateGroupShaDiaoTuConfig(toGroup, null); MessageManager.SendTextMessage(MessageSourceType.Group, "随机沙雕图已关闭", fromQQ, toGroup); } else if (command[0].Equals("add", StringComparison.CurrentCultureIgnoreCase)) { if (!GroupShaDiaoTuConfig.ContainsKey(toGroup)) { MessageManager.SendTextMessage(MessageSourceType.Group, "先找人把功能打开啦", fromQQ, toGroup); return; } if (_lastTime.ContainsKey(fromQQ) && _lastTime[fromQQ] == DateTime.Today && fromQQ != DataManager.Instance.AdminQQ) { MessageManager.SendTextMessage(MessageSourceType.Group, "每人每天只能添加一张", fromQQ, toGroup); return; } var image = (ImageMessage)originMessage.Find(p => p is ImageMessage); if (image == null) { MessageManager.SendTextMessage(MessageSourceType.Group, "图呢0 0", fromQQ, toGroup); return; } //var img = command[1]; //var match = _imageGuid.Match(img); //if (!match.Groups["Guid"].Success) //{ // MessageManager.SendTextMessage(MessageSourceType.Group, "图呢0 0", fromQQ, toGroup); // return; //} //var fileName = match.Groups["Guid"].Value; //var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "temp", "image"); //var iniFileName = Path.Combine(path, Path.GetFileNameWithoutExtension(fileName) + ".ini"); //if (!File.Exists(iniFileName)) //{ // MessageManager.SendTextMessage(MessageSourceType.Group, "上传失败惹", fromQQ, toGroup); // return; //} //var fileText = File.ReadAllText(iniFileName); //var url = fileText.Split('\n').FirstOrDefault(p => p.StartsWith("url"))?.Substring(4); var url = image.Url; if (string.IsNullOrWhiteSpace(url)) { MessageManager.SendTextMessage(MessageSourceType.Group, "上传失败惹", fromQQ, toGroup); return; } using (var client = new HttpClient()) { var imgRes = await client.GetAsync(url); var imgItem = System.Drawing.Image.FromStream(await imgRes.Content.ReadAsStreamAsync()); var savedPath = Path.Combine(Config.ShaDiaoImagePath, Guid.NewGuid().ToString() + ".png"); if (!Directory.Exists(Config.ShaDiaoImagePath)) { Directory.CreateDirectory(Config.ShaDiaoImagePath); } imgItem.Save(savedPath); } MessageManager.SendTextMessage(MessageSourceType.Group, "上传成功", fromQQ, toGroup); if (!_lastTime.ContainsKey(fromQQ)) { _lastTime.Add(fromQQ, DateTime.Today); } else { _lastTime[fromQQ] = DateTime.Today; } } else if (command[0].Equals("shadiaotu", StringComparison.CurrentCultureIgnoreCase)) { var dir = Path.Combine(Config.DataPath, "沙雕图"); if (!Directory.Exists(dir)) { return; } var files = Directory.GetFiles(dir); if (!files.Any()) { return; } var fileName = files[_rand.Next(0, files.Length)]; MessageManager.SendImageMessage(sourceType, fileName, fromQQ, toGroup); } }
public override async Task ExecuteAsync(List <string> command, List <BaseMessage> originMessage, MessageSourceType sourceType, UserInfo qq, Group group, GroupMember member) { await Task.Yield(); var fromQQ = 0L; var toGroup = 0L; //var message = ""; if (sourceType != MessageSourceType.Group) { return; } fromQQ = member.QQ; toGroup = member.GroupNumber; var permit = member.PermitType; if (!command.Any()) { if (!GroupBakiConfig.TryGetValue(toGroup, out var config)) { MessageManager.SendTextMessage(MessageSourceType.Group, "当前群尚未开启热狗图功能", fromQQ, toGroup); } else { MessageManager.SendTextMessage(MessageSourceType.Group, $"当前热狗人纯度:{config.Percent}%", fromQQ, toGroup); } return; } if (command[0].Equals("on", StringComparison.CurrentCultureIgnoreCase)) { if (permit == PermitType.None) { MessageManager.SendTextMessage(MessageSourceType.Group, "只有群主或管理员才有权限开启热狗图功能", fromQQ, toGroup); return; } BakiConfig config; if (command.Count == 1) { config = new BakiConfig(); } else { if (int.TryParse(command[1], out var percent)) { config = new BakiConfig { Percent = percent > 100 ? 100 : percent }; } else { config = new BakiConfig(); } } UpdateGroupBakiConfig(toGroup, config); MessageManager.SendTextMessage(MessageSourceType.Group, $"随机热狗图已开启,提升纯度概率:{config.Percent}%", fromQQ, toGroup); } else if (command[0].Equals("off", StringComparison.CurrentCultureIgnoreCase)) { if (permit == PermitType.None) { MessageManager.SendTextMessage(MessageSourceType.Group, "只有群主或管理员才有权限关闭热狗图功能", fromQQ, toGroup); return; } UpdateGroupBakiConfig(toGroup, null); MessageManager.SendTextMessage(MessageSourceType.Group, "随机热狗图已关闭", fromQQ, toGroup); } else if (command[0].Equals("baki", StringComparison.CurrentCultureIgnoreCase)) { var dir = Path.Combine(Config.DataPath, "Baki"); if (!Directory.Exists(dir)) { return; } var files = Directory.GetFiles(dir); if (!files.Any()) { return; } var fileName = files[_rand.Next(0, files.Length)]; MessageManager.SendImageMessage(sourceType, fileName, fromQQ, toGroup); } }
public static async Task Execute(string command, List <BaseMessage> originMessage, MessageSourceType sourceType, long?qqNo = null, long?groupNo = null) { UserInfo qq = null; Group group = null; if (qqNo.HasValue) { qq = UserManager.Get(qqNo.Value); } GroupMember member = null; if (qqNo.HasValue && groupNo.HasValue) { member = await GroupMemberManager.Get(qqNo.Value, groupNo.Value); if (member != null && (DataManager.Instance?.GroupIgnore?.ContainsKey((member.GroupNumber, member.QQ)) ?? false)) { return; } } if (!command.StartsWith(".") && !command.StartsWith("/")) { if (sourceType == MessageSourceType.Group) { ExecuteWithoutCommand(command, originMessage, sourceType, qq, member); } return; } var commandStr = command.Remove(0, 1); var commandList = Tools.TakeCommandParts(commandStr); var commandName = commandList.FirstOrDefault(); if (commandName == null) { return; } var manager = GetManagerByCommand(commandName); if (manager == null) { if (sourceType == MessageSourceType.Group) { ExecuteWithoutCommand(command, originMessage, sourceType, qq, member); } return; } commandList.RemoveAt(0); var args = commandList; if (sourceType == MessageSourceType.Group) { if (BanManager.QQBan.TryGetValue(member.QQ, out _)) { MessageManager.SendTextMessage(sourceType, "滚", member.QQ, member.GroupNumber); return; } else if (BanManager.GroupBan.TryGetValue((member.QQ, member.GroupNumber), out _)) { MessageManager.SendTextMessage(sourceType, "滚", member.QQ, member.GroupNumber); return; } } await manager.ExecuteAsync(args, originMessage, sourceType, qq, group, member); }
public override async Task ExecuteAsync(List <string> command, List <BaseMessage> originMessage, MessageSourceType sourceType, UserInfo qq, Group group, GroupMember member) { await Task.Yield(); var fromQQ = 0L; var toGroup = 0L; //var message = ""; if (sourceType != MessageSourceType.Group) { return; } fromQQ = member.QQ; toGroup = member.GroupNumber; var permit = member.PermitType; if (permit == PermitType.None) { MessageManager.SendTextMessage(MessageSourceType.Group, "只有群主或管理员才有权限封禁用户", fromQQ, toGroup); return; } if (!command.Any()) { return; } if (!long.TryParse(command[0], out var banQQ)) { return; } if (command.Count > 1 && long.TryParse(command[1], out var banGroup)) { if (GroupBan.ContainsKey((banGroup, banQQ))) { UpdateGroupQQBan(banGroup, banQQ, false); MessageManager.SendTextMessage(MessageSourceType.Group, $"用户{banQQ}在群{banGroup}的封禁已被解除", fromQQ, toGroup); return; } else { UpdateGroupQQBan(banGroup, banQQ, true); MessageManager.SendTextMessage(MessageSourceType.Group, $"用户{banQQ}在群{banGroup}已被封禁", fromQQ, toGroup); return; } }