diff --git a/assets/json/hat.json b/assets/json/hat.json new file mode 100644 index 00000000..6f515177 --- /dev/null +++ b/assets/json/hat.json @@ -0,0 +1,70 @@ +{ + "anon": { + "file": "anon.png", + "comment": "Wow {{user}}, you look ready to hack!" + }, + "ash": { + "file": "ash.png", + "comment": "How's that Pokédex coming along, {{user}}?" + }, + "becel": { + "file": "becel.png", + "comment": "Bake Well, Cook Well and Live Well, {{user}}." + }, + "biden": { + "file": "biden.png", + "comment": "[#Biden2024](https://joebiden.com/)!" + }, + "birthday": { + "file": "birthday.png", + "comment": "Happy birthday, {{user}}!" + }, + "christmas": { + "file": "christmas.png", + "comment": "Merry Christmas, {{user}}! I hope you've been good for Santa!" + }, + "devil": { + "file": "devil.png", + "comment": "Naughty little {{user}}! How's Hell going for ya?" + }, + "disguise": { + "file": "disguise.png", + "comment": "Huh? {{user}}? Where did you go?" + }, + "dunce": { + "file": "dunce.png", + "comment": "Hehe, {{user}}, you're so dumb!" + }, + "leprechaun": { + "file": "leprechaun.png", + "comment": "Hearts, stars, and horeshoes, clovers and blue moons, hourglasses, rainbows, and tasty red balloons!" + }, + "mask": { + "file": "mask.png", + "comment": "Good job {{user}}! Don't wanna get anyone sick!" + }, + "megumin": { + "file": "megumin.png", + "comment": "Oh, blackness shrouded in light, frenzied blaze clad in night...\nIn the name of the crimson demons, let the collapse of thine origin manifest.\nSummon before me the root of thy power hidden within the lands of the kingdom of demise!\n\nEXPLOSION!" + }, + "pilgrim": { + "file": "pilgrim.png", + "comment": "How's the turkey, {{user}}?" + }, + "pirate": { + "file": "pirate.png", + "comment": "Yo ho, yo ho, a pirate's life for me!" + }, + "soviet": { + "file": "soviet.png", + "comment": "In the US, you break the law. In Soviet Russia, law breaks you." + }, + "tophat": { + "file": "tophat.png", + "comment": "Oh, {{user}}! Top of the morning to ya!" + }, + "witch": { + "file": "witch.png", + "comment": "Whatcha got in that cauldron, {{user}}?" + } +} diff --git a/commands/edit-avatar/hat.js b/commands/edit-avatar/hat.js index 521aca6d..ed392cf0 100644 --- a/commands/edit-avatar/hat.js +++ b/commands/edit-avatar/hat.js @@ -3,9 +3,8 @@ const { PermissionFlagsBits } = require('discord.js'); const { createCanvas, loadImage } = require('canvas'); const request = require('node-superfetch'); const path = require('path'); -const fs = require('fs'); -const hats = fs.readdirSync(path.join(__dirname, '..', '..', 'assets', 'images', 'hat')) - .map(hat => hat.replace('.png', '')); +const hats = require('../../assets/json/hat'); +const hatsKeys = Object.keys(hats); module.exports = class HatCommand extends Command { constructor(client) { @@ -14,7 +13,7 @@ module.exports = class HatCommand extends Command { group: 'edit-avatar', memberName: 'hat', description: 'Draws a hat over a user\'s avatar.', - details: `**Hats:** ${hats.join(', ')}`, + details: `**Hats:** ${hatsKeys.join(', ')}`, throttling: { usages: 2, duration: 10 @@ -131,7 +130,7 @@ module.exports = class HatCommand extends Command { { key: 'type', type: 'string', - oneOf: ['random', ...hats], + oneOf: ['random', ...hatsKeys], parse: type => type.toLowerCase() }, { @@ -144,15 +143,17 @@ module.exports = class HatCommand extends Command { } async run(msg, { type, user }) { - if (type === 'random') type = hats[Math.floor(Math.random() * hats.length)]; + if (type === 'random') type = hatsKeys[Math.floor(Math.random() * hatsKeys.length)]; + const hat = hats[type]; const avatarURL = user.displayAvatarURL({ extension: 'png', size: 512 }); - const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'hat', `${type}.png`)); + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'hat', hat.file)); const { body } = await request.get(avatarURL); const avatar = await loadImage(body); const canvas = createCanvas(avatar.width, avatar.height); const ctx = canvas.getContext('2d'); ctx.drawImage(avatar, 0, 0); ctx.drawImage(base, 0, 0, avatar.width, avatar.height); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: `${type}-hat.png` }] }); + const comment = hat.comment.replace(/{{user}}/g, user.tag); + return msg.say(comment, { files: [{ attachment: canvas.toBuffer(), name: `${type}-hat.png` }] }); } };