diff --git a/README.md b/README.md index 7e889678..2fa6c4de 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,7 @@ on the [home server](https://discord.gg/sbMe32W). * **shields-io-badge:** Creates a badge from shields.io. * **silhouette:** Draws a silhouette of an image or a user's avatar. * **sora-selfie:** Draws an image or a user's avatar behind Sora taking a selfie. +* **thug-life:** Draws "Thug Life" over an image or a user's avatar. * **tint:** Draws an image or a user's avatar but tinted a specific color. * **to-be-continued:** Draws an image with the "To Be Continued..." arrow. * **vietnam-flashbacks:** Edits Vietnam flashbacks behind an image or a user's avatar. @@ -288,7 +289,6 @@ on the [home server](https://discord.gg/sbMe32W). * **the-ultimate-tattoo:** Draws a user's avatar as "The Ultimate Tattoo". * **this-is-beautiful:** Draws a user's avatar over Gravity Falls' "Oh, this? This is beautiful." meme. * **this-is-worthless:** Draws a user's avatar over Gravity Falls' "Oh, this? This is worthless." meme. -* **thug-life:** Draws "Thug Life" over a user's avatar. * **triggered:** Draws a user's avatar over the "Triggered" meme. * **wanted:** Draws a user's avatar over a wanted poster. * **yu-gi-oh-token:** Draws a user's avatar over a blank Yu-Gi-Oh! Token card. diff --git a/assets/images/thug-life.png b/assets/images/thug-life.png index 70a5ddb0..bc74d46f 100644 Binary files a/assets/images/thug-life.png and b/assets/images/thug-life.png differ diff --git a/commands/avatar-edit/thug-life.js b/commands/avatar-edit/thug-life.js deleted file mode 100644 index 37c3b5b4..00000000 --- a/commands/avatar-edit/thug-life.js +++ /dev/null @@ -1,46 +0,0 @@ -const Command = require('../../structures/Command'); -const { createCanvas, loadImage } = require('canvas'); -const request = require('node-superfetch'); -const path = require('path'); -const { greyscale } = require('../../util/Canvas'); - -module.exports = class ThugLifeCommand extends Command { - constructor(client) { - super(client, { - name: 'thug-life', - group: 'avatar-edit', - memberName: 'thug-life', - description: 'Draws "Thug Life" over a user\'s avatar.', - 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 - } - ] - }); - } - - async run(msg, { user }) { - const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 }); - try { - const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'thug-life.png')); - 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); - greyscale(ctx, 0, 0, avatar.width, avatar.height); - ctx.drawImage(base, 0, 0, avatar.width, avatar.height); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'thug-life.png' }] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/image-edit/thug-life.js b/commands/image-edit/thug-life.js new file mode 100644 index 00000000..5d9587ac --- /dev/null +++ b/commands/image-edit/thug-life.js @@ -0,0 +1,50 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const path = require('path'); +const { greyscale } = require('../../util/Canvas'); + +module.exports = class ThugLifeCommand extends Command { + constructor(client) { + super(client, { + name: 'thug-life', + group: 'image-edit', + memberName: 'thug-life', + description: 'Draws "Thug Life" over an image or a user\'s avatar.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 }) + } + ] + }); + } + + async run(msg, { image }) { + try { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'thug-life.png')); + const { body } = await request.get(image); + const data = await loadImage(body); + const canvas = createCanvas(data.width, data.height); + const ctx = canvas.getContext('2d'); + ctx.drawImage(data, 0, 0); + greyscale(ctx, 0, 0, data.width, data.height); + const ratio = base.width / base.height; + const width = data.width / 2; + const height = Math.round(width / ratio); + ctx.drawImage(base, (data.width / 2) - (width / 2), data.height - height, width, height); + const attachment = canvas.toBuffer(); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'thug-life.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 88673228..c753e46f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "91.8.1", + "version": "91.8.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {