From 7047bc0cb9848a172b76a39eb3b10749e7936b3f Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 7 Apr 2024 01:24:29 -0400 Subject: [PATCH] Fix exact results --- commands/search/lorcana.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/commands/search/lorcana.js b/commands/search/lorcana.js index 01f8f812..ce5514a2 100644 --- a/commands/search/lorcana.js +++ b/commands/search/lorcana.js @@ -66,9 +66,15 @@ module.exports = class LorcanaCommand extends Command { async search(query) { if (!this.cache) await this.fetchCards(); + const q = query.replace(/( -)|,/g, ''); + const exactResults = this.cache.filter(card => { + const slug = card.Name.toLowerCase().replace(/( -)|,/g, ''); + return slug === q; + }); + if (exactResults.length) return exactResults[0]; const results = this.cache.filter(card => { - const q = query.replace(/( -)|,/g, ''); - return card.Name.toLowerCase().replace(/( -)|,/g, '').includes(q.toLowerCase()); + const slug = card.Name.toLowerCase().replace(/( -)|,/g, ''); + return slug.includes(q.toLowerCase()); }); if (!results.length) return null; return results[0];