From c53a5a462ee36611a47fc24fd2e616c2fceab0c9 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 30 May 2021 09:58:11 -0400 Subject: [PATCH] Make smash cache a Collection --- commands/search/smash-bros.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/commands/search/smash-bros.js b/commands/search/smash-bros.js index 2671461f..c388b72c 100644 --- a/commands/search/smash-bros.js +++ b/commands/search/smash-bros.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const Collection = require('@discordjs/collection'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); @@ -28,7 +29,7 @@ module.exports = class SmashBrosCommand extends Command { ] }); - this.cache = null; + this.cache = new Collection(); } async run(msg, { query }) { @@ -59,9 +60,8 @@ module.exports = class SmashBrosCommand extends Command { } async fetchFighters() { - if (this.cache) return this.cache; + if (this.cache.size) return this.cache; const { body } = await request.get('https://www.smashbros.com/assets_v2/data/fighter.json'); - const fighters = []; for (const fighter of body.fighters) { const data = { name: fighter.displayName.en_US.replaceAll('
', ''), @@ -77,10 +77,9 @@ module.exports = class SmashBrosCommand extends Command { dlc: Boolean(fighter.dlc), slug: this.makeSlug(fighter.displayName.en_US) }; - fighters.push(data); + this.cache.set(fighter.id, data); } - this.cache = fighters; - setTimeout(() => { this.cache = null; }, 8.64e+7); + setTimeout(() => this.cache.clear(), 8.64e+7); return this.cache; }