Esempio n. 1
0
        /// <summary>Takes a danbooru.Image object and returns formatted tag string.</summary>
        /// <param name="img">A danbooru.Image object that will have tags extracted</param>
        /// <returns>Formatted tag and artist string.</returns>
        public static string BuildDanbooruTags(danbooru.Image img)
        {
            // Adds commas to tags, for easier reading.
            //put the artist and general tags string together.
            string allTagsstring = img.tag_string_general + " " + img.tag_string_copyright + " " + img.tag_string_character;
            string tagString     = allTagsstring.Replace(" ", ", ");
            // Create string with ratings and artist tags
            string artistAndRating = ratings[img.rating.ToString()] + "**Artist(s):** " + img.tag_string_artist;

            //return string with lots of formatting!
            return("**Info:** " + artistAndRating + "\n\n" + "All tags: \n```" + tagString + "```");
        }
Esempio n. 2
0
        public async Task danbooruSearchSort([Remainder] string srch)
        {
            await Context.Channel.TriggerTypingAsync();

            //url for use, explicit images and inserts provided tags straight in.
            string url;

            //if channel is not on the explicit channels list,
            if (!DBTransaction.isChannelWhitelisted(Context.Channel.Id) && !Context.IsPrivate)
            {
                url = $"https://danbooru.donmai.us/posts.json?tags={srch}+Rating%3Asafe&limit=50";
            }
            else
            {
                url = $"https://danbooru.donmai.us/posts.json?tags={srch}&limit=50";
            }
            string respond = danbooru.getJSON(url).Result;

            if (respond == "failure")
            {
                await ReplyAsync("An error occurred! It is possible your search returned 0 results or the results are filtered out due to channel.");

                return;
            }
            ImageList responseList = JsonConvert.DeserializeObject <ImageList>(respond);

            if (responseList.Count == 0)
            {
                await ReplyAsync("No results! The tag may be misspelled, or the results could be filtered out due to channel!");
            }
            else
            {
                Global.danbooruSearches[Context.Channel.Id] = respond;
                Random rand = new Random();
                Global.danbooruSearchIndex[Context.Channel.Id] = rand.Next(0, responseList.Count);
                danbooru.Image chosenImage = responseList[Global.danbooruSearchIndex[Context.Channel.Id]];
                int            loopCounter = 0;
                while (chosenImage.file_url == null)
                {
                    loopCounter++;
                    if (loopCounter > responseList.Count)
                    {
                        await ReplyAsync("No returned images had valid links, you may have searched a hidden tag such as loli. Make a new search.");

                        return;
                    }
                    Global.danbooruSearchIndex[Context.Channel.Id] = rand.Next(0, responseList.Count);
                    chosenImage = responseList[Global.danbooruSearchIndex[Context.Channel.Id]];
                }

                await ReplyAsync(chosenImage.file_url + "\n" + chosenImage.tag_string_artist.Replace(" ", ", "));
            }
        }
Esempio n. 3
0
        public async Task danbooruTags()
        {
            await Context.Channel.TriggerTypingAsync();

            if (Global.danbooruSearches.ContainsKey(Context.Channel.Id))
            {
                ImageList      responseList = JsonConvert.DeserializeObject <ImageList>(Global.danbooruSearches[Context.Channel.Id]);
                danbooru.Image chosen       = responseList.ElementAt(Global.danbooruSearchIndex[Context.Channel.Id]);
                if (responseList.Count == 0)
                {
                    await ReplyAsync("No results! The tag may be misspelled, or the results could be filtered out due to channel!");

                    return;
                }

                await ReplyAsync(BuildDanbooruTags(chosen));
            }
            else
            {
                await ReplyAsync("You have to make a search first! Try running ~e <tag(s)>");
            }
        }