Exemple #1
0
        public async Task SearchAsync(CommandContext ctx,
                                      [RemainingText, Description("desc-query")] string query)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                throw new InvalidCommandUsageException(ctx, "cmd-err-query");
            }

            WikiSearchResponse?res = await WikiService.SearchAsync(query);

            if (res is null || !res.Any())
            {
                await ctx.FailAsync("cmd-err-res-none");

                return;
            }

            await ctx.PaginateAsync(res, (emb, r) => {
                emb.WithTitle(r.Title);
                emb.WithDescription(r.Snippet);
                emb.WithUrl(r.Url);
                emb.WithLocalizedFooter("fmt-powered-by", WikiService.WikipediaIconUrl, "Wikipedia API");
                return(emb);
            }, this.ModuleColor);
        }
Exemple #2
0
        public async Task SearchAsync(CommandContext ctx,
                                      [RemainingText, Description("Query.")] string query)
        {
            var res = await WikiService.SearchAsync(query);

            if (res is null || !res.Any())
            {
                await this.InformOfFailureAsync(ctx, "No results...");

                return;
            }

            await ctx.Client.GetInteractivity().SendPaginatedMessageAsync(ctx.Channel, ctx.User, res.Select(r
                                                                                                            => new Page(embed: new DiscordEmbedBuilder
            {
                Title       = r.Title,
                Description = string.IsNullOrWhiteSpace(r.Snippet) ? "No description provided" : r.Snippet,
                Url         = r.Url,
                Color       = this.ModuleColor
            }.WithFooter("Powered by Wikipedia API", WikiService.WikipediaIconUrl))));
        }