Esempio n. 1
0
        public async Task News(CommandContext ctx,
                               [Description("Article topic to find on Google News")][RemainingText] string query)
        {
            var results = await GoogleService.GetNewsDataAsync(query).ConfigureAwait(false);

            if (results.Status != "ok")
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                while (results.Articles.Count > 0)
                {
                    var output = new DiscordEmbedBuilder()
                                 .WithFooter("Type 'next' within 10 seconds for the next five articles.")
                                 .WithColor(new DiscordColor("#253B80"));

                    foreach (var result in results.Articles.Take(5))
                    {
                        output.AddField(result.Title, result.Url);
                        results.Articles.Remove(result);
                    }
                    var message = await ctx.RespondAsync("Latest Google News articles from News API", embed : output.Build()).ConfigureAwait(false);

                    if (results.Articles.Count == 5)
                    {
                        continue;
                    }
                    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);
                }
            }
        }
Esempio n. 2
0
 public void GetNewsData()
 {
     Assert.IsTrue(GoogleService.GetNewsDataAsync().Result.Status == "ok");
     Assert.IsTrue(GoogleService.GetNewsDataAsync("Nintendo").Result.Status == "ok");
 }