mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-12 00:04:48 +02:00
Ascii Command
This commit is contained in:
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "132.9.0",
|
"version": "132.10.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -55,9 +55,10 @@
|
|||||||
"gifencoder": "^2.0.1",
|
"gifencoder": "^2.0.1",
|
||||||
"gm": "^1.23.1",
|
"gm": "^1.23.1",
|
||||||
"html-entities": "^2.1.1",
|
"html-entities": "^2.1.1",
|
||||||
|
"image-to-ascii": "^3.0.13",
|
||||||
"ioredis": "^4.24.2",
|
"ioredis": "^4.24.2",
|
||||||
"js-beautify": "^1.13.5",
|
"js-beautify": "^1.13.5",
|
||||||
"js-chess-engine": "^0.10.0",
|
"js-chess-engine": "^0.11.0",
|
||||||
"kuroshiro": "^1.1.2",
|
"kuroshiro": "^1.1.2",
|
||||||
"kuroshiro-analyzer-kuromoji": "^1.1.0",
|
"kuroshiro-analyzer-kuromoji": "^1.1.0",
|
||||||
"mathjs": "^9.3.0",
|
"mathjs": "^9.3.0",
|
||||||
@@ -74,7 +75,7 @@
|
|||||||
"tesseract.js": "^2.1.4",
|
"tesseract.js": "^2.1.4",
|
||||||
"text-diff": "^1.0.1",
|
"text-diff": "^1.0.1",
|
||||||
"tictactoe-minimax-ai": "^1.2.1",
|
"tictactoe-minimax-ai": "^1.2.1",
|
||||||
"user-agents": "^1.0.595",
|
"user-agents": "^1.0.597",
|
||||||
"valid-url": "^1.0.9",
|
"valid-url": "^1.0.9",
|
||||||
"winston": "^3.3.3",
|
"winston": "^3.3.3",
|
||||||
"ytdl-core": "^4.5.0"
|
"ytdl-core": "^4.5.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user