Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE 45 - Fuzzy Matching #4

Merged
merged 1 commit into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions commands/gacha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -924,4 +924,4 @@ class GachaCommand extends Command {
}
}

module.exports = GachaCommand
module.exports = GachaCommand
6 changes: 3 additions & 3 deletions commands/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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 {
Expand Down Expand Up @@ -838,4 +838,4 @@ class SparkCommand extends Command {
}
}

module.exports = SparkCommand
module.exports = SparkCommand
21 changes: 13 additions & 8 deletions helpers/decision.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -124,4 +129,4 @@ module.exports = {

return embed
}
}
}