Skip to content

Commit

Permalink
Sort sauces by similarity
Browse files Browse the repository at this point in the history
  • Loading branch information
RealKC committed Feb 16, 2021
1 parent 793b126 commit cf245f4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/commands/sauce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ pub async fn sauce(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let sauce = saucenao.check_sauce(url.as_str()).await;

match sauce {
Ok(sauce) => {
Ok(mut sauce) => {
sauce.items.sort_by(|s1, s2| {
s1.partial_cmp(s2)
.expect("Saucenao gave us NaN similarities")
});

if sauce.items[0].similarity > 50.0 {
msg.react(ctx, ReactionType::Unicode("✅".into())).await?;
} else {
Expand All @@ -62,10 +67,7 @@ pub async fn sauce(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
info!("URL?: {}", sauce.original_url);

let mut contents = String::with_capacity(2000);
contents.push_str(&format!(
"Possible sauces for <{url}>:\n",
url = &url
));
contents.push_str(&format!("Possible sauces for <{url}>:\n", url = &url));
for i in 0..min(5, sauce.items.len()) {
contents.push_str(&format!(
"* {similarity}% similar: <{url}>\n",
Expand Down

0 comments on commit cf245f4

Please sign in to comment.