mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-09 01:04:16 +02:00
Horse Info Command
This commit is contained in:
@@ -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,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)}`;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user