示例#1
0
        public async Task Tf2News(CommandContext ctx,
                                  [Description("Page number from which to retrieve the news")]
                                  int query = 0)
        {
            await ctx.TriggerTypingAsync();

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

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

                return;
            }

            while (results.Count > 0)
            {
                var output = new DiscordEmbedBuilder()
                             .WithColor(new DiscordColor("#E7B53B"))
                             .WithFooter(results.Count - 5 >= 5
                        ? "Type 'next' within 10 seconds for the next five posts."
                        : "These are all the latest posts at this time.");

                foreach (var result in results.Take(5))
                {
                    output.AddField(result.CreatedAt.Date.ToString(),
                                    $"{result.Provider ?? result.Type}: [{result.Title}]({result.Link.AbsoluteUri})");
                    results.Remove(result);
                }

                var message = await ctx.RespondAsync("Latest news articles from teamwork.tf", output)
                              .ConfigureAwait(false);

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

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

                await BotServices.RemoveMessage(message).ConfigureAwait(false);
            }
        }
示例#2
0
 public void GetNewsOverview()
 {
     Assert.IsNotNull(TeamFortressService.GetNewsArticlesAsync(TestSetup.Tokens.TeamworkToken).Result);
 }