Ascii Command

This commit is contained in:
Dragon Fire
2021-03-21 10:44:30 -04:00
parent e512c52e0f
commit 1b971f583c
2 changed files with 58 additions and 3 deletions
+54
View File
@@ -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);
});
});
}
};
+4 -3
View File
@@ -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"