示例#1
0
        public async Task QueryWikiAsync(CommandContext ctx, [RemainingText] string pageTitle)
        {
            if (string.IsNullOrEmpty(pageTitle))
            {
                await ctx.Channel.SendMessageAsync("Correct, we have a wiki.");

                return;
            }

            // Base embed
            DiscordEmbedBuilder wikiEmbed = new DiscordEmbedBuilder
            {
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    IconUrl = DiscordEmoji.FromGuildEmote(ctx.Client, PlatformEmojis.Wiki).Url,
                    Text    = "Superbossgames Wiki",
                },
                Color     = new DiscordColor(217, 187, 19),
                Timestamp = DateTime.UtcNow,
            };

            WikiArticle article = await this.wikiService.GetArticleAsync(pageTitle);

            // Found a matching article
            if (article != null)
            {
                wikiEmbed.Footer.Text += $" | Last Edited: {article.Timestamp}";
                wikiEmbed.Title        = article.Title;
                wikiEmbed.Description  = article.Body;
                wikiEmbed.Url          = article.Url.ToString();
                await ctx.Channel.SendMessageAsync(string.Empty, embed : wikiEmbed.Build());

                return;
            }

            // No exact match, find page titles containing the passed title
            List <string> suggestedPages = await this.wikiService.GetSuggestedPagesAsync(pageTitle);

            // Show what we found
            if (suggestedPages.Count > 0)
            {
                wikiEmbed.Title       = "No exact match";
                wikiEmbed.Description = $"Are you looking for any of the following pages:\n"
                                        + $"- {string.Join("\n- ", suggestedPages.Select(x => $"[{x}]({WikiUtils.GetUrlFromTitle(x)})"))}";
            }

            // No match, no suggestions, nothing
            else
            {
                wikiEmbed.Title       = "Nothing found";
                wikiEmbed.Description = @"¯\_(ツ)_/¯";
            }

            await ctx.Channel.SendMessageAsync(embed : wikiEmbed.Build());
        }
示例#2
0
文件: WikiJob.cs 项目: BloonBot/Bloon
        public async Task Execute()
        {
            Log.Information("Checking Wiki for new posts..");

            WikiArticle article = await this.wikiService.GetLatestAsync();

            // Unable to fetch the latest post from the wiki
            if (article == null)
            {
                //this.bloonLog.Error($"Something went wrong fetching the latest wiki article! Check Log File");
                return;
            }
            else if (!await this.wikiService.TryStoreNewAsync(article))
            {
                Log.Information("Finished Wiki checks early");
                return;
            }

            DiscordChannel sbgGen = await this.dClient.GetChannelAsync(SBGChannels.General);

            DiscordChannel sbgWiki = await this.dClient.GetChannelAsync(SBGChannels.Wiki);

            DiscordEmbed wikiEmbed = new DiscordEmbedBuilder
            {
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    IconUrl = DiscordEmoji.FromGuildEmote(this.dClient, PlatformEmojis.Wiki).Url,
                    Text    = $"Superbossgames Wiki | Bytes Changed: {(article.ByteDifference > 0 ? "+" : string.Empty)}{article.ByteDifference}",
                },
                Color       = new DiscordColor(217, 187, 19),
                Timestamp   = article.Timestamp,
                Description = $"Recent Wiki Change by {article.Author} to [{article.Title}]({WikiUtils.GetUrlFromTitle(article.Title)})",
            };

            await sbgWiki.SendMessageAsync(embed : wikiEmbed);

            await sbgGen.SendMessageAsync(embed : wikiEmbed);

            Log.Information("Finished Wiki Scraping");
        }