Exemplo n.º 1
0
        public async Task RandomMeme(CommandContext ctx)
        {
            JObject response = await ShimaHttpClient.HttpGet(
                $"https://api.imgur.com/3/g/memes/viral/{ThreadSafeRandom.ThisThreadsRandom.Next(1,9)}",
                new AuthenticationHeaderValue("Client-ID", ShimakazeBot.Config.apiKeys.imgurClientId));

            JToken item = null;

            if (response != null && response["data"].HasValues)
            {
                int size = response["data"].Children().Count();
                item = response["data"].Children().ToArray()[ThreadSafeRandom.ThisThreadsRandom.Next(0, size)];
            }
            if (item == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "The meme factory has stopped working 😩");

                return;
            }

            DateTime timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                                 .AddSeconds(item["datetime"].Value <long>());
            DiscordEmbedBuilder embed = Utils.BaseEmbedBuilder(ctx, null, item["title"].Value <string>(), null,
                                                               item["id"].Value <string>(), timestamp)
                                        .WithUrl(item["link"].Value <string>())
                                        .WithImageUrl(item["link"].Value <string>());

            if (!string.IsNullOrWhiteSpace(item["description"].Value <string>()))
            {
                embed.WithDescription(item["description"].Value <string>());
            }

            await CTX.RespondSanitizedAsync(ctx, null, false, embed);
        }
Exemplo n.º 2
0
        public async Task Dice(CommandContext ctx, [RemainingText] string suffix)
        {
            JObject response = await ShimaHttpClient.HttpGet($"https://rolz.org/api/?{suffix}.json");

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "The dice fell under the table...");

                return;
            }
            if (string.IsNullOrEmpty(response["result"].Value <string>()) ||
                response["result"].Value <string>().StartsWith("Error"))
            {
                await CTX.RespondSanitizedAsync(ctx, $"{response["result"].Value<string>()}" +
                                                "\nYou probably want to use the website for that one: https://rolz.org");

                return;
            }

            DateTime timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                                 .AddSeconds(response["timestamp"].Value <long>());
            DiscordEmbedBuilder embed = Utils.BaseEmbedBuilder(ctx, null,
                                                               null, null, null, timestamp)
                                        .WithAuthor(response["result"].Value <string>(), "https://rolz.org", "https://rolz.org/img/n3-d20.png")
                                        .AddField("Input", response["input"].Value <string>())
                                        .AddField("Details", response["details"].Value <string>());

            if (!string.IsNullOrWhiteSpace(response["code"].Value <string>()))
            {
                embed.AddField("Code", response["code"].Value <string>());
            }

            await CTX.RespondSanitizedAsync(ctx, null, false, embed);
        }
Exemplo n.º 3
0
        public async Task UrbanDictionary(CommandContext ctx, [RemainingText] string suffix)
        {
            if (string.IsNullOrWhiteSpace(suffix))
            {
                await CTX.RespondSanitizedAsync(ctx, ctx.User.Mention +
                                                ", If you actually tell me what word you want to look up that'll be great.");

                return;
            }
            JObject response = await ShimaHttpClient.HttpGet(
                $"http://api.urbandictionary.com/v0/define?term={suffix}");

            JToken item = null;

            if (response != null && response["list"].HasValues)
            {
                var items = response["list"].Children().ToList().OrderByDescending(i => i["thumbs_up"].Value <int>());
                item = items.First();
            }
            if (item == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "I burnt all the dictionaries because they were too slow 🔥🔥🔥");

                return;
            }
            DiscordEmbedBuilder embed = Utils.BaseEmbedBuilder(ctx, null, item["word"].Value <string>(), null,
                                                               $"{item["thumbs_up"].Value<string>()}👍 - {item["thumbs_down"].Value<string>()}👎",
                                                               item["written_on"].Value <DateTime>())
                                        .WithUrl(item["permalink"].Value <string>());

            if (item["definition"].Value <string>().Length > 2048)
            {
                embed.WithDescription(item["definition"].Value <string>().Substring(0, 2042) + " [...]");
            }
            else
            {
                embed.WithDescription(item["definition"].Value <string>());
            }
            if (!string.IsNullOrWhiteSpace(item["example"].Value <string>()))
            {
                if (item["example"].Value <string>().Length > 1024)
                {
                    embed.AddField("Example", item["example"].Value <string>().Substring(0, 1018) + " [...]");
                }
                else
                {
                    embed.AddField("Example", item["example"].Value <string>());
                }
            }

            await CTX.RespondSanitizedAsync(ctx, null, false, embed);
        }
Exemplo n.º 4
0
        public async Task YesNo(CommandContext ctx, [RemainingText] string choice)
        {
            JObject response = await ShimaHttpClient.HttpGet($"https://yesno.wtf/api/?force={choice}");

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "**No.**\nThe api broke.");

                return;
            }

            await CTX.RespondSanitizedAsync(ctx, response["image"]?.Value <string>());
        }
Exemplo n.º 5
0
        public async Task YoMomma(CommandContext ctx)
        {
            JObject response = await ShimaHttpClient.HttpGet("https://api.yomomma.info");

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "Yo momma so fat she broke the api.");

                return;
            }

            await CTX.RespondSanitizedAsync(ctx, response["joke"]?.Value <string>());
        }
Exemplo n.º 6
0
        public async Task Inspire(CommandContext ctx)
        {
            JObject response = await ShimaHttpClient.HttpGet("https://inspirobot.me/api?generate=true");

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "help viscocchi");

                return;
            }

            await CTX.RespondSanitizedAsync(ctx, $"|| {response["data"]?.Value<string>()} ||");
        }
Exemplo n.º 7
0
        public async Task UselessFact(CommandContext ctx)
        {
            JObject response = await ShimaHttpClient.HttpGet("https://uselessfacts.jsph.pl/random.json?language=en");

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "I've run out of useless facts ☹️");

                return;
            }

            await CTX.RespondSanitizedAsync(ctx, response["text"]?.Value <string>());
        }
Exemplo n.º 8
0
        public async Task Advice(CommandContext ctx)
        {
            JObject response = await ShimaHttpClient.HttpGet("https://api.adviceslip.com/advice");

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "I've run out of advice ☹️");

                return;
            }
            await CTX.RespondSanitizedAsync(ctx, null, false,
                                            Utils.BaseEmbedBuilder(ctx, null, response["slip"]?["advice"]?.Value <string>(), null,
                                                                   $"#{response["slip"]?["id"]?.Value<string>()}")
                                            .WithTimestamp(null));
        }
Exemplo n.º 9
0
        public async Task FancyInsult(CommandContext ctx)
        {
            JObject response = await ShimaHttpClient.HttpGet($"http://quandyfactory.com/insult/json/");

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "Damned as thou art, thou hast broken the api.");

                return;
            }

            await CTX.RespondSanitizedAsync(ctx, null, false,
                                            Utils.BaseEmbedBuilder(ctx, null as DiscordUser, response["insult"]?.Value <string>())
                                            .WithTimestamp(null)
                                            .WithImageUrl(FunConsts.FancyInsultImage));
        }
Exemplo n.º 10
0
        public async Task DogFact(CommandContext ctx)
        {
            JObject response = await ShimaHttpClient.HttpGet("https://some-random-api.ml/facts/dog");

            JObject image = await ShimaHttpClient.HttpGet("https://random.dog/woof.json?filter=mp4,webm");

            if (response == null || image == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "Doggos are gone ☹️");

                return;
            }
            await CTX.RespondSanitizedAsync(ctx, null, false,
                                            Utils.BaseEmbedBuilder(ctx, null as DiscordUser, response["fact"]?.Value <string>())
                                            .WithTimestamp(null)
                                            .WithImageUrl(image["url"]?.Value <string>()));
        }
Exemplo n.º 11
0
        public async Task CatFact(CommandContext ctx)
        {
            JObject response = await ShimaHttpClient.HttpGet("https://catfact.ninja/fact");

            JObject image = await ShimaHttpClient.HttpGet("http://aws.random.cat/meow");

            if (response == null || image == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "Kitties are gone ☹️");

                return;
            }
            //alternatively https://cataas.com/cat
            await CTX.RespondSanitizedAsync(ctx, null, false,
                                            Utils.BaseEmbedBuilder(ctx, null as DiscordUser, response["fact"]?.Value <string>())
                                            .WithTimestamp(null)
                                            .WithImageUrl(image["file"]?.Value <string>()));
        }
Exemplo n.º 12
0
        public async Task XKCD(CommandContext ctx, [RemainingText] string suffix)
        {
            JObject latestComic = await ShimaHttpClient.HttpGet("https://xkcd.com/info.0.json");

            if (latestComic == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "The comic store is closed today ☹️");

                return;
            }
            int latestN = latestComic["num"].Value <int>();

            int searchN;

            if (string.IsNullOrWhiteSpace(suffix))
            {
                searchN = ThreadSafeRandom.ThisThreadsRandom.Next(0, latestN + 1);
            }
            else if (!int.TryParse(suffix, out searchN) || searchN > latestN)
            {
                await CTX.RespondSanitizedAsync(ctx, $"**{suffix}** is not a valid number between 0 and {latestN}.");

                return;
            }

            JObject response = await ShimaHttpClient.HttpGet($"https://xkcd.com/{searchN}/info.0.json");

            DateTime timestamp = new DateTime(
                response["year"].Value <int>(),
                response["month"].Value <int>(),
                response["day"].Value <int>(), 0, 0, 0, DateTimeKind.Utc);

            await CTX.RespondSanitizedAsync(ctx, null, false,
                                            Utils.BaseEmbedBuilder(ctx, null, response["title"]?.Value <string>(), null, $"{searchN}", timestamp)
                                            .WithUrl($"https://xkcd.com/{searchN}")
                                            .WithImageUrl(response["img"]?.Value <string>())
                                            .WithDescription(response["alt"]?.Value <string>()));
        }
Exemplo n.º 13
0
        public async Task Stroke(CommandContext ctx, [RemainingText] string name)
        {
            string url = "https://api.icndb.com/jokes/random";

            if (!string.IsNullOrWhiteSpace(name))
            {
                var nameArray = name.Split(" ");
                if (nameArray.Length >= 2)
                {
                    url += $"?firstName={nameArray[0]}&lastName={nameArray[1]}";
                }
            }
            JObject response = await ShimaHttpClient.HttpGet(url);

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "Chuck Norris kicked the jokes away 👢");

                return;
            }

            await CTX.RespondSanitizedAsync(ctx, response["value"]?["joke"]?.Value <string>());
        }
Exemplo n.º 14
0
        private async Task <LavalinkLoadResult> GetSpotifyTracks(CommandContext ctx, string spotifyURI)
        {
            var tracks = new List <string>();

            spotifyURI = spotifyURI.Replace("https://open.spotify.com/", "");
            var  type       = spotifyURI.Substring(0, spotifyURI.IndexOf("/"));
            var  id         = spotifyURI.Substring(type.Length + 1);
            bool isPlaylist = type is "playlist";


            if (!isPlaylist && type != "track")
            {
                await CTX.RespondSanitizedAsync(ctx, "Use a spotify playlist or track URL");

                return(null);
            }
            if (string.IsNullOrWhiteSpace(ShimakazeBot.SpotifyToken))
            {
                var tokenResponse = await ShimaHttpClient.HttpPost("https://accounts.spotify.com/api/token",
                                                                   new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(
                                                                                                                                     $"{ShimakazeBot.Config.apiKeys.spotifyClientId}:" +
                                                                                                                                     $"{ShimakazeBot.Config.apiKeys.spotifyClientSecret}"))));

                if (tokenResponse == null)
                {
                    await CTX.RespondSanitizedAsync(ctx, "Spotify authentication failed.");

                    return(null);
                }
                ShimakazeBot.SpotifyToken = tokenResponse["access_token"].Value <string>();
                ShimakazeBot.events.InitializeSpotifyResetTimer(tokenResponse["expires_in"].Value <int>());
            }

            var response = await ShimaHttpClient.HttpGet($"https://api.spotify.com/v1/{type}s/{id}" +
                                                         (isPlaylist ? "/tracks" : ""), new AuthenticationHeaderValue("Bearer", ShimakazeBot.SpotifyToken));

            if (response == null)
            {
                await CTX.RespondSanitizedAsync(ctx, "Bad response from Spotify.");

                return(null);
            }

            if (!isPlaylist)
            {
                tracks.Add($"{response["artists"]?.Children().ToArray()[0]["name"].Value<string>()}" +
                           $" - {response["name"].Value<string>()}");
            }
            else
            {
                response["tracks"]?["items"]?.Children().ToList().ForEach(item =>
                {
                    tracks.Add($"{item["track"]?["artists"]?.Children().ToArray()[0]["name"].Value<string>()}" +
                               $" - {item["track"]?["name"].Value<string>()}");
                });
            }

            var result = new SpotifyLoadResult();

            result.Tracks = new List <LavalinkTrack>();
            bool firstLoaded = false;

            foreach (var track in tracks)
            {
                var trackResult = await ShimakazeBot.lvn.Rest.GetTracksAsync(track);

                if (trackResult.LoadResultType != LavalinkLoadResultType.NoMatches &&
                    trackResult.LoadResultType != LavalinkLoadResultType.LoadFailed)
                {
                    if (!firstLoaded)
                    {
                        await Play(ctx, track);

                        firstLoaded = true;
                    }
                    else
                    {
                        result.Tracks.Add(trackResult.Tracks.First());
                    }
                }
            }
            result.LoadResultType = firstLoaded ?
                                    LavalinkLoadResultType.PlaylistLoaded : LavalinkLoadResultType.NoMatches;

            return((LavalinkLoadResult)result);
        }