Haha-Yes/commands/fun/asciify.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-05-18 16:09:32 +02:00
const { Command } = require('discord-akairo');
2020-07-16 09:22:17 +02:00
const attachment = require('../../utils/attachment');
const os = require('os');
const fs = require('fs');
2019-05-18 16:09:32 +02:00
const asciify = require('asciify-image');
let options = {
fit: 'box',
width: 200,
height: 50,
color: false
};
class asciifyCommand extends Command {
constructor() {
super('asciify', {
aliases: ['asciify'],
category: 'fun',
2019-11-09 12:04:01 +01:00
clientPermissions: ['SEND_MESSAGES'],
2020-07-16 09:22:17 +02:00
args: [
{
id: 'link',
type: 'url',
}
],
2019-05-18 16:09:32 +02:00
cooldown: 600000,
ratelimit: 2,
description: {
2020-06-15 17:56:51 +02:00
content: 'Transform your image into ASCII! (This can be a bit spammy, so be careful!)',
2019-05-18 16:09:32 +02:00
usage: '[image in attachment]',
examples: ['image in attachment']
}
});
}
2020-07-16 09:22:17 +02:00
async exec(message, args) {
let url;
2019-05-18 16:09:32 +02:00
2020-07-16 09:22:17 +02:00
if (args.link)
url = args.link.href;
else
url = await attachment(message);
2019-05-18 16:09:32 +02:00
2020-07-16 09:22:17 +02:00
return asciify(url, options, function (err, asciified) {
2019-05-18 16:09:32 +02:00
if (err) throw err;
// Print to console
2020-07-16 09:22:17 +02:00
fs.writeFile(`${os.tmpdir()}/${message.id}ascii.txt`, asciified, function (err) {
if (err) {
console.log(err);
}
return message.channel.send({files: [`${os.tmpdir()}/${message.id}ascii.txt`]});
});
//return message.channel.send(asciified, { split: true, code: true });
2019-05-18 16:09:32 +02:00
});
}
}
module.exports = asciifyCommand;