public async Task e621SearchSort(int sort, [Remainder] string srch) { await Context.Channel.TriggerTypingAsync(); if (srch.Contains("loli") || srch.Contains("foalcon") || srch.Contains("cub")) { await ReplyAsync("Those search terms(loli, foalcon, or cub) are not allowed! Try again!"); return; } //if sort integer is too small or big, give help if (sort - 1 > sortingOptions.Length || sort < 0) { await ReplyAsync("Sorting integers are: \n```0:Default, newest to oldest. \n1:Oldest to newest. \n2:Score. \n3:FavCount. \n4:Random.```" + "\nManual sorting can be done by using this chart https://e621.net/help/show/cheatsheet#sorting and inserting it into a search as a tag. " + "\nEx: Overriding default search order with mpixels order.```~e order:mpixels horse```"); return; } //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://e621.net/posts.json?tags=order:{sortingOptions[sort]}+{srch}+rating:s&limit=50"; } else { url = $"https://e621.net/posts.json?tags=order:{sortingOptions[sort]}+{srch}+-cub+-loli+-foalcon&limit=50"; } string respond = e621.getJSON(url).Result; if (respond == "failure") { await ReplyAsync("An error occurred! " + url); return; } ImageList responseList = JsonConvert.DeserializeObject <ImageRoot>(respond).posts; 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.e621Searches[Context.Channel.Id] = respond; Random rand = new Random(); Global.e621SearchIndex[Context.Channel.Id] = rand.Next(0, responseList.Count); e621.Post chosenImage = responseList[Global.e621SearchIndex[Context.Channel.Id]]; RestUserMessage msg = await Context.Channel.SendMessageAsync(chosenImage.file.url + "\n" + string.Join(",", chosenImage.tags.artist)); await msg.AddReactionAsync(new Emoji("▶")); //set random info for running ~enext through emoji reactions. Global.e621Context[Context.Channel.Id] = Context; Global.e621MessageToTrack[Context.Channel.Id] = msg.Id; } }
/// <summary>Takes an e621.Image object and returns formatted tag string.</summary> /// <param name="img">An e621.Image object that will have tags extracted</param> /// <returns>Formatted tag and artist string.</returns> public static string Builde621Tags(e621.Post img) { // Adds commas to tags, for easier reading. //put the artist and general tags List together, so I can Join them all at once. List <string> allTagsList = img.tags.character; allTagsList.AddRange(img.tags.general); string tagString = String.Join(", ", allTagsList); // Create string with ratings and artist tags string artistAndRating = ratings[img.rating.ToString()] + "**Artist(s):** " + string.Join(", ", img.tags.artist); //return string with lots of formatting! return("**Info:** " + artistAndRating + "\n\n" + "All tags: \n```" + tagString + "```"); }
public async Task e621Tags() { await Context.Channel.TriggerTypingAsync(); if (Global.e621Searches.ContainsKey(Context.Channel.Id)) { ImageList responseList = JsonConvert.DeserializeObject <ImageRoot>(Global.e621Searches[Context.Channel.Id]).posts; e621.Post chosen = responseList.ElementAt(Global.e621SearchIndex[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(e621Helper.Builde621Tags(chosen)); } else { await ReplyAsync("You have to make a search first! Try running ~e <tag(s)>"); } }