This commit is contained in:
Dragon Fire
2024-05-01 23:35:34 -04:00
parent 447557622c
commit 78aed1eca0
14 changed files with 75 additions and 75 deletions
+2 -2
View File
@@ -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.');
}
};
+5 -5
View File
@@ -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,
+4 -4
View File
@@ -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`
+4 -4
View File
@@ -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);
+4 -4
View File
@@ -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) {
+4 -4
View File
@@ -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');
+4 -4
View File
@@ -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`
+4 -4
View File
@@ -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) {
+8 -8
View File
@@ -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]})`)
+1 -1
View File
@@ -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.`);
}
};
+1 -1
View File
@@ -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.`);
}
};