Beispiel #1
0
        public async Task GoogleAsyc([Remainder] string searchQuery)
        {
            //checks if the search fails the censor
            if (censor.CensorText(searchQuery))
            {
                //if so it sends an embed explaining the why the request failed
                EmbedBuilder builder = new EmbedBuilder()
                {
                    Author       = new EmbedAuthorBuilder().WithName("Error"),
                    Title        = "Your request could not be completed",
                    Description  = Context.Message.Author.Mention + " Your request most likely contained profanity and therefore was not completed.  Please refined your request so that it does not contain profanity.  Your original request has been removed.",
                    ThumbnailUrl = "https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678069-sign-error-512.png",
                    Color        = Color.DarkRed
                };


                await ReplyAsync(embed : builder.Build());

                //deletes orignal request
                await Context.Message.DeleteAsync();
            }
            //if it passes the censor complete the search
            else
            {
                GoogleResults searchResults = await searchService.SearchAsync(searchQuery);

                //the following code is responsible for bulding the embed and sending it
                EmbedAuthorBuilder EAB = new EmbedAuthorBuilder()
                {
                    Name = "Main Result:"
                };

                EmbedBuilder embedBuilder = new EmbedBuilder()
                {
                    Author       = EAB,
                    Title        = searchResults.Items[0].Title,
                    Url          = searchResults.Items[0].Link,
                    ThumbnailUrl = searchResults.Items[0].PageMap.CseThumbnail[0].Src,
                    Color        = new Color?(new Color(66, 133, 244)),
                    Footer       = new EmbedFooterBuilder().WithText("Search Requested").WithIconUrl("https://cdn4.iconfinder.com/data/icons/new-google-logo-2015/400/new-google-favicon-512.png")
                }
                .AddField("Result 2", "[" + searchResults.Items[1].Title + "](" + searchResults.Items[1].Link + ")", false)
                .AddField("Result 3", "[" + searchResults.Items[2].Title + "](" + searchResults.Items[2].Link + ")", false)
                .WithCurrentTimestamp();
                await ReplyAsync(embed: embedBuilder.Build());
            }
        }