Exemple #1
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);
                }
            }
        }