Esempio n. 1
0
        public async Task Twitch(CommandContext ctx,
                                 [Description("Channel to find on Twitch")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = await TwitchService.GetTwitchDataAsync(query).ConfigureAwait(false);

            if (results.Stream.Count == 0)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_TWITCH, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                var stream = results.Stream[0];
                var output = new DiscordEmbedBuilder()
                             .WithTitle(stream.UserName + " is live on Twitch!")
                             .WithDescription(stream.Title)
                             .AddField("Start Time:", stream.StartTime, true)
                             .AddField("View Count:", stream.ViewCount.ToString(), true)
                             .WithImageUrl(stream.ThumbnailUrl.Replace("{width}", "500").Replace("{height}", "300"))
                             .WithUrl("https://www.twitch.tv/" + stream.UserName)
                             .WithColor(new DiscordColor("#6441A5"));
                await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);
            }
        }
Esempio n. 2
0
        public async Task Poll(CommandContext ctx,
                               [Description("Question to be polled")][RemainingText] string question)
        {
            if (!BotServices.CheckUserInput(question))
            {
                await BotServices.SendEmbedAsync(ctx, Resources.ERR_POLL_QUESTION, EmbedType.Warning).ConfigureAwait(false);
            }
            else
            {
                var interactivity = ctx.Client.GetInteractivity();
                var pollOptions   = new List <DiscordEmoji>();
                pollOptions.Add(DiscordEmoji.FromName(ctx.Client, ":thumbsup:"));
                pollOptions.Add(DiscordEmoji.FromName(ctx.Client, ":thumbsdown:"));
                var duration = new TimeSpan(0, 0, 3, 0, 0);
                var output   = new DiscordEmbedBuilder().WithDescription(ctx.User.Mention + "asked: " + question + "\nThis poll ends in 3 minutes.");
                var message  = await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);

                foreach (var react in pollOptions)
                {
                    await message.CreateReactionAsync(react).ConfigureAwait(false);
                }
                var pollResult = await interactivity.CollectReactionsAsync(message, duration).ConfigureAwait(false);

                var results = pollResult.Where(x => pollOptions.Contains(x.Emoji)).Select(x => $"{x.Emoji} wins the poll with **{x.Total}** votes");
                await ctx.RespondAsync(string.Join("\n", results)).ConfigureAwait(false);
            }
        }
Esempio n. 3
0
        public async Task Weather(CommandContext ctx,
                                  [Description("Location to retrieve weather data from")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = await GoogleService.GetWeatherDataAsync(query).ConfigureAwait(false);

            if (results.COD == 404)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_LOCATION, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                Func <double, double> format = GoogleService.CelsiusToFahrenheit;
                var output = new DiscordEmbedBuilder()
                             .WithTitle(":partly_sunny: Current weather in " + results.Name + ", " + results.Sys.Country)
                             .AddField("Temperature", $"{results.Main.Temperature:F1}°C / {format(results.Main.Temperature):F1}°F", true)
                             .AddField("Humidity", $"{results.Main.Humidity}%", true)
                             .AddField("Wind Speed", $"{results.Wind.Speed}m/s", true)
                             .WithUrl("https://openweathermap.org/city/" + results.ID)
                             .WithColor(SharedData.DefaultColor);
                await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);
            }
        }
Esempio n. 4
0
 private async Task RedditPost(CommandContext ctx, string query, RedditCategory category)
 {
     if (!BotServices.CheckUserInput(query))
     {
         return;
     }
     var results = RedditService.GetEmbeddedResults(query, category);
     await ctx.RespondAsync("Search results for r/" + query, embed : results).ConfigureAwait(false);
 }
Esempio n. 5
0
        public async Task YouTubeSearch(CommandContext ctx,
                                        [Description("Video to find on YouTube")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var service = new YoutubeService();
            var results = await service.GetEmbeddedResults(query, 5, "video").ConfigureAwait(false);

            await ctx.RespondAsync("Search results for " + Formatter.Bold(query), embed : results).ConfigureAwait(false);
        }
Esempio n. 6
0
        public async Task YouTubeVideo(CommandContext ctx,
                                       [Description("First result video to find on YouTube")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var service = new YoutubeService();
            var results = await service.GetFirstVideoResultAsync(query).ConfigureAwait(false);

            await ctx.RespondAsync(results).ConfigureAwait(false);
        }
        public async Task Speedrun(CommandContext ctx,
                                   [Description("Game to search on Speedrun.com")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = SpeedrunService.GetSpeedrunGameAsync(query).Result.Data;

            if (results is null || results.Count == 0)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
Esempio n. 8
0
        public async Task SteamUser(CommandContext ctx,
                                    [Description("User to find on Steam")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var profile = SteamService.GetSteamProfileAsync(query).Result;
            var summary = SteamService.GetSteamSummaryAsync(query).Result;

            if (profile is null && summary is null)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
Esempio n. 9
0
        public async Task GetAmiibo(CommandContext ctx,
                                    [Description("Name of the Amiibo figurine")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = await AmiiboService.GetAmiiboDataAsync(query).ConfigureAwait(false);

            if (results is null)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                foreach (var amiibo in results.Amiibo)
                {
                    var output = new DiscordEmbedBuilder()
                                 .WithTitle(amiibo.Name)
                                 .AddField("Amiibo Series", amiibo.AmiiboSeries, true)
                                 .AddField("Game Series", amiibo.GameSeries, true)
                                 .AddField(":flag_us: Release:", amiibo.ReleaseDate.American, true)
                                 .AddField(":flag_jp: Release:", amiibo.ReleaseDate.Japanese, true)
                                 .AddField(":flag_eu: Release:", amiibo.ReleaseDate.European, true)
                                 .AddField(":flag_au: Release:", amiibo.ReleaseDate.Australian, true)
                                 .WithImageUrl(amiibo.Image)
                                 .WithFooter(!amiibo.Equals(results.Amiibo.Last()) ? "Type 'next' within 10 seconds for the next amiibo" : "This is the last found amiibo on the list.")
                                 .WithColor(new DiscordColor("#E70009"));
                    var message = await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);

                    if (results.Amiibo.Count == 1)
                    {
                        continue;
                    }
                    var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false);

                    if (interactivity.Result is null)
                    {
                        break;
                    }
                    await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false);

                    if (!amiibo.Equals(results.Amiibo.Last()))
                    {
                        await BotServices.RemoveMessage(message).ConfigureAwait(false);
                    }
                }
            }
        }
        public async Task UrbanDictionary(CommandContext ctx,
                                          [Description("Query to pass to Urban Dictionary")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = await DictionaryService.GetDictionaryDefinitionAsync(query).ConfigureAwait(false);

            if (results.ResultType == "no_results" || results.List.Count == 0)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                foreach (var definition in results.List)
                {
                    var output = new DiscordEmbedBuilder()
                                 .WithTitle("Urban Dictionary definition for " + Formatter.Bold(query))
                                 .WithDescription(!string.IsNullOrWhiteSpace(definition.Author) ? "Submitted by: " + definition.Author : string.Empty)
                                 .AddField("Definition", definition.Definition.Length < 500 ? definition.Definition : definition.Definition.Take(500) + "...")
                                 .AddField("Example", definition.Example ?? "None")
                                 .AddField(":thumbsup:", definition.ThumbsUp.ToString(), true)
                                 .AddField(":thumbsdown:", definition.ThumbsDown.ToString(), true)
                                 .WithUrl(definition.Permalink)
                                 .WithFooter(!definition.Equals(results.List.Last()) ? "Type 'next' within 10 seconds for the next definition" : "This is the last found definition on the list.")
                                 .WithColor(new DiscordColor("#1F2439"));
                    var message = await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);

                    if (results.List.Count == 1)
                    {
                        continue;
                    }
                    var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false);

                    if (interactivity.Result is null)
                    {
                        break;
                    }
                    await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false);

                    if (!definition.Equals(results.List.Last()))
                    {
                        await BotServices.RemoveMessage(message).ConfigureAwait(false);
                    }
                }
            }
        }
        public async Task Books(CommandContext ctx,
                                [Description("Book title to find on GoodReads")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = GoodReadsService.GetBookDataAsync(query).Result.Search;

            if (results.ResultCount <= 0)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                foreach (var book in results.Results)
                {
                    // TODO: Add page count, publication, ISBN, URLs
                    var output = new DiscordEmbedBuilder()
                                 .WithTitle(book.Book.Title)
                                 .AddField("Written by", book.Book.Author.Name ?? "Unknown", true)
                                 .AddField("Publication Date", (book.PublicationMonth.Text ?? "01") + "-" + (book.PublicationDay.Text ?? "01") + "-" + book.PublicationYear.Text, true)
                                 .AddField("Avg. Rating", book.RatingAverage ?? "Unknown", true)
                                 .WithThumbnailUrl(book.Book.ImageUrl ?? book.Book.ImageUrlSmall)
                                 .WithFooter(!book.Equals(results.Results.Last()) ? "Type 'next' within 10 seconds for the next book." : "This is the last found book on the list.")
                                 .WithColor(new DiscordColor("#372213"));
                    var message = await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);

                    if (results.Results.Count == 1)
                    {
                        continue;
                    }
                    var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false);

                    if (interactivity.Result is null)
                    {
                        break;
                    }
                    await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false);

                    if (!book.Equals(results.Results.Last()))
                    {
                        await BotServices.RemoveMessage(message).ConfigureAwait(false);
                    }
                }
            }
        }
        public async Task Wikipedia(CommandContext ctx,
                                    [Description("Query to search on Wikipedia")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = WikipediaService.GetWikipediaDataAsync(query).Result;

            if (results.Missing)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_WIKIPEDIA, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                await ctx.Channel.SendMessageAsync(results.FullUrl).ConfigureAwait(false);
            }
        }
Esempio n. 13
0
        public async Task TF2Map(CommandContext ctx,
                                 [Description("Normalized map name, like pl_upward")] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = await TeamFortressService.GetMapStatsAsync(query.ToLowerInvariant()).ConfigureAwait(false);

            if (results.Name is null)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                double.TryParse(results.AvgPlayers, out var avg_players);
                var output = new DiscordEmbedBuilder()
                             .WithTitle(results.Name)
                             .AddField("Official", results.OfficialMap ? "Yes" : "No", true)
                             .AddField("Game Mode", results.GameModes[0] ?? "Unknown", true)
                             .AddField("Highest Server Count", results.HighestServerCount.ToString() ?? "Unknown", true)
                             .AddField("Highest Player Count", results.HighestPlayerCount.ToString() ?? "Unknown", true)
                             .AddField("Avg. Players", Math.Round(avg_players, 2).ToString() ?? "Unknown", true)
                             .WithFooter("Statistics retrieved from teamwork.tf - refreshed every 5 minutes")
                             .WithImageUrl(results.Thumbnail)
                             .WithUrl("https://wiki.teamfortress.com/wiki/" + results.Name)
                             .WithColor(new DiscordColor("#E7B53B"));

                if (results.RelatedMaps.Count > 0)
                {
                    var maps = new StringBuilder();
                    foreach (var map in results.RelatedMaps.Take(4))
                    {
                        maps.Append(map + "\n");
                    }
                    output.AddField("Related Map(s)", maps.ToString(), true);
                }
                await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);
            }
        }
Esempio n. 14
0
        public async Task GetTime(CommandContext ctx,
                                  [Description("Location to retrieve time data from")][RemainingText] string location)
        {
            if (!BotServices.CheckUserInput(location))
            {
                return;
            }
            var results = GoogleService.GetTimeDataAsync(location).Result;

            if (results.status != "OK")
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                var output = new DiscordEmbedBuilder()
                             .WithTitle(":clock1: Current time in " + results.Results[0].FormattedAddress)
                             .WithDescription(Formatter.Bold(results.Time.ToShortTimeString()) + " " + results.Timezone.timeZoneName)
                             .WithColor(SharedData.DefaultColor);
                await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);
            }
        }