예제 #1
0
        public override async Task ExecuteAsync(List <string> command, EventSourceType sourceType, UserInfo qq, Group group, GroupMember member)
        {
            var fromQQ  = 0L;
            var toGroup = 0L;
            var message = "";

            if (sourceType != EventSourceType.Group)
            {
                return;
            }

            fromQQ  = member.QQ;
            toGroup = member.GroupNumber;
            var permit = member.PermitType;

            if (!command.Any())
            {
                return;
            }

            if (command[0].Equals("on", StringComparison.CurrentCultureIgnoreCase))
            {
                if (permit == PermitType.None)
                {
                    MessageManager.Send(EventSourceType.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();
                    }
                }

                DataManager.Instance.GroupBakiConfig.AddOrUpdate(toGroup, config, (p, q) => config);
                MessageManager.Send(EventSourceType.Group, $"随机热狗图已开启,提升纯度概率:{config.Percent}%", fromQQ, toGroup);
            }
            else if (command[0].Equals("off", StringComparison.CurrentCultureIgnoreCase))
            {
                if (permit == PermitType.None)
                {
                    MessageManager.Send(EventSourceType.Group, "只有群主或管理员才有权限关闭热狗图功能", fromQQ, toGroup);
                    return;
                }

                DataManager.Instance.GroupBakiConfig.TryRemove(toGroup, out _);
                MessageManager.Send(EventSourceType.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.Send(sourceType, $"[QQ:pic={fileName}]",
                                    fromQQ, toGroup);
            }
        }
예제 #2
0
        public override async Task ExecuteAsync(List <string> command, EventSourceType sourceType, UserInfo qq, Group group, GroupMember member)
        {
            if (sourceType != EventSourceType.Private && sourceType != EventSourceType.Friend)
            {
                return;
            }
            if (qq == null || qq.QQ != DataManager.Instance.AdminQQ)
            {
                return;
            }
            var firstCommand = command.FirstOrDefault();

            if (firstCommand == null)
            {
                return;
            }
            switch (firstCommand.ToLower())
            {
            case "say":
            {
                command.RemoveAt(0);
                if (command.Count < 2)
                {
                    return;
                }
                var groupNumber = 0L;
                if (!long.TryParse(command.First(), out groupNumber))
                {
                    return;
                }

                command.RemoveAt(0);
                var message = string.Join(" ", command);
                MessageManager.Send(EventSourceType.Group, message, qq?.QQ, groupNumber);
                return;
            }

            case "rename":
                command.RemoveAt(0);
                if (command.Count < 1)
                {
                    return;
                }
                var name = command[0];
                DataManager.Instance.BotName = name;
                MessageManager.Send(EventSourceType.Friend, "改名成功", qq?.QQ);
                return;

            case "save":
                DataManager.Save();
                MessageManager.Send(EventSourceType.Friend, "保存成功", qq?.QQ);
                return;
            }
        }
예제 #3
0
        public override async Task ExecuteAsync(List <string> command, EventSourceType sourceType, UserInfo qq, Group group, GroupMember member)
        {
            var fromQQ  = 0L;
            var toGroup = 0L;
            var message = "";

            if (sourceType != EventSourceType.Group)
            {
                return;
            }

            fromQQ  = member.QQ;
            toGroup = member.GroupNumber;
            var permit = member.PermitType;

            if (!command.Any())
            {
                return;
            }

            if (command[0].Equals("on", StringComparison.CurrentCultureIgnoreCase))
            {
                if (permit == PermitType.None)
                {
                    MessageManager.Send(EventSourceType.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();
                    }
                }


                DataManager.Instance.GroupShaDiaoTuConfig.AddOrUpdate(toGroup, config, (p, q) => config);
                MessageManager.Send(EventSourceType.Group, $"随机沙雕图已开启,发图概率:{config.Percent}%", fromQQ, toGroup);
            }
            else if (command[0].Equals("off", StringComparison.CurrentCultureIgnoreCase))
            {
                if (permit == PermitType.None)
                {
                    MessageManager.Send(EventSourceType.Group, "只有群主或管理员才有权限关闭沙雕图功能", fromQQ, toGroup);
                    return;
                }

                DataManager.Instance.GroupShaDiaoTuConfig.TryRemove(toGroup, out _);
                MessageManager.Send(EventSourceType.Group, "随机沙雕图已关闭", fromQQ, toGroup);
            }
            else if (command[0].Equals("add", StringComparison.CurrentCultureIgnoreCase))
            {
                if (!DataManager.Instance.GroupShaDiaoTuConfig.ContainsKey(toGroup))
                {
                    MessageManager.Send(EventSourceType.Group, "先找人把功能打开啦", fromQQ, toGroup);
                    return;
                }

                if (_lastTime.ContainsKey(fromQQ) && _lastTime[fromQQ] == DateTime.Today &&
                    fromQQ != DataManager.Instance.AdminQQ)
                {
                    MessageManager.Send(EventSourceType.Group, "每人每天只能添加一张", fromQQ, toGroup);
                    return;
                }

                if (command.Count == 1)
                {
                    MessageManager.Send(EventSourceType.Group, "图呢0 0", fromQQ, toGroup);
                    return;
                }
                var img   = command[1];
                var match = _imageGuid.Match(img);
                if (!match.Groups["Guid"].Success)
                {
                    MessageManager.Send(EventSourceType.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.Send(EventSourceType.Group, "上传失败惹", fromQQ, toGroup);
                    return;
                }

                var fileText = File.ReadAllText(iniFileName);
                var url      = fileText.Split('\n').FirstOrDefault(p => p.StartsWith("url"))?.Substring(4);
                if (string.IsNullOrWhiteSpace(url))
                {
                    MessageManager.Send(EventSourceType.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, fileName);
                    if (!Directory.Exists(Config.ShaDiaoImagePath))
                    {
                        Directory.CreateDirectory(Config.ShaDiaoImagePath);
                    }

                    imgItem.Save(savedPath);
                }

                MessageManager.Send(EventSourceType.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.Send(sourceType, $"[QQ:pic={fileName}]",
                                    fromQQ, toGroup);
            }
        }
예제 #4
0
        private static void ExecuteWithoutCommand(string message, EventSourceType sourceType, UserInfo qq, GroupMember member)
        {
            var managerList = new List <Tuple <BaseManager, List <string> > >();
            var randomRes   = Random.Next(1, 101);

            if (member != null && DataManager.Instance.GroupRepeatConfig.ContainsKey(member.GroupNumber))
            {
                var config = DataManager.Instance.GroupRepeatConfig[member.GroupNumber];
                if (randomRes <= config.Percent)
                {
                    managerList.Add(new Tuple <BaseManager, List <string> >(new RepeatManager(), new List <string>
                    {
                        "repeat", message
                    }));
                }
            }
            if (member != null && DataManager.Instance.GroupShaDiaoTuConfig.ContainsKey(member.GroupNumber))
            {
                var config = DataManager.Instance.GroupShaDiaoTuConfig[member.GroupNumber];
                if (randomRes <= config.Percent)
                {
                    managerList.Add(new Tuple <BaseManager, List <string> >(new ShaDiaoTuManager(), new List <string>
                    {
                        "shadiaotu"
                    }));
                }
            }
            if (member != null && DataManager.Instance.GroupBakiConfig.ContainsKey(member.GroupNumber))
            {
                var config = DataManager.Instance.GroupBakiConfig[member.GroupNumber];
                if (randomRes <= config.Percent)
                {
                    managerList.Add(new Tuple <BaseManager, List <string> >(new BakiManager(), new List <string>
                    {
                        "baki"
                    }));
                }
            }

            if (managerList.Any())
            {
                var choose  = Random.Next(0, managerList.Count);
                var choosen = managerList[choose];
                Task.Run(async() =>
                {
                    await choosen.Item1.ExecuteAsync(choosen.Item2, sourceType, qq, null, member);
                });
            }
        }