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); } }
public async Task Wikipedia(CommandContext ctx, [Description("Articles to find on Wikipedia.")][RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) { return; } await ctx.TriggerTypingAsync(); var results = WikipediaService.GetWikipediaDataAsync(query); if (results.Error != null || results.Search?.Count == 0) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_WIKIPEDIA, ResponseType.Missing) .ConfigureAwait(false); return; } if (results.Search?.Count <= 1) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) .ConfigureAwait(false); return; } while (results.Search?.Count > 0) { var output = new DiscordEmbedBuilder() .WithColor(new DiscordColor("#6B6B6B")) .WithFooter(results.Search.Count - 5 >= 5 ? "Type 'next' within 10 seconds for the next five articles." : "There articles are retrieved using WikipediaNET."); foreach (var result in results.Search.Take(5)) { var desc = Regex.Replace( result.Snippet.Length <= 300 ? string.IsNullOrEmpty(result.Snippet) ? "Article has not content." : result.Snippet : result.Snippet[..150] + "...", "<[^>]*>", "");
public void GetWikipediaPage() { Assert.IsFalse(WikipediaService.GetWikipediaDataAsync("Russia").Result.Missing); }
public void GetWikipediaPage() { Assert.IsNull(WikipediaService.GetWikipediaDataAsync("Russia").Error); }