Пример #1
0
        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 NadekoRandom();
            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);
        }
Пример #2
0
            public async Task Roll(IUserMessage umsg, string arg)
            {
                var channel = (ITextChannel)umsg.Channel;
                if (channel == null)
                    return;

                var ordered = true;
                var rng = new NadekoRandom();
                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);
                    }
                }
            }
Пример #3
0
        public async Task _8Ball(IUserMessage umsg, [Remainder] string question = null)
        {
            var channel = (ITextChannel)umsg.Channel;

            if (string.IsNullOrWhiteSpace(question))
                return;
                var rng = new NadekoRandom();
            await channel.SendMessageAsync($@"❓ `Question` __**{question}**__ 
🎱 `8Ball Answers` __**{_8BallResponses.Shuffle().FirstOrDefault()}**__").ConfigureAwait(false);
        }
Пример #4
0
 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 NadekoRandom();
     await channel.SendMessageAsync(listArr[rng.Next(0, listArr.Length)]).ConfigureAwait(false);
 }
 public async Task Scsc(IUserMessage msg)
 {
     var channel = (ITextChannel)msg.Channel;
     var token = new NadekoRandom().Next();
     var set = new ConcurrentHashSet<ITextChannel>();
     if (Subscribers.TryAdd(token, set))
     {
         set.Add(channel);
         await ((IGuildUser)msg.Author).SendMessageAsync("This is your CSC token:" + token.ToString()).ConfigureAwait(false);
     }
 }
Пример #6
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 NadekoRandom();
            pool = new ConcurrentHashSet<TriviaQuestion>(pool.OrderBy(x => r.Next()));
        }
Пример #7
0
 public static async Task<string> GetYandereImageLink(string tag)
 {
     var rng = new NadekoRandom();
     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;
     }
 }
Пример #8
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 NadekoRandom();
                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);
            }
Пример #9
0
            public async Task Roll(IUserMessage umsg)
            {
                var channel = (ITextChannel)umsg.Channel;
                if (channel == null)
                    return;
                var rng = new NadekoRandom();
                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);
            }
Пример #10
0
                private async Task StartRace()
                {
                    var rng = new NadekoRandom();
                    Participant winner = null;
                    IUserMessage msg = null;
                    int place = 1;
                    try
                    {
                        NadekoBot.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
                    {
                        NadekoBot.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!**");
                    }

                }
Пример #11
0
 public static async Task<string> GetRule34ImageLink(string tag)
 {
     var rng = new NadekoRandom();
     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;
     }
 }
Пример #12
0
        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 NadekoRandom();
                var match = matches[rng.Next(0, matches.Count)];
                return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
            }
        }
Пример #13
0
        public static async Task<string> GetDanbooruImageLink(string tag)
        {
            var rng = new NadekoRandom();

            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}";
            }
        }
Пример #14
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 NadekoRandom();

                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);
            }
Пример #15
0
        public static async Task<string> GetKonachanImageLink(string tag)
        {
            var rng = new NadekoRandom();

            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;
            }
        }
Пример #16
0
        public async Task Videocall(IUserMessage umsg, [Remainder] string arg = null)
        {
            var channel = (ITextChannel)umsg.Channel;

            try
            {
                var allUsrs = umsg.MentionedUsers.Append(umsg.Author);
                var allUsrsArray = allUsrs.ToArray();
                var str = allUsrsArray.Aggregate("http://appear.in/", (current, usr) => current + Uri.EscapeUriString(usr.Username[0].ToString()));
                str += new NadekoRandom().Next();
                foreach (var usr in allUsrsArray)
                {
                    await (await (usr as IGuildUser).CreateDMChannelAsync()).SendMessageAsync(str).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #17
0
        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 NadekoRandom();
                    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={NadekoBot.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.");
                }
            }
        }
Пример #18
0
            public async Task MagicItem(IUserMessage umsg)
            {
                var channel = (ITextChannel)umsg.Channel;
                var rng = new NadekoRandom();
                var item = magicItems[rng.Next(0, magicItems.Count)].ToString();

                await channel.SendMessageAsync(item).ConfigureAwait(false);
            }
Пример #19
0
        public async Task Rps(IUserMessage umsg, string input)
        {
            var channel = (ITextChannel)umsg.Channel;

            Func<int,string> GetRPSPick = (p) =>
            {
                if (p == 0)
                    return "🚀";
                else if (p == 1)
                    return "📎";
                else
                    return "✂️";
            };

            int pick;
            switch (input)
            {
                case "r":
                case "rock":
                case "rocket":
                    pick = 0;
                    break;
                case "p":
                case "paper":
                case "paperclip":
                    pick = 1;
                    break;
                case "scissors":
                case "s":
                    pick = 2;
                    break;
                default:
                    return;
            }
            var nadekoPick = new NadekoRandom().Next(0, 3);
            var msg = "";
            if (pick == nadekoPick)
                msg = $"It's a draw! Both picked {GetRPSPick(pick)}";
            else if ((pick == 0 && nadekoPick == 1) ||
                     (pick == 1 && nadekoPick == 2) ||
                     (pick == 2 && nadekoPick == 0))
                msg = $"{NadekoBot.Client.GetCurrentUser().Mention} won! {GetRPSPick(nadekoPick)} beats {GetRPSPick(pick)}";
            else
                msg = $"{umsg.Author.Mention} won! {GetRPSPick(pick)} beats {GetRPSPick(nadekoPick)}";

            await channel.SendMessageAsync(msg).ConfigureAwait(false);
        }
Пример #20
0
        public async Task BetRoll(IUserMessage umsg, long amount)
        {
            var channel = (ITextChannel)umsg.Channel;

            if (amount < 1)
                return;

            var guildUser = (IGuildUser)umsg.Author;

            long userFlowers;
            using (var uow = DbHandler.UnitOfWork())
            {
                userFlowers = uow.Currency.GetOrCreate(umsg.Author.Id).Amount;
            }

            if (userFlowers < amount)
            {
                await channel.SendMessageAsync($"{guildUser.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false);
                return;
            }

            await CurrencyHandler.RemoveCurrencyAsync(guildUser, "Betroll Gamble", amount, false).ConfigureAwait(false);

            var rng = new NadekoRandom().Next(0, 101);
            var str = $"{guildUser.Mention} `You rolled {rng}.` ";
            if (rng < 67)
            {
                str += "Better luck next time.";
            }
            else if (rng < 91)
            {
                str += $"Congratulations! You won {amount * 2}{Gambling.CurrencySign} for rolling above 66";
                await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 2, false).ConfigureAwait(false);
            }
            else if (rng < 100)
            {
                str += $"Congratulations! You won {amount * 3}{Gambling.CurrencySign} for rolling above 90.";
                await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 3, false).ConfigureAwait(false);
            }
            else
            {
                str += $"👑 Congratulations! You won {amount * 10}{Gambling.CurrencySign} for rolling **100**. 👑";
                await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 10, false).ConfigureAwait(false);
            }

            await channel.SendMessageAsync(str).ConfigureAwait(false);
        }
Пример #21
0
            public async Task NRoll(IUserMessage umsg, [Remainder] string range)
            {
                var channel = (ITextChannel)umsg.Channel;

                try
                {
                    int rolled;
                    if (range.Contains("-"))
                    {
                        var arr = range.Split('-')
                                        .Take(2)
                                        .Select(int.Parse)
                                        .ToArray();
                        if (arr[0] > arr[1])
                            throw new ArgumentException("First argument should be bigger than the second one.");
                        rolled = new NadekoRandom().Next(arr[0], arr[1] + 1);
                    }
                    else
                    {
                        rolled = new NadekoRandom().Next(0, int.Parse(range) + 1);
                    }

                    await channel.SendMessageAsync($"{umsg.Author.Mention} rolled **{rolled}**.").ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    await channel.SendMessageAsync($":anger: {ex.Message}").ConfigureAwait(false);
                }
            }