High Scores in a few games

This commit is contained in:
Dragon Fire
2020-12-13 09:51:16 -05:00
parent e64c743e00
commit 87d83051fa
5 changed files with 45 additions and 7 deletions
+8 -1
View File
@@ -45,9 +45,16 @@ module.exports = class TypingRaceCommand extends Command {
max: 1,
time: 30000
});
const newScore = Date.now() - now;
const highScoreGet = await this.client.redis.get('typing-test');
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
if (!highScore || highScore < newScore) await this.client.redis.set('typing-test', newScore);
this.client.games.delete(msg.channel.id);
if (!winner.size) return msg.say('Oh... No one won.');
return msg.say(`The winner is ${winner.first().author}! (Took ${(Date.now() - now) / 1000} seconds)`);
return msg.say(stripIndents`
The winner is ${winner.first().author}! (Took ${newScore / 1000} seconds)
${!highScore || highScore < newScore ? `**New High Score!** Old:` : `High Score:`} ${highScore / 1000}
`);
} catch (err) {
this.client.games.delete(msg.channel.id);
throw err;
+19 -3
View File
@@ -66,10 +66,26 @@ module.exports = class AnagramicaCommand extends Command {
const msgs = await msg.channel.awaitMessages(filter, {
time: time * 1000
});
const highScoreGet = await this.client.redis.get('anagramica');
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
if (!highScore || highScore < points) await this.client.redis.set('anagramica', points);
this.client.games.delete(msg.channel.id);
if (!msgs.size) return msg.reply('Couldn\'t even think of one? Ouch.');
if (points < 1) return msg.reply(`Ouch, your final score was **${points}**. Try harder next time!`);
return msg.reply(`Nice job! Your final score was **${points}**!`);
if (!msgs.size) {
return msg.reply(stripIndents`
Couldn't even think of one? Ouch.
${!highScore || highScore < points ? `**New High Score!** Old:` : `High Score:`} ${highScore}
`);
}
if (points < 1) {
return msg.reply(stripIndents`
Ouch, your final score was **${points}**. Try harder next time!
${!highScore || highScore < points ? `**New High Score!** Old:` : `High Score:`} ${highScore}
`);
}
return msg.reply(stripIndents`
Nice job! Your final score was **${points}**!
${!highScore || highScore < points ? `**New High Score!** Old:` : `High Score:`} ${highScore}
`);
} catch (err) {
this.client.games.delete(msg.channel.id);
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+9 -1
View File
@@ -1,4 +1,5 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const { delay, randomRange } = require('../../util/Util');
const words = ['fire', 'draw', 'shoot', 'bang', 'pull', 'boom'];
@@ -28,9 +29,16 @@ module.exports = class ReactionTimeCommand extends Command {
max: 1,
time: 30000
});
const newScore = Date.now() - now;
const highScoreGet = await this.client.redis.get('reaction-time');
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
if (!highScore || highScore < newScore) await this.client.redis.set('reaction-time', newScore);
this.client.games.delete(msg.channel.id);
if (!msgs.size) return msg.say('Failed to answer within 30 seconds.');
return msg.say(`Nice one! (Took ${(Date.now() - now) / 1000} seconds)`);
return msg.say(stripIndents`
Nice one! (Took ${newScore / 1000} seconds)
${!highScore || highScore < newScore ? `**New High Score!** Old:` : `High Score:`} ${highScore / 1000}
`);
} catch (err) {
this.client.games.delete(msg.channel.id);
throw err;
+8 -1
View File
@@ -44,8 +44,15 @@ module.exports = class TypingTestCommand extends Command {
max: 1,
time
});
const newScore = Date.now() - now;
const highScoreGet = await this.client.redis.get('typing-test');
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
if (!highScore || highScore < newScore) await this.client.redis.set('typing-test', newScore);
if (!msgs.size) return msg.reply('Sorry! You lose!');
if (msgs.first().content !== sentence) return msg.reply('Sorry! You made a typo, so you lose!');
return msg.reply(`Nice job! 10/10! You deserve some cake! (Took ${(Date.now() - now) / 1000} seconds)`);
return msg.reply(stripIndents`
Nice job! 10/10! You deserve some cake! (Took ${newScore / 1000} seconds)
${!highScore || highScore < newScore ? `**New High Score!** Old:` : `High Score:`} ${highScore / 1000}
`);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "123.5.5",
"version": "123.6.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {