Horse Info Command

This commit is contained in:
Dragon Fire
2020-10-27 00:03:48 -04:00
parent 9cd4ebef38
commit b752ebe07e
6 changed files with 180 additions and 73 deletions
+34
View File
@@ -0,0 +1,34 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const { formatTime } = require('../../util/Util');
const horses = require('../../assets/json/horse-race');
module.exports = class HorseInfoCommand extends Command {
constructor(client) {
super(client, {
name: 'horse-info',
aliases: ['horse'],
group: 'games-sp',
memberName: 'horse-info',
description: 'Responds with detailed information on a horse.',
args: [
{
key: 'horse',
prompt: 'Which horse would you like to get information on?',
type: 'string',
validate: horse => horses.some(h => h.name.toLowerCase() === horse.toLowerCase()),
parse: horse => horses.find(h => h.name.toLowerCase() === horse.toLowerCase())
}
]
});
}
run(msg, { horse }) {
return msg.say(stripIndents`
__**Information on ${horse.name}**__
**Name:** ${horse.name}
**Fastest Recorded Time:** ${formatTime(horse.minTime)}
**Name Origin:** ${horse.origin || 'None'}
`);
}
};
+2 -9
View File
@@ -2,7 +2,7 @@ const Command = require('../../structures/Command');
const { createCanvas, loadImage, registerFont } = require('canvas');
const path = require('path');
const { stripIndents } = require('common-tags');
const { shuffle, randomRange } = require('../../util/Util');
const { shuffle, randomRange, formatTime } = require('../../util/Util');
const { drawImageWithTint } = require('../../util/Canvas');
const horses = require('../../assets/json/horse-race');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Paladins.otf'), { family: 'Paladins' });
@@ -102,17 +102,10 @@ module.exports = class HorseRaceCommand extends Command {
const horse = chosenHorses.find(hor => hor.name === result.name);
if (colors[i]) drawImageWithTint(ctx, horseImg, colors[i], 37, 114 + (49 * i), 49, 49);
ctx.font = '34px Paladins';
ctx.fillText(this.formatTime(result.time), 755, 138 + (49 * i));
ctx.fillText(formatTime(result.time), 755, 138 + (49 * i));
ctx.font = '15px Paladins';
ctx.fillText(horse.name, 251, 138 + (49 * i));
}
return { attachment: canvas.toBuffer(), name: 'leaderboard.png' };
}
formatTime(time) {
const min = Math.floor(time / 60);
const sec = Math.floor(time - (min * 60));
const ms = time - sec - (min * 60);
return `${min}:${sec.toString().padStart(2, '0')}.${ms.toFixed(4).slice(2)}`;
}
};