diff --git a/src/assets/png/bonk.png b/src/assets/png/bonk.png new file mode 100644 index 000000000..9a14cb4e9 Binary files /dev/null and b/src/assets/png/bonk.png differ diff --git a/src/commands/memes/bonk.js b/src/commands/memes/bonk.js new file mode 100644 index 000000000..fa63a941e --- /dev/null +++ b/src/commands/memes/bonk.js @@ -0,0 +1,23 @@ +const { CanvasTemplates, Command } = require('../../') +const { MessageAttachment } = require('discord.js') + +module.exports = class Bonk extends Command { + constructor (client) { + super({ + name: 'bonk', + aliases: ['bonkcheems', 'bonkdoge', 'bcheems', 'bdoge'], + category: 'images', + requirements: { canvasOnly: true }, + parameters: [{ + type: 'image', + missingError: 'commands:bonk.missingUser' + }] + }, client) + } + + async run ({ t, author, channel }, image) { + channel.startTyping() + const bonk = await CanvasTemplates.bonk(image) + channel.send(new MessageAttachment(bonk, 'bonk.png')).then(() => channel.stopTyping()) + } +} diff --git a/src/locales/en-US/commands.json b/src/locales/en-US/commands.json index c3b9836df..af519c866 100644 --- a/src/locales/en-US/commands.json +++ b/src/locales/en-US/commands.json @@ -1546,6 +1546,11 @@ "commandUsage": "", "missingImage": "You need to give me an image to generate the meme with." }, + "bonk": { + "commandDescription": "Generates a \"Bonk\" meme with the provided user's avatar image.", + "commandUsage": "", + "missingUser": "You need to give me a user to generate this meme with." + }, "color": { "commandDescription": "Gets information about a color.", "commandUsage": "", diff --git a/src/utils/CanvasTemplates.js b/src/utils/CanvasTemplates.js index 288cd5c3d..fb9e8410d 100644 --- a/src/utils/CanvasTemplates.js +++ b/src/utils/CanvasTemplates.js @@ -743,6 +743,23 @@ module.exports = class CanvasTemplates { return canvas.toBuffer() } + static async bonk (image) { + image = await Promise.all(image) + + const IMAGE_ASSETS = Promise.all([ + Image.from(Constants.BONK_TEMPLATE, true), + Image.from(image) + ]) + const [ template, avatarImage ] = await IMAGE_ASSETS + const AVATAR_WIDTH = avatarImage.width + const AVATAR_HEIGHT = avatarImage.height + const canvas = createCanvas(template.width, template.height) + const ctx = canvas.getContext('2d') + ctx.drawImage(avatarImage, 4 * AVATAR_WIDTH, AVATAR_HEIGHT, AVATAR_WIDTH, AVATAR_HEIGHT) + ctx.drawImage(template, 0, 0, template.width, template.height) + return canvas.toBuffer() + } + static gradient (colors, width, height) { // TODO: more gradient directions besides linear const canvas = createCanvas(width, height) diff --git a/src/utils/Constants.js b/src/utils/Constants.js index f43bcc1d4..6cd98f613 100644 --- a/src/utils/Constants.js +++ b/src/utils/Constants.js @@ -87,6 +87,7 @@ module.exports = { TRIGGERED_LABEL_PNG: 'src/assets/png/triggered_label.png', QUIERES_HAND_PNG: 'src/assets/png/quieres.png', HERE_WE_GO_AGAIN_PNG: 'src/assets/png/ashwga.png', + BONK_TEMPLATE: 'src/assets/png/bonk.png', KANNA_PAPER_TEMPLATE: 'src/assets/png/kanna_paper_template.png', PRESIDENTIAL_ALERT_TEMPLATE: 'src/assets/jpg/presidential_alert.jpg', // Backgrounds