diff --git a/README.md b/README.md index 8633c747..e112a296 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 390 +Total: 391 ### Utility: @@ -429,6 +429,7 @@ Total: 390 * **newspaper:** Creates a fake newspaper with the headline and body of your choice. * **pixelize:** Draws an image or a user's avatar pixelized. * **pokemon-fusion:** Fuses two Generation I Pokémon together. +* **police-tape:** Draws police tape over an image or a user's avatar. * **rainbow:** Draws a rainbow over an image or a user's avatar. * **rejected:** Draws a "rejected" stamp over an image or a user's avatar. * **robohash:** Creates a robot based on the text you provide. @@ -962,6 +963,8 @@ here. - [Perspective API](https://www.perspectiveapi.com/#/) * severe-toxicity (API) * toxicity (API) +- [PNG Arts](https://www.pngarts.com/) + * police-tape ([Image](https://www.pngarts.com/explore/94078)) - [pngimg.com](https://pngimg.com/) * thug-life ([Image](http://pngimg.com/download/58231)) - [Platinum Designz](http://store.platinumdesignz.com/) diff --git a/assets/images/police-tape.png b/assets/images/police-tape.png new file mode 100644 index 00000000..02ba1e7d Binary files /dev/null and b/assets/images/police-tape.png differ diff --git a/commands/edit-image/police-tape.js b/commands/edit-image/police-tape.js new file mode 100644 index 00000000..d268a1b1 --- /dev/null +++ b/commands/edit-image/police-tape.js @@ -0,0 +1,56 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const path = require('path'); +const { centerImage } = require('../../util/Canvas'); + +module.exports = class PoliceTapeCommand extends Command { + constructor(client) { + super(client, { + name: 'police-tape', + aliases: ['caution-tape', 'caution'], + group: 'edit-image', + memberName: 'police tape', + description: 'Draws police tape over an image or a user\'s avatar.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + credit: [ + { + name: 'PNG Arts', + url: 'https://www.pngarts.com/', + reason: 'Image', + reasonURL: 'https://www.pngarts.com/explore/94078' + } + ], + args: [ + { + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) + } + ] + }); + } + + async run(msg, { image }) { + try { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'police-tape.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); + const { x, y, width, height } = centerImage(base, data); + ctx.drawImage(base, x, y, 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: 'police-tape.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 e99e3abd..5eb7d286 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "113.4.0", + "version": "113.5.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {