Beispiel #1
0
        public override async Task InvokeAsync(CommandContext ctx, string[] args)
        {
            if (args.Length < 1)
            {
                await ctx.ReplyAsync(Util.GenerateInvalidUsage(ctx.Bot, this));

                return;
            }

            List <string> tagList    = args.Distinct().OrderBy(x => x).Select(x => x.Trim()).ToList();
            List <string> sortParams = args.Where(x => x.Contains(":")).Distinct().OrderBy(x => x).Select(x => x.Trim()).ToList();

            tagList.RemoveAll(x => x.Contains(":"));
            tagList.AddRange(sortParams);

            string tags = String.Join(" ", tagList.ToArray());

            if (tagList.Count > 2)
            {
                await ctx.ReplyAsync($"You supplied too many tags. Danbooru has a limit of two tags per query. Your tags: ``{tags}``");

                return;
            }

            var client = new DanbooruClient(ctx.DbContext);

            int count;

            try { count = await client.GetImageCountAsync(tags); }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.ToString());
                await ctx.ReplyAsync("The request to the API failed. Looks like the service might be down, try again later.");

                return;
            }


            await ctx.ReplyAsync($"Total amount of posts with the tags ``{tags}`` on Danbooru: **{count}**");
        }
Beispiel #2
0
        public async Task Danbooru(params string[] tags)
        {
            tags
            .ContainsBlacklistedTags()
            .IsSuccessAsync(x => containsIllegalTags(x.Data, tags, Context))
            .IsErrorAsync(async x =>
            {
                var posts = await DanbooruClient.GetImagesAsync(tags).ConfigureAwait(false);
                StatsdClient.DogStatsd.Increment("web.get");

                if (posts == null || !posts.Any())
                {
                    await EmbedExtensions.FromError("Couldn't find an image.", Context).QueueMessageAsync(Context).ConfigureAwait(false);
                    return;
                }

                var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();

                await post.GetMessage(Context).QueueMessageAsync(Context).ConfigureAwait(false);
            }
                          );
        }
Beispiel #3
0
        public async Task HentaiBomb([Remainder] string tags = null)
        {
            List <string> localTags = new List <string>();

            if (tags != null)
            {
                tags.Split(' ').ToArray();
            }

            localTags
            .ContainsBlacklistedTags()
            .IsSuccessAsync(x => containsIllegalTags(x.Data, localTags, Context))
            .IsError(x =>
            {
                ""
                .ThenAsync(async x =>
                {
                    var posts = await YandereClient.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                        if (post != null)
                        {
                            x = $"Yande.re: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    if (localTags.Count < 6)
                    {
                        var posts = await KonaChanClient.GetImagesAsync(tags).ConfigureAwait(false);
                        StatsdClient.DogStatsd.Increment("web.get");
                        if (posts != null && posts.Any())
                        {
                            var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                            if (post != null)
                            {
                                x += $"Konachan {post.GetMessage(Context, true)}\n";
                            }
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    var posts = await E621Client.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.All(z => z.Value.ContainsBlacklistedTags().Successful)).RandomValue();
                        if (post != null)
                        {
                            x += $"E621: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    var posts = await Rule34Client.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                        if (post != null)
                        {
                            x += $"R34: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    var posts = await GelbooruClient.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                        if (post != null)
                        {
                            x += $"Gelbooru: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    var posts = await DanbooruClient.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                        if (post != null)
                        {
                            x += $"Danbooru: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .Then(async x =>
                {
                    if (!string.IsNullOrEmpty((string)x))
                    {
                        await x.QueueMessageAsync(Context).ConfigureAwait(false);
                    }
                });
            }
                     );
        }
        public override async Task InvokeAsync(CommandContext ctx, string[] args)
        {
            if (args.Length < 1)
            {
                await ctx.ReplyAsync(Util.GenerateInvalidUsage(ctx.Bot, this));

                return;
            }

            List <string> tagList    = args.Distinct().OrderBy(x => x).Select(x => x.Trim()).ToList();
            List <string> sortParams = args.Where(x => x.Contains(":")).Distinct().OrderBy(x => x).Select(x => x.Trim()).ToList();

            tagList.RemoveAll(x => x.Contains(":"));
            tagList.AddRange(sortParams);

            if (ctx.Channel is ITextChannel ch && !ch.IsNsfw)
            {
                tagList.RemoveAll(x => String.Equals("rating:explicit", x, StringComparison.OrdinalIgnoreCase) ||
                                  String.Equals("rating:questionable", x, StringComparison.OrdinalIgnoreCase));

                tagList.Add("rating:safe");
            }

            string tags = String.Join(' ', tagList.ToArray()).ToLower();

            if (tagList.Count > 2)
            {
                await ctx.ReplyAsync($"You supplied too many tags. Danbooru has a limit of two tags per query. Your tags: ``{tags}``");

                return;
            }

            var client = new DanbooruClient(ctx.DbContext);

            int count;

            try { count = await client.GetImageCountAsync(tags); }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.ToString());
                await ctx.ReplyAsync("The request to the API failed. Looks like the service might be down, try again later.");

                return;
            }

            if (count < 1)
            {
                await ctx.ReplyAsync("No posts were found for that tag.");

                return;
            }

            Random r = new Random();

            int limit = 20;

            Dictionary <int, string> urls;

            try { urls = await client.GetPostsAsync(tags, r.Next(count / limit > 1000 ? 1000 : count / limit), limit); }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.ToString());
                await ctx.ReplyAsync("The request to the API failed. Looks like the service might be down, try again later.");

                return;
            }

            if (urls.Count < 1)
            {
                await ctx.ReplyAsync("No posts were found for that tag.");

                return;
            }

            KeyValuePair <int, string> url = urls.ElementAt(r.Next(urls.Count));

            EmbedBuilder embed = new EmbedBuilder
            {
                Title    = $"tags: {tags}",
                Url      = $"https://danbooru.donmai.us/posts/{url.Key}",
                ImageUrl = url.Value,
                Color    = Util.CyanColor
            };

            embed.WithFooter("https://danbooru.donmai.us", "http://i.imgur.com/4Wjm9rb.png");

            await ctx.ReplyAsync(embed.Build());
        }
        public override async Task InvokeAsync(CommandContext ctx, string[] args)
        {
            if (args.Length < 1)
            {
                await ctx.ReplyAsync(Util.GenerateInvalidUsage(ctx.Bot, this));

                return;
            }

            if (ctx.Channel is ITextChannel ch && !ch.IsNsfw)
            {
                await ctx.ReplyAsync("gtfo h**o nsfw or nothing");

                return;
            }

            args[0] = args[0] + " -rating:safe";
            List <string> tagList    = args.Distinct().OrderBy(x => x).Select(x => x.Trim()).ToList();
            List <string> sortParams = args.Where(x => x.Contains(":")).Distinct().OrderBy(x => x).Select(x => x.Trim()).ToList();

            tagList.RemoveAll(x => x.Contains(":"));
            tagList.AddRange(sortParams);

            string tags = String.Join(' ', tagList.ToArray());

            if (tagList.Count > 2)
            {
                await ctx.ReplyAsync($"You supplied too many tags. Danbooru has a limit of two tags per query. Your tags: ``{tags}``");

                return;
            }

            var client = new DanbooruClient(ctx.DbContext);

            int count;

            try { count = await client.GetImageCountAsync(tags); }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.ToString());
                await ctx.ReplyAsync("The request to the API failed. Looks like the service might be down, try again later.");

                return;
            }

            if (count < 1)
            {
                await ctx.ReplyAsync("No posts were found for that tag.");

                return;
            }

            Random r = new Random();

            int limit = 20;

            Dictionary <int, string> urls;

            try { urls = await client.GetPostsAsync(tags, r.Next(count / limit > 1000 ? 1000 : count / limit), limit); }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.ToString());
                await ctx.ReplyAsync("The request to the API failed. Looks like the service might be down, try again later.");

                return;
            }

            if (urls.Count < 1)
            {
                await ctx.ReplyAsync("No posts were found for that tag.");

                return;
            }

            var urlList = urls.OrderBy(x => r.Next()).Take(r.Next(2, 5));

            foreach (var url in urlList)
            {
                EmbedBuilder e = new EmbedBuilder
                {
                    Title    = $"tags: {tags}",
                    Url      = $"https://danbooru.donmai.us/posts/{url.Key}",
                    ImageUrl = url.Value,
                    Color    = Util.CyanColor
                };
                e.WithFooter("https://danbooru.donmai.us", "http://i.imgur.com/4Wjm9rb.png");

                try { await ctx.Author.SendMessageAsync("", embed : e.Build()); }
                catch (Exception) { await ctx.ReplyAsync("Something went wrong. Do you have your DMs disabled?"); break; }
            }

            await((IUserMessage)ctx.Message).AddReactionAsync(new Emoji("👌"));
        }