예제 #1
0
 public override async Task ExecuteAsync(List <string> command, EventSourceType sourceType, UserInfo qq, Group group, GroupMember member)
 {
     MessageManager.Send(sourceType, "略略略😝", qq: qq?.QQ, toGroupNo: member?.GroupNumber);
     return;
 }
예제 #2
0
        public override async System.Threading.Tasks.Task ExecuteAsync(List <string> command, EventSourceType sourceType, UserInfo qq, Group group, GroupMember member)
        {
            var toGroup = 0L;
            var fromQQ  = 0L;

            if (sourceType == EventSourceType.Private)
            {
                fromQQ = qq.QQ;
                if (fromQQ != DataManager.Instance.AdminQQ)
                {
                    MessageManager.Send(sourceType, "不给看不给看!", fromQQ, toGroup);
                    return;
                }
            }
            else if (sourceType == EventSourceType.Group)
            {
                fromQQ  = member.QQ;
                toGroup = member.GroupNumber;
                if (command.Any() && command.First() == "on")
                {
                    if (member.QQ == DataManager.Instance.AdminQQ)
                    {
                        if (!DataManager.Instance.EnabledRandomImgNumbers.Contains(member.GroupNumber))
                        {
                            DataManager.Instance.EnabledRandomImgNumbers.Add(member.GroupNumber);
                            MessageManager.Send(sourceType, "启用成功!", fromQQ, toGroup);
                            return;
                        }
                    }
                }
                else if (command.Any() && command.First() == "off")
                {
                    if (member.QQ == DataManager.Instance.AdminQQ)
                    {
                        if (DataManager.Instance.EnabledRandomImgNumbers.Contains(member.GroupNumber))
                        {
                            DataManager.Instance.EnabledRandomImgNumbers.Remove(member.GroupNumber);
                            MessageManager.Send(sourceType, "禁用成功!", fromQQ, toGroup);
                            return;
                        }
                    }
                }

                if (!DataManager.Instance.EnabledRandomImgNumbers.Contains(member.GroupNumber))
                {
                    MessageManager.Send(sourceType, "这个群没启用这个功能,快去找开发者来开启", fromQQ, toGroup);
                    return;
                }
            }
            else
            {
                return;
            }

            if (command.Count > 2)
            {
                MessageManager.Send(sourceType, "Tag太多啦,一次最多只能查两个", fromQQ, toGroup);
                return;
            }

            var key = new Tuple <EventSourceType, long>(sourceType, sourceType == EventSourceType.Private ? fromQQ : toGroup);

            if (fromQQ != DataManager.Instance.AdminQQ)
            {
                if (_lastFetchTimeDic.ContainsKey(key))
                {
                    if (DateTime.Now.Subtract(_lastFetchTimeDic[key]).TotalSeconds < _intervalSeconds)
                    {
                        MessageManager.Send(sourceType, "太频繁啦,每分钟只能出一张图", fromQQ, toGroup);
                        return;
                    }
                }
            }

            using (var client = new HttpClient())
            {
                var url = "https://danbooru.donmai.us/posts/random.json";
                var tag = string.Join("+", command);
                if ((command?.Count ?? 0) > 0)
                {
                    url += $"?tags={tag}";
                }
                var res = await client.GetAsync(url);

                if (res.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    MessageManager.Send(sourceType, $"{tag}:\ntag写错了吗,没找到图呢", fromQQ, toGroup);
                    return;
                }
                if (!res.IsSuccessStatusCode)
                {
                    MessageManager.Send(sourceType, $"{tag}:\n请求失败了QAQ", fromQQ, toGroup);
                    return;
                }

                var strContent = await res.Content.ReadAsStringAsync();

                var jsonRes = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(strContent, new
                {
                    file_url  = "",
                    id        = 0L,
                    success   = (bool?)null,
                    is_banned = (bool?)null
                });
                if (jsonRes.success.HasValue && !jsonRes.success.Value)
                {
                    MessageManager.Send(sourceType, $"{tag}:\ntag写错了吗,没找到图呢", fromQQ, toGroup);
                    return;
                }

                if (jsonRes.is_banned.HasValue && jsonRes.is_banned.Value)
                {
                    MessageManager.Send(sourceType, $"{tag}:\nid:{jsonRes.id}\n这张图被作者要求下架了:(", fromQQ, toGroup);
                    return;
                }

                try
                {
                    var imgRes = await client.GetAsync(jsonRes.file_url);

                    var img      = System.Drawing.Image.FromStream(await imgRes.Content.ReadAsStreamAsync());
                    var fileName = jsonRes.file_url.Split('/').Last();

                    var dir  = Path.Combine(Config.DataPath, "image");
                    var path = Path.Combine(dir, fileName);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    img.Save(path);
                    MessageManager.Send(sourceType, $"[CQ:image,file={fileName}]\n{tag}:\nhttps://danbooru.donmai.us/posts/{jsonRes.id}",
                                        fromQQ, toGroup);
                    File.Delete(path);
                }
                catch (Exception e)
                {
                    FileLogHelper.WriteLog(e, Config.LogPath);
                    FileLogHelper.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(jsonRes), Config.LogPath);
                    throw;
                }

                if (fromQQ != DataManager.Instance.AdminQQ)
                {
                    if (_lastFetchTimeDic.ContainsKey(key))
                    {
                        _lastFetchTimeDic[key] = DateTime.Now;
                    }
                    else
                    {
                        _lastFetchTimeDic.Add(key, DateTime.Now);
                    }
                }
            }
            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;
                }
                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();
                    }
                }

                DataManager.Instance.GroupRepeatConfig.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.GroupRepeatConfig.TryRemove(toGroup, out _);
                MessageManager.Send(EventSourceType.Group, "复读已关闭", fromQQ, toGroup);
            }
            else if (command[0].Equals("repeat", StringComparison.CurrentCultureIgnoreCase) && command.Count > 1)
            {
                MessageManager.Send(EventSourceType.Group, command[1], fromQQ, toGroup);
            }
        }
예제 #4
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 == Native.Csharp.Sdk.Cqp.Enum.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
                        };
                    }
                    else
                    {
                        config = new ShaDiaoTuConfig();
                    }
                }

                DataManager.Instance.GroupShaDiaoTuConfig.AddOrUpdate(toGroup, config, (p, q) => config);
                MessageManager.Send(EventSourceType.Group, "随机沙雕图已开启", fromQQ, toGroup);
            }
            else if (command[0].Equals("off", StringComparison.CurrentCultureIgnoreCase))
            {
                if (permit == Native.Csharp.Sdk.Cqp.Enum.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("shadiaotu", StringComparison.CurrentCultureIgnoreCase) && command.Count > 1)
            {
                var dir = Path.Combine(Common.DataDirectory, "Shadiao");
                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, $"[CQ:image,file={fileName}]",
                                    fromQQ, toGroup);
            }
        }
예제 #5
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);
            }
        }
예제 #6
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);
            }
        }