public async Task google([Remainder] string keywords) { Search searchResults = GoogleService.Search(keywords).Result; var eb = new EmbedBuilder(); if (searchResults.Items.Count < 1) { eb.WithTitle("Google Search"); eb.WithColor(Color.Red); eb.WithDescription("No results were found."); } else { eb.WithTitle("Google Search"); eb.WithColor(Color.Green); string description = ""; foreach (Result result in searchResults.Items) { string formattedResult = ConvertSearchToMessage(result); if ((description + formattedResult).Length <= 2048) { description += formattedResult; } } eb.WithDescription(description); } await Context.Channel.SendMessageAsync(embed : eb.Build()); }
public async Task GoogleSearchService_Get_SearchResultUrlPosition() { // Arrange SearchRequest request = new SearchRequest(); request.SearchUrl = "Sympli.com.au"; request.Search = "e-settlement"; // Act var response = await _googleService.Search(request); // Assert Assert.That(response, Is.Not.Null); Assert.AreEqual("0", response); }
public void TestMultipleTermsCase() { GoogleService service = new GoogleService(); string searchCriteria = "microsoft office"; SearchEngineQuery result; try { result = service.Search(searchCriteria).GetAwaiter().GetResult(); Assert.IsTrue(result != null && result.TotalResults > 0); } catch (Exception) { Assert.Fail("Exception was thrown"); } }
public void TestEmptyCriteriaCase() { GoogleService service = new GoogleService(); string searchCriteria = " "; SearchEngineQuery result; try { result = service.Search(searchCriteria).GetAwaiter().GetResult(); } catch (Exception ex) { StringAssert.Contains(ex.Message, "Search criteria is empty or null"); return; } Assert.Fail("Exception was not thrown"); }
private async Task GSearch(string search, ISocketMessageChannel channel, int maxResults = 10) { EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle($"Google Search '{search}'"); embed.WithDescription("Searching Google..."); embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); embed.WithColor(FunCmdsConfig.googleColor); embed.WithCurrentTimestamp(); RestUserMessage message = await channel.SendMessageAsync("", false, embed.Build()); Search searchListResponse = GoogleService.Search(search, GetType().ToString()); StringBuilder description = new StringBuilder(); int currentResult = 0; foreach (Result result in searchListResponse.Items) { if (currentResult == maxResults) { continue; } string link = $"**[{result.Title}]({result.Link})**\n{result.Snippet}\n\n"; if (description.Length >= 2048) { continue; } if (description.Length + link.Length >= 2048) { continue; } description.Append(link); currentResult += 1; } embed.WithDescription(description.ToString()); embed.WithCurrentTimestamp(); await MessageUtils.ModifyMessage(message, embed); }
public async Task googleimage([Remainder] string keywords) { Search searchResults = GoogleService.Search(keywords, true).Result; var eb = new EmbedBuilder(); if (searchResults.Items.Count < 1) { eb.WithTitle("Google Search"); eb.WithColor(Color.Red); eb.WithDescription("No results were found."); } else { eb.WithTitle("Google Search"); eb.WithColor(Color.Green); Result result = searchResults.Items[0]; eb.WithImageUrl(result.Link); } await Context.Channel.SendMessageAsync(embed : eb.Build()); }