mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-22 18:29:14 +02:00
Horse Race Command
This commit is contained in:
@@ -44,7 +44,7 @@ module.exports = class AppleEngravingCommand extends Command {
|
||||
s: 2,
|
||||
f: 'font1'
|
||||
});
|
||||
return msg.channel.send({ files: [{ attachment: body, name: 'apple-engraving.jpg' }] });
|
||||
return msg.say({ files: [{ attachment: body, name: 'apple-engraving.jpg' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ module.exports = class NewspaperCommand extends Command {
|
||||
.attach('headline', headline)
|
||||
.attach('text', body);
|
||||
const newspaperURL = text.match(/<img src="(https:\/\/r[0-9]+\.fodey\.com\/[0-9]+\/.+\.jpg)"/i)[1];
|
||||
return msg.channel.send({ files: [newspaperURL] });
|
||||
return msg.say({ files: [newspaperURL] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage, registerFont } = require('canvas');
|
||||
const path = require('path');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { shuffle } = require('../../util/Util');
|
||||
const { drawImageWithTint, randomRange } = require('../../util/Canvas');
|
||||
const horses = require('../../assets/json/horse-race');
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Paladins-nl8P.otf'), { family: 'Paladins' });
|
||||
|
||||
module.exports = class HorseRaceCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'horse-race',
|
||||
aliases: ['race-horse', 'kentucky-derby'],
|
||||
group: 'games-sp',
|
||||
memberName: 'horse-race',
|
||||
description: 'Bet on the fastest horse in a 6-horse race.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
credit: [
|
||||
{
|
||||
name: 'Ambition',
|
||||
url: 'https://ambition.com/',
|
||||
reason: 'Image',
|
||||
// eslint-disable-next-line max-len
|
||||
reasonURL: 'https://help.ambition.com/hc/en-us/articles/360005048011-How-do-I-set-up-a-Leaderboard-Slide-'
|
||||
},
|
||||
{
|
||||
name: 'Free SVG',
|
||||
url: 'https://freesvg.org/',
|
||||
reason: 'Image',
|
||||
reasonURL: 'https://freesvg.org/race-horse'
|
||||
},
|
||||
{
|
||||
name: 'Iconian Fonts',
|
||||
url: 'https://www.fontspace.com/iconian-fonts',
|
||||
reason: 'Paladins Font',
|
||||
reasonURL: 'https://www.fontspace.com/paladins-font-f32777'
|
||||
},
|
||||
{
|
||||
name: 'Stadium Talk',
|
||||
url: 'https://www.stadiumtalk.com/',
|
||||
reason: 'Horse Name Data',
|
||||
reasonURL: 'https://www.stadiumtalk.com/s/best-racehorse-names-be7b8ad6b49a42df'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
const chosenHorses = shuffle(horses).slice(0, 6);
|
||||
await msg.reply(stripIndents`
|
||||
**Choose a horse to bet on:** _(Type the number)_
|
||||
${chosenHorses.map((horse, i) => `**${i + 1}.** ${horse.name}`).join('\n')}
|
||||
`);
|
||||
const filter = res => {
|
||||
if (res.author.id !== msg.author.id) return false;
|
||||
const num = Number.parseInt(res.content, 10);
|
||||
if (!num) return false;
|
||||
return num > 0 && num <= chosenHorses.length;
|
||||
};
|
||||
const msgs = await msg.channel.awaitMessages(filter, {
|
||||
max: 1,
|
||||
time: 30000
|
||||
});
|
||||
if (!msgs.size) return msg.reply('Sorry, can\'t have a race with no bets!');
|
||||
const pick = chosenHorses[Number.parseInt(msgs.first().content, 10) - 1];
|
||||
const results = [];
|
||||
for (const horse of chosenHorses) {
|
||||
results.push({
|
||||
name: horse.name,
|
||||
time: randomRange(horse.minTime, horse.minTime + 15) + Math.random()
|
||||
});
|
||||
}
|
||||
results = results.sort((a, b) => b.time - a.time);
|
||||
const leaderboard = await this.generateLeaderboard(chosenHorses, results);
|
||||
const win = results[0].name === pick.name;
|
||||
return msg.reply(win ? `Nice job! Your horse won!` : 'Better luck next time!', { files: [leaderboard] });
|
||||
}
|
||||
|
||||
async generateLeaderboard(horses, results) {
|
||||
const lb = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'horse-race', 'leaderboard.png'));
|
||||
const horseImg = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'horse-race', 'horse.png'));
|
||||
const canvas = createCanvas(lb.width, lb.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(base, 0, 0);
|
||||
ctx.font = '34px Paladins';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
for (let i = 0; i < horses.length; i++) {
|
||||
const horse = horses[i];
|
||||
const result = results.find(result => horse.name === result.name).time;
|
||||
drawImageWithTint(ctx, horseImg, horse.color, 37 * i, 114, 49, 49);
|
||||
ctx.fillText(this.formatTime(result), 138 * i, 755);
|
||||
ctx.fillText(horse.name, 138 * 1, 251);
|
||||
}
|
||||
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}.${ms.toFixed(4).slice(2)}`;
|
||||
}
|
||||
};
|
||||
@@ -26,7 +26,7 @@ module.exports = class LightNovelCoverCommand extends Command {
|
||||
const { text } = await request.get('https://salty-salty-studios.com/shiz/lncovers.php');
|
||||
const $ = cheerio.load(text);
|
||||
const cover = $('img').first();
|
||||
return msg.channel.send(cover.attr('alt'), {
|
||||
return msg.say(cover.attr('alt'), {
|
||||
files: [`https://salty-salty-studios.com/shiz/${cover.attr('src')}`]
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
@@ -34,8 +34,8 @@ module.exports = class RollCommand extends Command {
|
||||
|
||||
run(msg, { maxValue, minValue }) {
|
||||
let result;
|
||||
if (!minValue) result = Math.floor(Math.random() * maxValue) + 1;
|
||||
else result = randomRange(minValue, maxValue);
|
||||
if (minValue) result = randomRange(minValue, maxValue);
|
||||
else result = Math.floor(Math.random() * maxValue) + 1;
|
||||
return msg.say(`You rolled a ${formatNumber(result)}.`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -32,6 +32,6 @@ module.exports = class GenerateCommandsCommand extends Command {
|
||||
}).join('\n')}`;
|
||||
});
|
||||
const text = `Total: ${this.client.registry.commands.size}\n${list.join('\n')}`;
|
||||
return msg.channel.send({ files: [{ attachment: Buffer.from(text), name: 'commands.txt' }] });
|
||||
return msg.say({ files: [{ attachment: Buffer.from(text), name: 'commands.txt' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -47,6 +47,6 @@ module.exports = class GenerateCreditCommand extends Command {
|
||||
if (!cmd.reasonURL) return ` * ${cmd.name} (${cmd.reason})`;
|
||||
return ` * ${cmd.name} (${embedURL(cmd.reason, cmd.reasonURL || '', false)})`;
|
||||
}).join('\n')}`);
|
||||
return msg.channel.send({ files: [{ attachment: Buffer.from(mapped.join('\n')), name: 'credit.txt' }] });
|
||||
return msg.say({ files: [{ attachment: Buffer.from(mapped.join('\n')), name: 'credit.txt' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,6 +24,6 @@ module.exports = class GenerateProcessEnvCommand extends Command {
|
||||
line = line.replace('=', '');
|
||||
return `${line}="${process.env[line] || ''}"`;
|
||||
}).join('\n');
|
||||
return msg.channel.send({ files: [{ attachment: Buffer.from(list), name: 'process.env.txt' }] });
|
||||
return msg.say({ files: [{ attachment: Buffer.from(list), name: 'process.env.txt' }] });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user