Skip to content

Commit

Permalink
Improve source command
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwilarg committed Sep 19, 2024
1 parent c3411aa commit 68b0ae7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sanara/Module/Utility/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ public static async Task<Embed> GetSourceAsync(IServiceProvider provider, string
{
var web = provider.GetRequiredService<HtmlWeb>();
var html = web.Load("https://saucenao.com/search.php?url=" + Uri.EscapeDataString(paramUrl));
var answers = html.DocumentNode.SelectNodes("//div[contains(@class, 'result')]");
if (!answers.Any())
var answer = html.DocumentNode.SelectSingleNode("//div[contains(@class, 'result')]");
if (answer == null)
throw new CommandFailed("I didn't find the source of this image.");

var answer = answers[0];
var url = html.GetElementbyId("resImage0").Attributes["src"].Value;
var compatibility = answer.SelectSingleNode("//div[contains(@class, 'resultsimilarityinfo')]").InnerHtml;
var content = answer.SelectSingleNode("//div[contains(@class, 'resultcontentcolumn')]").InnerHtml;

var link = answer.SelectSingleNode("//div[contains(@class, 'resultcontentcolumn')]").SelectSingleNode("a");
var linkUrl = link == null ? null : link.Attributes["href"].Value;

return new EmbedBuilder
{
Title = "Closest match",
Url = linkUrl,
ImageUrl = url,
Description = Utils.CleanHtml(content),
Color = Color.Blue,
Expand Down

0 comments on commit 68b0ae7

Please sign in to comment.