diff --git a/assets/images/look-at-this-photograph.png b/assets/images/look-at-this-photograph.png new file mode 100644 index 00000000..0ca2400d Binary files /dev/null and b/assets/images/look-at-this-photograph.png differ diff --git a/commands/avatar-edit/look-at-this-photograph.js b/commands/avatar-edit/look-at-this-photograph.js new file mode 100644 index 00000000..78f38dca --- /dev/null +++ b/commands/avatar-edit/look-at-this-photograph.js @@ -0,0 +1,51 @@ +const { Command } = require('discord.js-commando'); +const { createCanvas, loadImage } = require('canvas'); +const snekfetch = require('snekfetch'); +const path = require('path'); + +module.exports = class LookAtThisPhotographCommand extends Command { + constructor(client) { + super(client, { + name: 'look-at-this-photograph', + aliases: ['photo', 'nickelback'], + group: 'avatar-edit', + memberName: 'look-at-this-photograph', + description: 'Draws a user\'s avatar over Nickelback\'s photograph.', + throttling: { + usages: 1, + duration: 15 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'user', + prompt: 'Which user would you like to edit the avatar of?', + type: 'user', + default: '' + } + ] + }); + } + + async run(msg, { user }) { + if (!user) user = msg.author; + const avatarURL = user.displayAvatarURL({ + format: 'png', + size: 256 + }); + try { + const canvas = createCanvas(620, 349); + const ctx = canvas.getContext('2d'); + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'look-at-this-photograph.png')); + const { body } = await snekfetch.get(avatarURL); + const avatar = await loadImage(body); + ctx.drawImage(base, 0, 0); + ctx.rotate(-13.5 * (Math.PI / 180)); + ctx.drawImage(avatar, 321, 147, 175, 125); + ctx.rotate(13.5 * (Math.PI / 180)); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'look-at-this-photograph.png' }] }); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 9befd8d4..bc2d65d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "44.1.0", + "version": "44.2.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {