Exemplo n.º 1
0
        public async Task Tf2Map(CommandContext ctx,
                                 [Description("Normalized map name, like pl_upward")]
                                 string query)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                return;
            }
            await ctx.TriggerTypingAsync();

            var results = await TeamFortressService
                          .GetMapStatsAsync(Program.Settings.Tokens.TeamworkToken, query.ToLowerInvariant())
                          .ConfigureAwait(false);

            if (results is null)
            {
                await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing)
                .ConfigureAwait(false);

                return;
            }

            _ = double.TryParse(results.AllTimeAvgPlayers, out var avgPlayers);
            var output = new DiscordEmbedBuilder()
                         .WithTitle(results.MapName)
                         .AddField("Highest Server Count", results.HighestServers.ToString() ?? "Unknown", true)
                         .AddField("Highest Player Count", results.HighestPlayers.ToString() ?? "Unknown", true)
                         .AddField("Avg. Players", Math.Round(avgPlayers, 2).ToString(CultureInfo.InvariantCulture) ?? "Unknown",
                                   true)
                         .WithFooter("Statistics retrieved from teamwork.tf - refreshed every 5 minutes")
                         .WithImageUrl(results.Thumbnail)
                         .WithUrl(string.Format(Resources.URL_TF2Wiki, results.MapName))
                         .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);
            }

            if (results.ExtraInfo != null)
            {
                var links = new StringBuilder();
                if (results.ExtraInfo.SteamWorkshopUrl != null)
                {
                    links.Append($"[Steam Workshop]({results.ExtraInfo.SteamWorkshopUrl}) **|**");
                }
                if (results.ExtraInfo.Tf2MapsUrl != null)
                {
                    links.Append($"[TF2Maps]({results.ExtraInfo.Tf2MapsUrl}) **|**");
                }
                if (results.ExtraInfo.GameBananaUrl != null)
                {
                    links.Append($"[GameBanana]({results.ExtraInfo.GameBananaUrl}");
                }
                output.AddField("Links", links.ToString(), true);
            }

            if (results.GameModes.Count > 0)
            {
                var desc = TeamFortressService.GetGameModeInfoAsync(Program.Settings.Tokens.TeamworkToken,
                                                                    results.GameModes.FirstOrDefault()).Result;
                output.WithDescription(desc.Title + " - " + desc.Description);
                output.WithColor(new DiscordColor($"#{desc.Color}"));
            }

            await ctx.RespondAsync(output.Build()).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task Tf2Creators(CommandContext ctx,
                                      [Description("Name of the community creator to find.")][RemainingText]
                                      string query)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                return;
            }
            await ctx.TriggerTypingAsync();

            var steamId = SteamService.GetSteamUserId(query).Result;

            if (steamId is null)
            {
                await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing)
                .ConfigureAwait(false);

                return;
            }

            var results = await TeamFortressService
                          .GetContentCreatorAsync(Program.Settings.Tokens.TeamworkToken, steamId.Data).ConfigureAwait(false);

            if (results.Count == 0)
            {
                await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing)
                .ConfigureAwait(false);

                return;
            }

            foreach (var creator in results)
            {
                var user   = results.FirstOrDefault();
                var output = new DiscordEmbedBuilder()
                             .WithTitle(user?.Name)
                             .WithDescription("Main Class: " + user?.Main?.ToString()?.ToUpper())
                             .WithThumbnail(user?.ThumbnailUrl)
                             .WithUrl(user?.Link)
                             .WithColor(new DiscordColor("#E7B53B"))
                             .WithFooter(!creator.Equals(results.Last())
                        ? "Type 'next' within 10 seconds for the next creator"
                        : "Data retrieved from teamwork.tf");

                var links = new StringBuilder();
                if (creator.DiscordGroup != null)
                {
                    links.Append($"[Discord]({Resources.URL_Discord}{creator.DiscordGroup}) **|** ");
                }
                if (!string.IsNullOrWhiteSpace(creator.Steam))
                {
                    links.Append($"[Steam]({Resources.URL_Steam_User}{creator.Steam}) **|** ");
                }
                if (creator.SteamGroup != null)
                {
                    links.Append($"[Steam Group]({Resources.URL_Steam_Group}{creator.SteamGroup}) **|** ");
                }
                if (creator.Twitch != null)
                {
                    links.Append($"[Twitch]({Resources.URL_Twitch}{creator.Twitch}) **|** ");
                }
                if (!string.IsNullOrWhiteSpace(creator.Twitter))
                {
                    links.Append($"[Twitter]({Resources.URL_Twitter}{creator.Twitter}) **|** ");
                }
                if (!string.IsNullOrWhiteSpace(creator.Youtube))
                {
                    links.Append($"[YouTube]({string.Format(Resources.URL_YouTube_Channel, creator.Youtube)})");
                }
                output.AddField("Links", links.ToString(), true);
                var message = await ctx.RespondAsync(output.Build()).ConfigureAwait(false);

                if (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 (!creator.Equals(results.Last()))
                {
                    await BotServices.RemoveMessage(message).ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 3
0
        public async Task Tf2ServerByMode(CommandContext ctx,
                                          [Description("Name of the game-mode, like payload.")][RemainingText]
                                          string query)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                return;
            }
            await ctx.TriggerTypingAsync();

            var results = await TeamFortressService
                          .GetServersByGameModeAsync(Program.Settings.Tokens.TeamworkToken, query.Trim().Replace(' ', '-'))
                          .ConfigureAwait(false);

            if (results is null)
            {
                await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing)
                .ConfigureAwait(false);

                return;
            }

            foreach (var server in results.OrderBy(_ => new Random().Next()).ToList())
            {
                var output = new DiscordEmbedBuilder()
                             .WithTitle(server.Name)
                             .WithDescription("steam://connect/" + server.Ip + ":" + server.Port)
                             .AddField("Provider", server.Provider != null ? server.Provider.Name : "Unknown", true)
                             .AddField("Player Count",
                                       (server.Players.ToString() ?? "Unknown") + "/" + (server.MaxPlayers.ToString() ?? "Unknown"),
                                       true)
                             .AddField("Password Lock", server.HasPassword ? "Yes" : "No", true)
                             .AddField("Random Crits", server.HasRandomCrits == true ? "Yes" : "No", true)
                             .AddField("Instant Respawn", server.HasNoRespawnTime ? "Yes" : "No", true)
                             .AddField("All Talk", server.HasAllTalk ? "Yes" : "No", true)
                             .AddField("Current Map", server.MapName ?? "Unknown", true)
                             .AddField("Next Map", server.MapNameNext ?? "Unknown", true)
                             .WithFooter("Type 'next' within 10 seconds for the next server.")
                             .WithColor(new DiscordColor("#E7B53B"));

                var thumbnailUrl = await TeamFortressService
                                   .GetMapThumbnailAsync(Program.Settings.Tokens.TeamworkToken, server.MapName).ConfigureAwait(false);

                output.WithImageUrl(thumbnailUrl.Name);

                var message = await ctx.RespondAsync(output.Build()).ConfigureAwait(false);

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

                if (interactivity.Result is null)
                {
                    break;
                }
                if (!server.Equals(results.Last()))
                {
                    await BotServices.RemoveMessage(message).ConfigureAwait(false);
                }
                await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false);
            }
        }
Exemplo n.º 4
0
        public async Task Omdb(CommandContext ctx,
                               [Description("Movie or TV show to find on OMDB.")][RemainingText]
                               string query)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                return;
            }
            await ctx.TriggerTypingAsync();

            var results = OmdbService.GetMovieListAsync(Program.Settings.Tokens.OmdbToken, query.Replace(" ", "+"))
                          .Result;

            if (!results.Search.Any())
            {
                await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing)
                .ConfigureAwait(false);

                return;
            }

            foreach (var title in results.Search)
            {
                var movie = OmdbService
                            .GetMovieDataAsync(Program.Settings.Tokens.OmdbToken, title.Title.Replace(" ", "+")).Result;
                var output = new DiscordEmbedBuilder()
                             .WithTitle(movie.Title)
                             .WithDescription(movie.Plot.Length < 500 ? movie.Plot : movie.Plot.Take(500) + "...")
                             .AddField("Released", movie.Released, true)
                             .AddField("Runtime", movie.Runtime, true)
                             .AddField("Genre", movie.Genre, true)
                             .AddField("Rating", movie.Rated, true)
                             .AddField("IMDb Rating", movie.IMDbRating, true)
                             .AddField("Box Office", movie.BoxOffice, true)
                             .AddField("Directors", movie.Director)
                             .AddField("Actors", movie.Actors)
                             .WithFooter(!movie.Title.Equals(results.Search.Last().Title)
                        ? "Type 'next' within 10 seconds for the next movie."
                        : "This is the last found movie on OMDB.")
                             .WithColor(DiscordColor.Goldenrod);
                if (movie.Poster != "N/A")
                {
                    output.WithImageUrl(movie.Poster);
                }
                var message = await ctx.RespondAsync(output.Build()).ConfigureAwait(false);

                if (results.Search.Length == 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 (!movie.Title.Equals(results.Search.Last().Title))
                {
                    await BotServices.RemoveMessage(message).ConfigureAwait(false);
                }
            }
        }