diff --git a/commands/edit-image/ascii.js b/commands/edit-image/ascii.js new file mode 100644 index 00000000..cee18255 --- /dev/null +++ b/commands/edit-image/ascii.js @@ -0,0 +1,54 @@ +const Command = require('../../structures/Command'); +const { loadImage } = require('canvas'); +const imageToAscii = require('image-to-ascii'); +const request = require('node-superfetch'); + +module.exports = class AsciiCommand extends Command { + constructor(client) { + super(client, { + name: 'ascii', + group: 'edit-image', + memberName: 'ascii', + description: 'Draws an image or a user\'s avatar but with ascii.', + throttling: { + usages: 1, + duration: 15 + }, + args: [ + { + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image-or-avatar', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) + } + ] + }); + } + + async run(msg, { image }) { + try { + const { body } = await request.get(image); + const asciiImg = await this.ascii(body); + return msg.code(null, asciiImg); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + async ascii(image) { + const { width, height } = await loadImage(image); + const options = { + colored: false, + size: { + height: height >= width ? 25 : undefined, + width: width > height ? 25 : undefined + } + }; + return new Promise((res, rej) => { + imageToAscii(image, options, (err, converted) => { + if (err) return rej(err); + return res(converted); + }); + }); + } +}; diff --git a/package.json b/package.json index 894f4d37..a8e2680f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "132.9.0", + "version": "132.10.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { @@ -55,9 +55,10 @@ "gifencoder": "^2.0.1", "gm": "^1.23.1", "html-entities": "^2.1.1", + "image-to-ascii": "^3.0.13", "ioredis": "^4.24.2", "js-beautify": "^1.13.5", - "js-chess-engine": "^0.10.0", + "js-chess-engine": "^0.11.0", "kuroshiro": "^1.1.2", "kuroshiro-analyzer-kuromoji": "^1.1.0", "mathjs": "^9.3.0", @@ -74,7 +75,7 @@ "tesseract.js": "^2.1.4", "text-diff": "^1.0.1", "tictactoe-minimax-ai": "^1.2.1", - "user-agents": "^1.0.595", + "user-agents": "^1.0.597", "valid-url": "^1.0.9", "winston": "^3.3.3", "ytdl-core": "^4.5.0"