From 08f88892b4a3a5589bf8b6fa549a99fbda61341d Mon Sep 17 00:00:00 2001 From: Maf Date: Sat, 23 May 2020 04:28:01 -0600 Subject: [PATCH] ISSUE 45 - Fuzzy Matching --- commands/gacha.js | 10 +++++----- commands/spark.js | 6 +++--- helpers/decision.js | 21 +++++++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/commands/gacha.js b/commands/gacha.js index bd84312..dbe410b 100644 --- a/commands/gacha.js +++ b/commands/gacha.js @@ -420,12 +420,12 @@ class GachaCommand extends Command { let sql = [ "SELECT id, name, recruits, rarity, item_type", "FROM gacha", - "WHERE name = $1 OR recruits = $1" + "WHERE name % $1 OR recruits % $1" ].join(" ") try { var results - return await Client.any(sql, [target]) + return await Client.any(sql, target) .then(data => { results = data return decision.buildDuplicateEmbed(data, target) @@ -665,7 +665,7 @@ class GachaCommand extends Command { let sql = [ "SELECT COUNT(*)", "FROM gacha", - "WHERE name = $1 OR recruits = $1" + "WHERE name % $1 OR recruits % $1" ].join(" ") try { @@ -676,7 +676,7 @@ class GachaCommand extends Command { } async fetchSuppliedTarget(name) { - let sql = "SELECT * FROM gacha WHERE name = $1 OR recruits = $1" + let sql = "SELECT * FROM gacha WHERE name % $1 OR recruits % $1" return await Client.one(sql, [name]) .then(res => { return res @@ -924,4 +924,4 @@ class GachaCommand extends Command { } } -module.exports = GachaCommand \ No newline at end of file +module.exports = GachaCommand diff --git a/commands/spark.js b/commands/spark.js index a09dab2..07d68f5 100644 --- a/commands/spark.js +++ b/commands/spark.js @@ -232,7 +232,7 @@ class SparkCommand extends Command { let sql = [ "SELECT COUNT(*)", "FROM gacha", - "WHERE name = $1 OR recruits = $1" + "WHERE name % $1 OR recruits % $1" ].join(" ") Client.any(sql, [target]) @@ -257,7 +257,7 @@ class SparkCommand extends Command { let sql = [ "SELECT id, name, recruits, rarity, item_type", "FROM gacha", - "WHERE name = $1 OR recruits = $1" + "WHERE name % $1 OR recruits % $1" ].join(" ") try { @@ -838,4 +838,4 @@ class SparkCommand extends Command { } } -module.exports = SparkCommand \ No newline at end of file +module.exports = SparkCommand diff --git a/helpers/decision.js b/helpers/decision.js index 42309ec..285ddf8 100644 --- a/helpers/decision.js +++ b/helpers/decision.js @@ -44,23 +44,28 @@ module.exports = { generateOptions: function(data, target) { var options = "" - for (const [i, item] of data.entries()) { + re = new RegExp(target, 'i'); + + for (const [i, item] of data.entries()) { var string = `${i + 1}. ` - if (item.item_type == 0) { string += `(${common.mapRarity(item.rarity)} Weapon) ` } else { string += `(${common.mapRarity(item.rarity)} Summon) ` } - if (item.recruits != null) { - if (item.name === target) { + if (item.recruits != null) { + + if (item.name.match(re)) { string += `<${item.name}> - ${item.recruits}` - } else if (item.recruits === target) { + } else if (item.recruits.match(re)) { string += `${item.name} - <${item.recruits}>` - } + } else { + string += `${item.name} - ${item.recruits}` + } + } else { - if (item.name === target) { + if (item.name.match(re)) { string += `<${item.name}>` } else { string += `${item.name}` @@ -124,4 +129,4 @@ module.exports = { return embed } -} \ No newline at end of file +}