Exemplo n.º 1
0
        public async Task SearchByTags()
        {
            string[] tags = new string[] { "lolicon ", SearchClient.GetExactTag("full color"),
                                           SearchClient.GetCategoryTag("kantai", TagType.Parody),
                                           SearchClient.GetExcludeTag("drugs"), SearchClient.GetExcludeTag("rape") };
            var res = (await SearchClient.SearchWithTagsAsync(tags, 1)).elements[0];
            var ids = res.tags.Select(x => x.id);

            Assert.Contains(1841, ids);
            Assert.Contains(19440, ids);
            Assert.DoesNotContain(22079, ids);
            Assert.DoesNotContain(27553, ids);
        }
Exemplo n.º 2
0
        public async Task Command()
        {
            bool isBlacklisted     = true;
            var  wildcardBlacklist = new[]
            {
                "loli",
                "con",
                "shota",
                "rape"
            };

            string[] tags = new[]
            {
                SearchClient.GetExcludeTag("rape"),
                SearchClient.GetExcludeTag("loli"),
                SearchClient.GetExcludeTag("lolicon"),
                SearchClient.GetExcludeTag("furry"),
                SearchClient.GetExcludeTag("vore"),
                SearchClient.GetExcludeTag("gore"),
                SearchClient.GetExcludeTag("shotacon")
            };

            while (isBlacklisted)
            {
                var r = new Random();

                SearchResult result = await SearchClient.SearchWithTagsAsync(tags.ToArray());

                int page = r.Next(0, result.numPages) + 1; // Page count begins at 1.

                result = await SearchClient.SearchWithTagsAsync(tags.ToArray(), page);

                GalleryElement selection = result.elements[r.Next(0, result.elements.Length)];

                string tagString = selection.tags.Aggregate("", (current, tag) => current + $"`{tag.name}`, ");
                tagString = tagString.Substring(0, tagString.Length - 2);

                if (wildcardBlacklist.Any(tagString.Contains))
                {
                    continue;
                }

                isBlacklisted = false;

                var embed = new KaguyaEmbedBuilder
                {
                    Title       = $"{selection.englishTitle}",
                    Description = $"[[Source]]({selection.url})",
                    Fields      = new List <EmbedFieldBuilder>()
                    {
                        new EmbedFieldBuilder
                        {
                            Name  = "Favorites",
                            Value = selection.numFavorites.ToString("N0")
                        },
                        new EmbedFieldBuilder
                        {
                            Name  = "Date Uploaded",
                            Value = selection.uploadDate.Humanize()
                        },
                        new EmbedFieldBuilder
                        {
                            Name  = "Pages",
                            Value = selection.numPages
                        },
                        new EmbedFieldBuilder
                        {
                            Name  = "Tags",
                            Value = tagString
                        }
                    },
                    ImageUrl = selection.thumbnail.imageUrl.ToString()
                };

                await ReplyAsync(embed : embed.Build());
            }
        }