Ejemplo n.º 1
0
        public static BooruResult SearchForImage(string SearchTerm)
        {
            //replace any instance of >= <= > and < with the relevant syntax
            SearchTerm = SearchTerm.Replace(">=", ":>=");
            SearchTerm = SearchTerm.Replace("<=", ":<=");
            SearchTerm = SearchTerm.Replace(">", ":>");
            SearchTerm = SearchTerm.Replace("<", ":<");

            //make a new container for our result
            BooruResult result = new BooruResult();

            //constructing a search string
            string baseLink = "https://e621.net/post/index.json?tags=";

            //https://e621.net/post/index.json?tags=penis+order%3Arandom
            string currentPage = baseLink + SearchTerm + "+order%3Arandom";

            string  searchResult = BooruUtilities.GetPage(currentPage);
            dynamic stuff        = JsonConvert.DeserializeObject(searchResult);

            if (stuff.Count > 0)
            {
                result.link = stuff[0].file_url;
                //extract page link
                //image score
                result.score = stuff[0].score;
                //e621 handily has an artist tag
                if (stuff[0].artist.Count > 0)
                {
                    result.artist = stuff[0].artist[0];
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        internal static async Task PostAFact(SocketMessage e)
        {
            try
            {
                Random random = new Random();
                if (random.Next(100) < 95)
                {
                    //Go to the TodayILearned subreddit, get the whole front page, and post a random title (minus the TIL)
                    string  page         = "https://www.reddit.com/r/todayilearned/hot.json";
                    string  searchResult = BooruUtilities.GetPage(page);
                    dynamic stuff        = JsonConvert.DeserializeObject(searchResult);

                    //get data.children
                    string fact = null;



                    int totalFacts = Convert.ToInt32(stuff.data.children.Count);
                    int factNum    = random.Next(totalFacts);

                    fact = stuff.data.children[factNum].data.title;
                    fact = fact.Substring(4);

                    await e.Channel.SendMessageAsync("**Did you know:** `<" + fact + ">`");
                }
                else
                {
                    string[] result = new string[] { "Historia's hair smells like a library!",
                                                     "Historia does not like using fish as a bookmark :c  ",
                                                     "I sometimes illustrate Historia's books with crayon!... Then she yells at me",
                                                     "My middle name is fish!",
                                                     "Historia's trying her best to learn sign language!",
                                                     "I love all of you!",
                                                     "I like fish!" };
                    int r = random.Next(result.Count());
                    await e.Channel.SendMessageAsync("**Did you know:** `<" + result[r] + ">`");
                }
            }
            catch (Exception ex)
            {
                await e.Channel.SendMessageAsync("`Coral is running around panicking because something went badly wrong!!!!`\n" + ex.Message);
            }
        }
Ejemplo n.º 3
0
        public static BooruResult SearchForImage(string SearchTerm, bool isSafeSearch)
        {
            //replace any instance of >= <= > and < with the relevant syntax
            SearchTerm = SearchTerm.Replace(">=", ".gte:");
            SearchTerm = SearchTerm.Replace("<=", ".lte:");
            SearchTerm = SearchTerm.Replace(">", ".gt:");
            SearchTerm = SearchTerm.Replace("<", ".lt:");

            string[] searchParts = SearchTerm.Split(',');
            for (int i = 0; i < searchParts.Length; i++)
            {
                searchParts[i] = searchParts[i].Trim();
            }

            //Aliases
            for (int i = 0; i < searchParts.Length; i++)
            {
                if (searchParts[i] == "nsfw")
                {
                    searchParts[i] = "(explicit OR questionable)";
                }
                if (searchParts[i] == "tiddies")
                {
                    searchParts[i] = "breasts";
                }
            }
            SearchTerm = "";
            foreach (string par in searchParts)
            {
                SearchTerm += par + ",";
            }

            SearchTerm = SearchTerm.Trim(new char[] { ',' });

            //make a new container for our result
            BooruResult result = new BooruResult();

            //make safe search
            if (isSafeSearch)
            {
                SearchTerm += ", (Safe OR Suggestive)";
            }

            //constructing a search string
            string baseLink = "https://derpibooru.org/search.json?q=";
            string keyPart  = "&key=" + Config.derpiKey;
            string pagePart = "&page=";
            int    page     = 1;
            Random random   = new Random();
            int    seed     = random.Next(900000);

            string currentPage = baseLink + SearchTerm + keyPart + pagePart + Convert.ToString(page) + "&sf=random:" + seed.ToString() + "&sd=desc";

            string  searchResult = BooruUtilities.GetPage(currentPage);
            dynamic stuff        = JsonConvert.DeserializeObject(searchResult);

            if (stuff.total > 0)
            {
                //result.link = "https:" + stuff.search[0].representations.full;
                //extract page link
                result.link = "https://derpibooru.org/" + stuff.search[0].id;
                //image score
                result.score = stuff.search[0].score;
                //get all the tags
                string   tags    = stuff.search[0].tags;
                string[] tagList = tags.Split(',');

                //we only want to show the artist though
                foreach (string tag in tagList)
                {
                    if (tag.Trim().StartsWith("artist:"))
                    {
                        result.artist = tag;
                    }
                }
            }

            return(result);
        }