Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Add 'Bonk' meme template generator #1253

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/assets/png/bonk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions src/commands/memes/bonk.js
Original file line number Diff line number Diff line change
@@ -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())
}
}
5 changes: 5 additions & 0 deletions src/locales/en-US/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,11 @@
"commandUsage": "<image>",
"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": "<user>",
"missingUser": "You need to give me a user to generate this meme with."
},
"color": {
"commandDescription": "Gets information about a color.",
"commandUsage": "<color>",
Expand Down
17 changes: 17 additions & 0 deletions src/utils/CanvasTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/utils/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down