Haha-Yes/commands/images/paint.js

51 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2019-02-08 18:46:59 +01:00
const { Command } = require('discord-akairo');
2020-07-16 09:22:17 +02:00
const attachment = require('../../utils/attachment');
2019-02-08 18:46:59 +01:00
const { createCanvas, loadImage } = require('canvas');
const superagent = require('superagent');
class paintCommand extends Command {
constructor() {
super('paint', {
aliases: ['paint'],
category: 'images',
2019-11-09 12:04:01 +01:00
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
2019-02-08 18:46:59 +01:00
args: [
{
id: 'image',
type: 'string',
optional: true,
}
]
});
}
async exec(message, args) {
let image = args.image;
2020-07-16 09:22:17 +02:00
if (!image)
image = await attachment(message);
else if (!image)
2019-02-08 18:46:59 +01:00
image = message.author.displayAvatarURL().replace('webp', 'png');
2020-07-16 09:22:17 +02:00
else if(image.endsWith('gif'))
2019-02-08 18:46:59 +01:00
return message.channel.send('Gif dosent work, sorry');
2020-07-16 09:22:17 +02:00
2019-02-08 18:46:59 +01:00
let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>')
2019-02-08 18:46:59 +01:00
2019-02-13 02:17:18 +01:00
const canvas = createCanvas(488, 400);
2019-02-08 18:46:59 +01:00
const ctx = canvas.getContext('2d');
2019-02-13 01:53:50 +01:00
const background = await loadImage(image).catch(() => {
return message.channel.send('An error as occurred, please try again. Did you load a correct image?');
2019-02-08 18:46:59 +01:00
});
2019-02-13 02:17:18 +01:00
ctx.drawImage(background, 65, 30, 405, 280);
2019-02-13 01:53:50 +01:00
const { body: buffer } = await superagent.get('https://cdn.discordapp.com/attachments/488483518742134794/542633779601342476/260293545019212.png');
2019-02-08 18:46:59 +01:00
const bg = await loadImage(buffer);
2019-02-13 01:53:50 +01:00
ctx.drawImage(bg, 0, 0, canvas.width, canvas.height);
2019-02-08 18:46:59 +01:00
loadingmsg.delete();
2019-02-08 18:46:59 +01:00
message.channel.send({files: [canvas.toBuffer()]}).catch(() => {
message.channel.send('an error as occurred. Check the bot/channel permissions');
2019-02-08 18:46:59 +01:00
});
}
}
module.exports = paintCommand;