Exemple #1
0
        private async Task SearchUrban(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args)
        {
            string search = "";

            if (string.IsNullOrWhiteSpace(args[0]))
            {
                await embedrep.Danger(msg, "Urban", "No entry to look for was given");
            }
            else
            {
                int page = 0;
                if (args.Count > 1)
                {
                    if (!string.IsNullOrWhiteSpace(args[1]))
                    {
                        if (int.TryParse(args[1].Trim(), out int temp))
                        {
                            page = temp - 1;
                        }
                    }
                }

                search = args[0];
                string body = await HTTP.Fetch("http://api.urbandictionary.com/v0/define?term=" + search, this.Log);

                Urban.UGlobal global = JSON.Deserialize <Urban.UGlobal>(body, this.Log);

                if (global == null)
                {
                    await embedrep.Danger(msg, "Err", "There was no data to use for this!");
                }
                else
                {
                    if (global.list.Length == 0)
                    {
                        await embedrep.Danger(msg, "Arf!", "Looks like I couldn't find anything!");
                    }
                    else
                    {
                        if (global.list.Length - 1 >= page && page >= 0)
                        {
                            Urban.UWord wordobj    = global.list[page];
                            bool        hasexample = string.IsNullOrWhiteSpace(wordobj.example);
                            string      smalldef   = wordobj.definition.Length > 300 ? wordobj.definition.Remove(300) + "..." : wordobj.definition;
                            await embedrep.Good(msg, "Definition #" + (page + 1),
                                                "**" + wordobj.permalink + "**\n\n"
                                                + smalldef + (!hasexample ? "\n\nExample:\n\n*" + wordobj.example + "*" : "") + "\n\n" +
                                                ":thumbsup: x" + wordobj.thumbs_up + "\t :thumbsdown: x" + wordobj.thumbs_down);
                        }
                        else
                        {
                            await embedrep.Danger(msg, "uh", "No result for definition n°" + (page + 1));
                        }
                    }
                }
            }
        }
Exemple #2
0
        private async Task SearchE621(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args)
        {
            if (msg.Channel.IsNsfw)
            {
                Random rand = new Random();
                string body = await HTTP.Fetch("https://e621.net/post/index.json", this.Log);

                List <E621.EPost> posts = JSON.Deserialize <List <E621.EPost> >(body, this.Log);
                E621.EPost        post;

                if (posts == null)
                {
                    await embedrep.Danger(msg, "Err", "There was no data to use sorry!");
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(args[0]))
                    {
                        post = E621.SortingHandler.GetRandom(posts);
                    }
                    else
                    {
                        post = E621.Search.Handle(posts, args);
                    }

                    if (post == null)
                    {
                        await embedrep.Danger(msg, "Nooo", "Seems like I couldn't find anything!");
                    }
                    else
                    {
                        EmbedBuilder embed = new EmbedBuilder
                        {
                            Color       = new Color(110, 220, 110),
                            ImageUrl    = post.sample_url,
                            Title       = "E621 - " + msg.Author.Username,
                            Description = post.sample_url + "\n*Width: " + post.sample_width + "\tHeight: " + post.sample_height + "*"
                        };

                        await embedrep.Send(msg, embed.Build());
                    }
                }
            }
            else
            {
                await embedrep.Danger(msg, "Hum no.", "Haha, did you really believe it would be that easy? :smirk:");
            }
        }
Exemple #3
0
        private async Task Alerts(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args)
        {
            string body = await HTTP.Fetch("http://content.warframe.com/dynamic/worldState.php", this.Log);

            WGlobal global = JSON.Deserialize <WGlobal>(body, this.Log);

            if (global == null)
            {
                await embedrep.Danger(msg, "Err", "Looks like I couldn't access date for that!");
            }
            else
            {
                for (int i = 0; i < global.Alerts.Length; i++)
                {
                    WAlert   alert   = global.Alerts[i];
                    WMission minfo   = alert.MissionInfo;
                    WReward  mreward = minfo.missionReward;

                    DateTime endtime = DateTime.Now.Date.AddTicks(alert.Expiry.date.numberLong);
                    DateTime offset  = new DateTime().AddHours(5); //canada time offset (server hosted in germany)
                    DateTime nowtime = new DateTime(DateTime.Now.Subtract(offset).Ticks);

                    string showrewards = "";

                    if (mreward.items != null)
                    {
                        showrewards = "**Items**: \n";
                        for (int j = 0; j < mreward.items.Length; j++)
                        {
                            string[] dirs = mreward.items[j].Split("/");
                            string   name = dirs[dirs.Length - 1];

                            showrewards += "\t\t" + name + "\n";
                        }
                    }

                    await embedrep.Good(msg, "Warframe Alert #" + (i + 1),
                                        "**Level**: " + minfo.minEnemyLevel + " - " + minfo.maxEnemyLevel + "\t**Type**: " + minfo.missionType.Substring(3).ToLower().Replace("_", " ")
                                        + "\t**Enemy**: " + minfo.faction.Substring(3).ToLower() + "\n"
                                        + "**Credits**: " + mreward.credits + "\t**Time Left**: " + (endtime.Subtract(nowtime).Minutes) + "mins\n"
                                        + showrewards
                                        );
                }
            }
        }
Exemple #4
0
        public static async Task <string> Ask(SocketChannel chan, string sentence, BotLog log)
        {
            if (!_Cookies.TryGetValue(chan, out CookieContainer cookie))
            {
                cookie = new CookieContainer();
                _Cookies.Add(chan, cookie);
            }

            NameValueCollection values = HttpUtility.ParseQueryString(string.Empty);

            values["name"]     = "EBot";
            values["question"] = sentence;

            string parameters = values.ToString();
            string html       = await HTTP.Fetch(_URL + parameters, log, null, request => {
                request.CookieContainer = cookie;
            });

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            HtmlNode SELECT = doc.DocumentNode.Element("html").Element("body").Element("div").Element("select");

            foreach (HtmlNode node in SELECT.ChildNodes)
            {
                string start = "answer = ";
                if (node.InnerText.StartsWith(start))
                {
                    string answer = node.InnerText.Remove(0, start.Length);
                    Random rand   = new Random();
                    if (rand.Next(0, 100) <= 25) // 1/4
                    {
                        string end = " " + _SentencesEnd[rand.Next(0, _SentencesEnd.Length - 1)];
                        answer = answer.Substring(0, answer.Length - 3) + end;
                    }

                    return(answer);
                }
            }

            return(null);
        }
Exemple #5
0
        private async Task ASCII(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args)
        {
            if (string.IsNullOrWhiteSpace(args[0]))
            {
                await embedrep.Danger(msg, "Nope", "You didn't provide any word or sentence!");
            }
            else
            {
                string body = await HTTP.Fetch("http://artii.herokuapp.com/make?text=" + args[0], Log);

                if (body.Length > 2000)
                {
                    await embedrep.Danger(msg, "ASCII", "The word or sentence you provided is too long!");
                }
                else
                {
                    await msg.Channel.SendMessageAsync("```\n" + body + "\n```");
                }
            }
        }