mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Use slugs in whos-that-pokemon
This commit is contained in:
@@ -60,7 +60,9 @@ module.exports = class WhosThatPokemonCommand extends Command {
|
||||
time: 15000
|
||||
});
|
||||
if (!msgs.size) return msg.reply(`Sorry, time is up! It was ${data.name}.`);
|
||||
if (!names.includes(msgs.first().content.toLowerCase())) return msg.reply(`Nope, sorry, it's ${data.name}.`);
|
||||
const guess = msgs.first().content.toLowerCase();
|
||||
const slug = this.client.pokemon.makeSlug(guess);
|
||||
if (!names.includes(guess) && data.slug !== slug) return msg.reply(`Nope, sorry, it's ${data.name}.`);
|
||||
return msg.reply('Nice job! 10/10! You deserve some cake!');
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
@@ -34,7 +34,7 @@ module.exports = class Pokemon {
|
||||
}
|
||||
|
||||
get slug() {
|
||||
return encodeURIComponent(this.name.toLowerCase().replace(/ /g, '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
return this.store.makeSlug(this.name);
|
||||
}
|
||||
|
||||
get spriteImageURL() {
|
||||
|
||||
@@ -5,7 +5,7 @@ const missingno = require('../../assets/json/missingno');
|
||||
|
||||
module.exports = class PokemonStore extends Collection {
|
||||
async fetch(query) {
|
||||
query = encodeURIComponent(query.toLowerCase().replace(/ /g, '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
query = this.makeSlug(query);
|
||||
if (!query) return null;
|
||||
const num = Number.parseInt(query, 10);
|
||||
if (this.has(num)) return this.get(num);
|
||||
@@ -26,4 +26,8 @@ module.exports = class PokemonStore extends Collection {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
makeSlug(query) {
|
||||
return encodeURIComponent(query.toLowerCase().replace(/ /g, '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user