예제 #1
0
파일: NSFW.cs 프로젝트: faulty15/Faulty
        public static async Task <string> GetDanbooruImageLink(string tag)
        {
            var rng = new FaultyRandom();

            if (tag == "loli") //loli doesn't work for some reason atm
            {
                tag = "flat_chest";
            }

            var link = $"http://danbooru.donmai.us/posts?" +
                       $"page={rng.Next(0, 15)}";

            if (!string.IsNullOrWhiteSpace(tag))
            {
                link += $"&tags={tag.Replace(" ", "_")}";
            }
            using (var http = new HttpClient())
            {
                var webpage = await http.GetStringAsync(link).ConfigureAwait(false);

                var matches = Regex.Matches(webpage, "data-large-file-url=\"(?<id>.*?)\"");

                if (matches.Count == 0)
                {
                    return(null);
                }
                return($"http://danbooru.donmai.us" +
                       $"{matches[rng.Next(0, matches.Count)].Groups["id"].Value}");
            }
        }
예제 #2
0
            public async Task Place(IUserMessage imsg, PlaceType placeType, uint width = 0, uint height = 0)
            {
                var channel = (ITextChannel)imsg.Channel;

                string url = "";

                switch (placeType)
                {
                case PlaceType.Cage:
                    url = "http://www.placecage.com";
                    break;

                case PlaceType.Steven:
                    url = "http://www.stevensegallery.com";
                    break;

                case PlaceType.Beard:
                    url = "http://placebeard.it";
                    break;

                case PlaceType.Fill:
                    url = "http://www.fillmurray.com";
                    break;

                case PlaceType.Bear:
                    url = "https://www.placebear.com";
                    break;

                case PlaceType.Kitten:
                    url = "http://placekitten.com";
                    break;

                case PlaceType.Bacon:
                    url = "http://baconmockup.com";
                    break;

                case PlaceType.Xoart:
                    url = "http://xoart.link";
                    break;
                }
                var rng = new FaultyRandom();

                if (width <= 0 || width > 1000)
                {
                    width = (uint)rng.Next(250, 850);
                }

                if (height <= 0 || height > 1000)
                {
                    height = (uint)rng.Next(250, 850);
                }

                url += $"/{width}/{height}";

                await channel.SendMessageAsync(url).ConfigureAwait(false);
            }
예제 #3
0
            public async Task Roll(IUserMessage umsg, int num)
            {
                var channel = (ITextChannel)umsg.Channel;

                if (channel == null)
                {
                    return;
                }

                var ordered = true;

                if (num < 1 || num > 30)
                {
                    await channel.SendMessageAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);

                    return;
                }

                var rng = new FaultyRandom();

                var dice   = new List <Image>(num);
                var values = new List <int>(num);

                for (var i = 0; i < num; i++)
                {
                    var randomNumber = rng.Next(1, 7);
                    var toInsert     = dice.Count;
                    if (ordered)
                    {
                        if (randomNumber == 6 || dice.Count == 0)
                        {
                            toInsert = 0;
                        }
                        else if (randomNumber != 1)
                        {
                            for (var j = 0; j < dice.Count; j++)
                            {
                                if (values[j] < randomNumber)
                                {
                                    toInsert = j;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        toInsert = dice.Count;
                    }
                    dice.Insert(toInsert, GetDice(randomNumber));
                    values.Insert(toInsert, randomNumber);
                }

                var bitmap = dice.Merge();
                var ms     = new MemoryStream();

                bitmap.SaveAsPng(ms);
                ms.Position = 0;
                await channel.SendFileAsync(ms, "dice.png", $"{umsg.Author.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
            }
예제 #4
0
            public async Task Roll(IUserMessage umsg)
            {
                var channel = (ITextChannel)umsg.Channel;

                if (channel == null)
                {
                    return;
                }
                var rng = new FaultyRandom();
                var gen = rng.Next(1, 101);

                var num1        = gen / 10;
                var num2        = gen % 10;
                var imageStream = await Task.Run(() =>
                {
                    try
                    {
                        var ms = new MemoryStream();
                        new[] { GetDice(num1), GetDice(num2) }.Merge().SaveAsPng(ms);
                        ms.Position = 0;
                        return(ms);
                    }
                    catch { return(new MemoryStream()); }
                });

                await channel.SendFileAsync(imageStream, "dice.png", $"{umsg.Author.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false);
            }
예제 #5
0
            public async Task MagicItem(IUserMessage umsg)
            {
                var channel = (ITextChannel)umsg.Channel;
                var rng     = new FaultyRandom();
                var item    = magicItems[rng.Next(0, magicItems.Count)].ToString();

                await channel.SendMessageAsync(item).ConfigureAwait(false);
            }
예제 #6
0
파일: NSFW.cs 프로젝트: faulty15/Faulty
        public static async Task <string> GetRule34ImageLink(string tag)
        {
            var rng = new FaultyRandom();
            var url =
                $"http://rule34.xxx/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";

            using (var http = new HttpClient())
            {
                var webpage = await http.GetStringAsync(url).ConfigureAwait(false);

                var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
                if (matches.Count == 0)
                {
                    return(null);
                }
                var match = matches[rng.Next(0, matches.Count)];
                return("http:" + matches[rng.Next(0, matches.Count)].Groups["url"].Value);
            }
        }
예제 #7
0
파일: NSFW.cs 프로젝트: faulty15/Faulty
        public static async Task <string> GetGelbooruImageLink(string tag)
        {
            using (var http = new HttpClient())
            {
                http.AddFakeHeaders();

                var webpage = await http.GetStringAsync("http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=100&tags=" + tag.Replace(" ", "_")).ConfigureAwait(false);

                var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
                if (matches.Count == 0)
                {
                    return(null);
                }

                var rng   = new FaultyRandom();
                var match = matches[rng.Next(0, matches.Count)];
                return(matches[rng.Next(0, matches.Count)].Groups["url"].Value);
            }
        }
예제 #8
0
파일: NSFW.cs 프로젝트: faulty15/Faulty
        public static async Task <string> GetYandereImageLink(string tag)
        {
            var rng = new FaultyRandom();
            var url =
                $"https://yande.re/post.xml?" +
                $"limit=25" +
                $"&page={rng.Next(0, 15)}" +
                $"&tags={tag.Replace(" ", "_")}";

            using (var http = new HttpClient())
            {
                var webpage = await http.GetStringAsync(url).ConfigureAwait(false);

                var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
                //var rating = Regex.Matches(webpage, "rating=\"(?<rate>.*?)\"");
                if (matches.Count == 0)
                {
                    return(null);
                }
                return(matches[rng.Next(0, matches.Count)].Groups["url"].Value);
            }
        }
예제 #9
0
        public void Reload()
        {
            var arr = JArray.Parse(File.ReadAllText("data/questions.json"));

            foreach (var item in arr)
            {
                var tq = new TriviaQuestion(item["Question"].ToString().SanitizeMentions(), item["Answer"].ToString().SanitizeMentions(), item["Category"]?.ToString());
                pool.Add(tq);
            }
            var r = new FaultyRandom();

            pool = new ConcurrentHashSet <TriviaQuestion>(pool.OrderBy(x => r.Next()));
        }
예제 #10
0
파일: NSFW.cs 프로젝트: faulty15/Faulty
        public static async Task <string> GetKonachanImageLink(string tag)
        {
            var rng = new FaultyRandom();

            var link = $"http://konachan.com/post?" +
                       $"page={rng.Next(0, 5)}";

            if (!string.IsNullOrWhiteSpace(tag))
            {
                link += $"&tags={tag.Replace(" ", "_")}";
            }
            using (var http = new HttpClient())
            {
                var webpage = await http.GetStringAsync(link).ConfigureAwait(false);

                var matches = Regex.Matches(webpage, "<a class=\"directlink largeimg\" href=\"(?<ll>.*?)\">");

                if (matches.Count == 0)
                {
                    return(null);
                }
                return(matches[rng.Next(0, matches.Count)].Groups["ll"].Value);
            }
        }
예제 #11
0
파일: Games.cs 프로젝트: faulty15/Faulty
        public async Task Choose(IUserMessage umsg, [Remainder] string list = null)
        {
            var channel = (ITextChannel)umsg.Channel;

            if (string.IsNullOrWhiteSpace(list))
            {
                return;
            }
            var listArr = list.Split(';');

            if (listArr.Count() < 2)
            {
                return;
            }
            var rng = new FaultyRandom();
            await channel.SendMessageAsync(listArr[rng.Next(0, listArr.Length)]).ConfigureAwait(false);
        }
예제 #12
0
파일: NSFW.cs 프로젝트: faulty15/Faulty
        public async Task Hentai(IUserMessage umsg, [Remainder] string tag = null)
        {
            var channel = (ITextChannel)umsg.Channel;

            tag = tag?.Trim() ?? "";

            tag = "rating%3Aexplicit+" + tag;

            var           rng      = new FaultyRandom();
            Task <string> provider = Task.FromResult("");

            switch (rng.Next(0, 4))
            {
            case 0:
                provider = GetDanbooruImageLink(tag);
                break;

            case 1:
                provider = GetGelbooruImageLink(tag);
                break;

            case 2:
                provider = GetKonachanImageLink(tag);
                break;

            case 3:
                provider = GetYandereImageLink(tag);
                break;

            default:
                break;
            }
            var link = await provider.ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(link))
            {
                await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false);
            }
            else
            {
                await channel.SendMessageAsync(link).ConfigureAwait(false);
            }
        }
예제 #13
0
            public async Task Roll(IUserMessage umsg, string arg)
            {
                var channel = (ITextChannel)umsg.Channel;

                if (channel == null)
                {
                    return;
                }

                var   ordered = true;
                var   rng     = new FaultyRandom();
                Match match;

                if ((match = dndRegex.Match(arg)).Length != 0)
                {
                    int n1;
                    int n2;
                    if (int.TryParse(match.Groups["n1"].ToString(), out n1) &&
                        int.TryParse(match.Groups["n2"].ToString(), out n2) &&
                        n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
                    {
                        var add = 0;
                        var sub = 0;
                        int.TryParse(match.Groups["add"].Value, out add);
                        int.TryParse(match.Groups["sub"].Value, out sub);

                        var arr = new int[n1];
                        for (int i = 0; i < n1; i++)
                        {
                            arr[i] = rng.Next(1, n2 + 1) + add - sub;
                        }
                        var elemCnt = 0;
                        await channel.SendMessageAsync($"{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
                    }
                }
            }
예제 #14
0
                private async Task StartRace()
                {
                    var          rng    = new FaultyRandom();
                    Participant  winner = null;
                    IUserMessage msg    = null;
                    int          place  = 1;

                    try
                    {
                        FaultyBot.Client.MessageReceived += Client_MessageReceived;

                        while (!participants.All(p => p.Total >= 60))
                        {
                            //update the state
                            participants.ForEach(p =>
                            {
                                p.Total += 1 + rng.Next(0, 10);
                                if (p.Total > 60)
                                {
                                    p.Total = 60;
                                    if (winner == null)
                                    {
                                        winner = p;
                                    }
                                    if (p.Place == 0)
                                    {
                                        p.Place = place++;
                                    }
                                }
                            });


                            //draw the state

                            var text = $@"|🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|
{String.Join("\n", participants.Select(p => $"{(int)(p.Total / 60f * 100),-2}%|{p.ToString()}"))}
|🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|";
                            if (msg == null || messagesSinceGameStarted >= 10) // also resend the message if channel was spammed
                            {
                                if (msg != null)
                                {
                                    try { await msg.DeleteAsync(); } catch { }
                                }
                                messagesSinceGameStarted = 0;
                                try { msg = await raceChannel.SendMessageAsync(text).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                            }
                            else
                            {
                                try { await msg.ModifyAsync(m => m.Content = text).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                            }

                            await Task.Delay(2500);
                        }
                    }
                    catch { }
                    finally
                    {
                        FaultyBot.Client.MessageReceived -= Client_MessageReceived;
                    }

                    if (winner.AmountBet > 0)
                    {
                        var wonAmount = winner.AmountBet * (participants.Count - 1);

                        await CurrencyHandler.AddCurrencyAsync(winner.User, "Won a Race", wonAmount, false).ConfigureAwait(false);

                        await raceChannel.SendMessageAsync($"🏁 {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{CurrencySign}!**").ConfigureAwait(false);
                    }
                    else
                    {
                        await raceChannel.SendMessageAsync($"🏁 {winner.User.Mention} as {winner.Animal} **Won the race!**");
                    }
                }
예제 #15
0
파일: Searches.cs 프로젝트: faulty15/Faulty
        public async Task Ir(IUserMessage umsg, [Remainder] string query = null)
        {
            var channel = (ITextChannel)umsg.Channel;

            if (string.IsNullOrWhiteSpace(query))
            {
                return;
            }
            try
            {
                using (var http = new HttpClient())
                {
                    var rng       = new FaultyRandom();
                    var reqString = $"https://www.googleapis.com/customsearch/v1?q={Uri.EscapeDataString(query)}&cx=018084019232060951019%3Ahs5piey28-e&num=1&searchType=image&start={ rng.Next(1, 50) }&fields=items%2Flink&key={FaultyBot.Credentials.GoogleApiKey}";
                    var obj       = JObject.Parse(await http.GetStringAsync(reqString).ConfigureAwait(false));
                    var items     = obj["items"] as JArray;
                    await channel.SendMessageAsync(items[0]["link"].ToString()).ConfigureAwait(false);
                }
            }
            catch (HttpRequestException exception)
            {
                if (exception.Message.Contains("403 (Forbidden)"))
                {
                    await channel.SendMessageAsync("Daily limit reached!");
                }
                else
                {
                    await channel.SendMessageAsync("Something went wrong.");
                }
            }
        }
예제 #16
0
        public Task <Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword)
        {
            var rng = new FaultyRandom();

            return(_set.Where(q => q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rng.Next()).FirstOrDefaultAsync());
        }