diff --git a/README.md b/README.md index 79e99872..8e8600a6 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Xiao is a Discord bot coded in JavaScript with 7. Run `npm i -g pm2` to install PM2. 8. Run `pm2 start Xiao.js --name xiao` to run the bot. -## Commands (334) +## Commands (335) ### Utility: * **eval:** Executes JavaScript code. @@ -337,6 +337,7 @@ Xiao is a Discord bot coded in JavaScript with * **look-at-this-photograph:** Draws a user's avatar over Nickelback's photograph. * **look-what-karen-have:** Draws a user's avatar over Karen's piece of paper. * **rip:** Draws a user's avatar over a gravestone. +* **sip:** Draws a user's avatar sipping tea. * **steam-card:** Draws a user's avatar on a Steam Trading Card. * **steam-now-playing:** Draws a user's avatar and the game of your choice over a Steam "now playing" notification. * **triggered:** Draws a user's avatar over the "Triggered" meme. diff --git a/assets/images/sip.png b/assets/images/sip.png new file mode 100644 index 00000000..99e6dea2 Binary files /dev/null and b/assets/images/sip.png differ diff --git a/commands/avatar-edit/sip.js b/commands/avatar-edit/sip.js new file mode 100644 index 00000000..6ca887b3 --- /dev/null +++ b/commands/avatar-edit/sip.js @@ -0,0 +1,59 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const path = require('path'); + +module.exports = class SipCommand extends Command { + constructor(client) { + super(client, { + name: 'sip', + aliases: ['tea'], + group: 'avatar-edit', + memberName: 'sip', + description: 'Draws a user\'s avatar sipping tea.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'user', + prompt: 'Which user would you like to edit the avatar of?', + type: 'user', + default: msg => msg.author + }, + { + key: 'direction', + prompt: 'What direction should the avatar face?', + type: 'string', + oneOf: ['left', 'right'], + default: 'left', + parse: direction => direction.toLowerCase() + } + ] + }); + } + + async run(msg, { user, direction }) { + const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 }); + try { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sip.png')); + const { body } = await request.get(avatarURL); + const avatar = await loadImage(body); + const canvas = createCanvas(base.width, base.height); + const ctx = canvas.getContext('2d'); + ctx.fillRect(0, 0, base.width, base.height); + if (direction === 'right') { + ctx.translate(base.width, 0); + ctx.scale(-1, 1); + } + ctx.drawImage(avatar, 0, 0, 512, 512); + if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.drawImage(base, 0, 0); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sip.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 5bb54f28..bad946f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "101.3.0", + "version": "101.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {