From 78aed1eca0e201b1cd13101cf6fc651f874bd475 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 1 May 2024 23:35:34 -0400 Subject: [PATCH] Fix --- Xiao.js | 60 ++++++++++++++--------------- commands/games-mp/chess-delete.js | 4 +- commands/games-mp/chess.js | 10 ++--- commands/games-mp/gunfight.js | 8 ++-- commands/games-mp/typing-race.js | 8 ++-- commands/games-sp/anagramica.js | 8 ++-- commands/games-sp/minesweeper.js | 8 ++-- commands/games-sp/reaction-time.js | 8 ++-- commands/games-sp/typing-test.js | 8 ++-- commands/util-public/high-scores.js | 16 ++++---- commands/util/disable.js | 2 +- commands/util/enable.js | 2 +- structures/remind/Timer.js | 4 +- structures/remind/TimerManager.js | 4 +- 14 files changed, 75 insertions(+), 75 deletions(-) diff --git a/Xiao.js b/Xiao.js index 732f7b40..03bb542b 100644 --- a/Xiao.js +++ b/Xiao.js @@ -73,36 +73,6 @@ client.on('ready', async () => { const decTalkFolderExists = await checkFileExists(path.join(__dirname, 'tmp', 'dec-talk')); if (!decTalkFolderExists) await mkdir(path.join(__dirname, 'tmp', 'dec-talk')); - // Interval to change activity every minute - setInterval(() => { - const activity = client.activities[Math.floor(Math.random() * client.activities.length)]; - const text = typeof activity.text === 'function' ? activity.text(client) : activity.text; - client.user.setActivity(text, { type: activity.type }); - }, 60000); - - // Import command-leaderboard.json - try { - const results = client.importCommandLeaderboard(); - if (results) { - client.logger.info('[LEADERBOARD] command-leaderboard.json successfully loaded.'); - } else { - client.logger.error('[LEADERBOARD] command-leaderboard.json is not formatted correctly.'); - } - } catch (err) { - client.logger.error(`[LEADERBOARD] Could not parse command-leaderboard.json:\n${err.stack}`); - } - - // Set up disabled commands - try { - const disabled = await client.redis.hgetall('disabled'); - for (const command of Object.keys(disabled)) { - client.registry.commands.get(command).disable(); - client.logger.info(`[DISABLED] Disabled the ${command} command.`); - } - } catch (err) { - client.logger.error(`[DISABLED] Error while disabling commands:\n${err.stack}`); - } - // Check for API keys and disable commands that need them if not present if (!process.env.REDIS_HOST || !process.env.REDIS_PASS) { client.logger.error('[REDIS] No REDIS_HOST or REDIS_PASS in env. Exiting process.'); @@ -145,6 +115,36 @@ client.on('ready', async () => { client.logger.info('[DISABLED] No WEBSTER_KEY in env. word-of-the-day, word-chain, and define have been disabled.'); } + // Interval to change activity every minute + setInterval(() => { + const activity = client.activities[Math.floor(Math.random() * client.activities.length)]; + const text = typeof activity.text === 'function' ? activity.text(client) : activity.text; + client.user.setActivity(text, { type: activity.type }); + }, 60000); + + // Set up disabled commands + try { + const disabled = await client.redis.db.hgetall('disabled'); + for (const command of Object.keys(disabled)) { + client.registry.commands.get(command).disable(); + client.logger.info(`[DISABLED] Disabled the ${command} command.`); + } + } catch (err) { + client.logger.error(`[DISABLED] Error while disabling commands:\n${err.stack}`); + } + + // Import command-leaderboard.json + try { + const results = client.importCommandLeaderboard(); + if (results) { + client.logger.info('[LEADERBOARD] command-leaderboard.json successfully loaded.'); + } else { + client.logger.error('[LEADERBOARD] command-leaderboard.json is not formatted correctly.'); + } + } catch (err) { + client.logger.error(`[LEADERBOARD] Could not parse command-leaderboard.json:\n${err.stack}`); + } + // Import command-last-run.json try { const results = client.importLastRun(); diff --git a/commands/games-mp/chess-delete.js b/commands/games-mp/chess-delete.js index 92af2190..9908cc82 100644 --- a/commands/games-mp/chess-delete.js +++ b/commands/games-mp/chess-delete.js @@ -12,9 +12,9 @@ module.exports = class ChessDeleteCommand extends Command { } async run(msg) { - const data = await this.client.redis.exists(`chess-${msg.author.id}`); + const data = await this.client.redis.db.exists(`chess-${msg.author.id}`); if (!data) return msg.reply('You do not have a saved Chess game.'); - await this.client.redis.del(`chess-${msg.author.id}`); + await this.client.redis.db.del(`chess-${msg.author.id}`); return msg.say('Your saved game has been deleted.'); } }; diff --git a/commands/games-mp/chess.js b/commands/games-mp/chess.js index da48595b..ca932eac 100644 --- a/commands/games-mp/chess.js +++ b/commands/games-mp/chess.js @@ -65,7 +65,7 @@ module.exports = class ChessCommand extends Command { const verification = await verify(msg.channel, opponent); if (!verification) return msg.say('Looks like they declined...'); } - const resumeGame = await this.client.redis.get(`chess-${msg.author.id}`); + const resumeGame = await this.client.redis.db.get(`chess-${msg.author.id}`); let game; let whiteTime = time === 0 ? Infinity : time * 60000; let blackTime = time === 0 ? Infinity : time * 60000; @@ -85,9 +85,9 @@ module.exports = class ChessCommand extends Command { blackTime = data.blackTime === -1 ? Infinity : data.blackTime; whitePlayer = data.color === 'white' ? msg.author : opponent; blackPlayer = data.color === 'black' ? msg.author : opponent; - await this.client.redis.del(`chess-${msg.author.id}`); + await this.client.redis.db.del(`chess-${msg.author.id}`); } catch { - await this.client.redis.del(`chess-${msg.author.id}`); + await this.client.redis.db.del(`chess-${msg.author.id}`); return msg.reply('An error occurred reading your saved game. It will be deleted.'); } } else { @@ -154,7 +154,7 @@ module.exports = class ChessCommand extends Command { if (turn.first().content.toLowerCase() === 'end') break; if (turn.first().content.toLowerCase() === 'save') { const { author } = turn.first(); - const alreadySaved = await this.client.redis.get(`chess-${author.id}`); + const alreadySaved = await this.client.redis.db.get(`chess-${author.id}`); if (alreadySaved) { await msg.say('You already have a saved game, do you want to overwrite it?'); const verification = await verify(msg.channel, author); @@ -162,7 +162,7 @@ module.exports = class ChessCommand extends Command { } if (gameState.turn === 'black') blackTime -= new Date() - now; if (gameState.turn === 'white') whiteTime -= new Date() - now; - await this.client.redis.set( + await this.client.redis.db.set( `chess-${author.id}`, this.exportGame( game, diff --git a/commands/games-mp/gunfight.js b/commands/games-mp/gunfight.js index 0ecf670c..99960e4a 100644 --- a/commands/games-mp/gunfight.js +++ b/commands/games-mp/gunfight.js @@ -41,14 +41,14 @@ module.exports = class GunfightCommand extends Command { time: 30000 }); const newScore = Date.now() - now; - const highScoreGet = await this.client.redis.get('reaction-time'); + const highScoreGet = await this.client.redis.db.get('reaction-time'); const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null; - const highScoreUser = await this.client.redis.get('reaction-time-user'); + const highScoreUser = await this.client.redis.db.get('reaction-time-user'); const scoreBeat = !highScore || highScore > newScore; const user = await fetchHSUserDisplay(this.client, highScoreUser); if (scoreBeat) { - await this.client.redis.set('reaction-time', newScore); - await this.client.redis.set('reaction-time-user', winner.first().author.id); + await this.client.redis.db.set('reaction-time', newScore); + await this.client.redis.db.set('reaction-time-user', winner.first().author.id); } if (!winner.size) return msg.say('Oh... No one won.'); return msg.say(stripIndents` diff --git a/commands/games-mp/typing-race.js b/commands/games-mp/typing-race.js index 7bd9822f..241a8467 100644 --- a/commands/games-mp/typing-race.js +++ b/commands/games-mp/typing-race.js @@ -43,14 +43,14 @@ module.exports = class TypingRaceCommand extends Command { time: 30000 }); const newScore = Date.now() - now; - const highScoreGet = await this.client.redis.get('typing-test'); + const highScoreGet = await this.client.redis.db.get('typing-test'); const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null; - const highScoreUser = await this.client.redis.get('typing-test-user'); + const highScoreUser = await this.client.redis.db.get('typing-test-user'); const scoreBeat = winner.size && (!highScore || highScore > newScore); const user = await fetchHSUserDisplay(this.client, highScoreUser); if (scoreBeat) { - await this.client.redis.set('typing-test', newScore); - await this.client.redis.set('typing-test-user', winner.first().author.id); + await this.client.redis.db.set('typing-test', newScore); + await this.client.redis.db.set('typing-test-user', winner.first().author.id); } if (!winner.size) return msg.say('Oh... No one won.'); const wpm = (sentence.length / 5) / ((newScore / 1000) / 60); diff --git a/commands/games-sp/anagramica.js b/commands/games-sp/anagramica.js index 467168d4..17e95820 100644 --- a/commands/games-sp/anagramica.js +++ b/commands/games-sp/anagramica.js @@ -70,14 +70,14 @@ module.exports = class AnagramicaCommand extends Command { filter, time: time * 1000 }); - const highScoreGet = await this.client.redis.get('anagramica'); + const highScoreGet = await this.client.redis.db.get('anagramica'); const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null; - const highScoreUser = await this.client.redis.get('anagramica-user'); + const highScoreUser = await this.client.redis.db.get('anagramica-user'); const scoreBeat = !highScore || highScore < points; const user = await fetchHSUserDisplay(this.client, highScoreUser); if (scoreBeat) { - await this.client.redis.set('anagramica', points); - await this.client.redis.set('anagramica-user', msg.author.id); + await this.client.redis.db.set('anagramica', points); + await this.client.redis.db.set('anagramica-user', msg.author.id); } const moreWords = shuffle(valid.filter(word => !picked.includes(word))).slice(0, 5); if (!msgs.size) { diff --git a/commands/games-sp/minesweeper.js b/commands/games-sp/minesweeper.js index 616c961f..eeef861c 100644 --- a/commands/games-sp/minesweeper.js +++ b/commands/games-sp/minesweeper.js @@ -127,14 +127,14 @@ module.exports = class MinesweeperCommand extends Command { } } const newScore = Date.now() - startTime; - const highScoreGet = await this.client.redis.get(`minesweeper-${size}`); + const highScoreGet = await this.client.redis.db.get(`minesweeper-${size}`); const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null; - const highScoreUser = await this.client.redis.get(`minesweeper-${size}-user`); + const highScoreUser = await this.client.redis.db.get(`minesweeper-${size}-user`); const scoreBeat = !cheatMode && win && (!highScore || highScore > newScore); const user = await fetchHSUserDisplay(this.client, highScoreUser); if (scoreBeat) { - await this.client.redis.set(`minesweeper-${size}`, newScore); - await this.client.redis.set(`minesweeper-${size}-user`, msg.author.id); + await this.client.redis.db.set(`minesweeper-${size}`, newScore); + await this.client.redis.db.set(`minesweeper-${size}-user`, msg.author.id); } if (win === null) return gameMsg.edit('Game ended due to inactivity.'); const newDisplayTime = moment.duration(newScore).format('mm:ss'); diff --git a/commands/games-sp/reaction-time.js b/commands/games-sp/reaction-time.js index 1d1d4fa1..2df39d5d 100644 --- a/commands/games-sp/reaction-time.js +++ b/commands/games-sp/reaction-time.js @@ -28,14 +28,14 @@ module.exports = class ReactionTimeCommand extends Command { time: 30000 }); const newScore = Date.now() - now; - const highScoreGet = await this.client.redis.get('reaction-time'); + const highScoreGet = await this.client.redis.db.get('reaction-time'); const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null; - const highScoreUser = await this.client.redis.get('reaction-time-user'); + const highScoreUser = await this.client.redis.db.get('reaction-time-user'); const scoreBeat = !highScore || highScore > newScore; const user = await fetchHSUserDisplay(this.client, highScoreUser); if (scoreBeat) { - await this.client.redis.set('reaction-time', newScore); - await this.client.redis.set('reaction-time-user', msg.author.id); + await this.client.redis.db.set('reaction-time', newScore); + await this.client.redis.db.set('reaction-time-user', msg.author.id); } if (!msgs.size) return msg.say('Failed to answer within 30 seconds.'); return msg.say(stripIndents` diff --git a/commands/games-sp/typing-test.js b/commands/games-sp/typing-test.js index 491d70b8..3527fc3e 100644 --- a/commands/games-sp/typing-test.js +++ b/commands/games-sp/typing-test.js @@ -29,14 +29,14 @@ module.exports = class TypingTestCommand extends Command { }); const win = msgs.size && msgs.first().content.toLowerCase() === sentence; const newScore = Date.now() - now; - const highScoreGet = await this.client.redis.get('typing-test'); + const highScoreGet = await this.client.redis.db.get('typing-test'); const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null; - const highScoreUser = await this.client.redis.get('typing-test-user'); + const highScoreUser = await this.client.redis.db.get('typing-test-user'); const scoreBeat = win && (!highScore || highScore > newScore); const user = await fetchHSUserDisplay(this.client, highScoreUser); if (scoreBeat) { - await this.client.redis.set('typing-test', newScore); - await this.client.redis.set('typing-test-user', msg.author.id); + await this.client.redis.db.set('typing-test', newScore); + await this.client.redis.db.set('typing-test-user', msg.author.id); } if (!msgs.size) return msg.reply('Sorry! You lose!'); if (msgs.first().content.toLowerCase() !== sentence) { diff --git a/commands/util-public/high-scores.js b/commands/util-public/high-scores.js index e0404028..06337acc 100644 --- a/commands/util-public/high-scores.js +++ b/commands/util-public/high-scores.js @@ -18,26 +18,26 @@ module.exports = class HighScoresCommand extends Command { } async run(msg) { - const typingRaceGet = await this.client.redis.get('typing-test'); + const typingRaceGet = await this.client.redis.db.get('typing-test'); const typingRace = typingRaceGet ? Number.parseInt(typingRaceGet, 10) : null; - const typingRaceUser = await this.client.redis.get('typing-test-user'); + const typingRaceUser = await this.client.redis.db.get('typing-test-user'); const typingRaceUserDisplay = await fetchHSUserDisplay(this.client, typingRaceUser); - const anagramsGet = await this.client.redis.get('anagramica'); + const anagramsGet = await this.client.redis.db.get('anagramica'); const anagrams = anagramsGet ? Number.parseInt(anagramsGet, 10) : null; - const anagramsUser = await this.client.redis.get('anagramica-user'); + const anagramsUser = await this.client.redis.db.get('anagramica-user'); const anagramsUserDisplay = await fetchHSUserDisplay(this.client, anagramsUser); const minesweeperScores = {}; const minesweeperUsers = {}; for (const size of minesweeperSizes) { - const minesweeperGet = await this.client.redis.get(`minesweeper-${size}`); + const minesweeperGet = await this.client.redis.db.get(`minesweeper-${size}`); const minesweeper = minesweeperGet ? Number.parseInt(minesweeperGet, 10) : null; - const minesweeperUser = await this.client.redis.get(`minesweeper-${size}-user`); + const minesweeperUser = await this.client.redis.db.get(`minesweeper-${size}-user`); minesweeperScores[size] = moment.duration(minesweeper).format('mm:ss'); minesweeperUsers[size] = await fetchHSUserDisplay(this.client, minesweeperUser); } - const reactionTimeGet = await this.client.redis.get('reaction-time'); + const reactionTimeGet = await this.client.redis.db.get('reaction-time'); const reactionTime = reactionTimeGet ? Number.parseInt(reactionTimeGet, 10) : null; - const reactionTimeUser = await this.client.redis.get('reaction-time-user'); + const reactionTimeUser = await this.client.redis.db.get('reaction-time-user'); const reactionTimeUserDisplay = await fetchHSUserDisplay(this.client, reactionTimeUser); const minesweeperDisplay = Object.entries(minesweeperScores) .map(([size, score]) => `\`${size}x${size}\`: ${score} (Held by ${minesweeperUsers[size]})`) diff --git a/commands/util/disable.js b/commands/util/disable.js index 659ff7c2..155291f5 100644 --- a/commands/util/disable.js +++ b/commands/util/disable.js @@ -24,7 +24,7 @@ module.exports = class DisableCommand extends Command { if (!command._enabled) return msg.say(`The \`${command.name}\` command is already disabled.`); if (command.guarded) return msg.say(`The \`${command.name}\` command cannot be disabled.`); command.disable(); - await this.client.redis.hset('disabled', { [command.name]: true }); + await this.client.redis.db.hset('disabled', { [command.name]: true }); return msg.say(`Disabled the \`${command.name}\` command.`); } }; diff --git a/commands/util/enable.js b/commands/util/enable.js index 5ba767bf..157de33e 100644 --- a/commands/util/enable.js +++ b/commands/util/enable.js @@ -23,7 +23,7 @@ module.exports = class EnableCommand extends Command { async run(msg, { command }) { if (command._enabled) return msg.say(`The \`${command.name}\` command is already enabled.`); command.enable(); - await this.client.redis.hdel('disabled', command.name); + await this.client.redis.db.hdel('disabled', command.name); return msg.say(`Enabled the \`${command.name}\` command.`); } }; diff --git a/structures/remind/Timer.js b/structures/remind/Timer.js index 98359c5d..7f5c2754 100644 --- a/structures/remind/Timer.js +++ b/structures/remind/Timer.js @@ -29,7 +29,7 @@ module.exports = class Timer { await channel.send(`🕰️ <@${this.userID}>, you wanted me to remind you of: **"${this.title}"**.`); } finally { this.client.timers.delete(this.id); - await this.client.redis.hdel('timer', this.id); + await this.client.redis.db.hdel('timer', this.id); } }, time); } @@ -37,6 +37,6 @@ module.exports = class Timer { delete() { clearTimeout(this.timeout); this.client.timers.delete(this.id); - return this.client.redis.hdel('timer', this.id); + return this.client.redis.db.hdel('timer', this.id); } }; diff --git a/structures/remind/TimerManager.js b/structures/remind/TimerManager.js index 22518894..301cd48a 100644 --- a/structures/remind/TimerManager.js +++ b/structures/remind/TimerManager.js @@ -9,7 +9,7 @@ module.exports = class TimerManager extends Collection { } async fetchAll() { - const timers = await this.client.redis.hgetall('timer'); + const timers = await this.client.redis.db.hgetall('timer'); for (let data of Object.values(timers)) { data = JSON.parse(data); await this.setTimer(data.id, data.channelID, new Date(data.time) - new Date(), data.userID, data.title, false); @@ -19,7 +19,7 @@ module.exports = class TimerManager extends Collection { async setTimer(id, channelID, time, userID, title, updateRedis = true) { const timer = new Timer(this.client, id, channelID, userID, time, title); - if (updateRedis) await this.client.redis.hset('timer', { [timer.id]: timer.stringify() }); + if (updateRedis) await this.client.redis.db.hset('timer', { [timer.id]: timer.stringify() }); this.set(timer.id, timer); return timer; }