2019-03-21 20:40:55 +01:00
|
|
|
const { Command } = require('discord-akairo');
|
|
|
|
const fs = require('fs');
|
|
|
|
const fetch = require('node-fetch');
|
2019-11-04 14:41:45 +01:00
|
|
|
const os = require('os');
|
2019-03-21 20:40:55 +01:00
|
|
|
|
|
|
|
class spbCommand extends Command {
|
|
|
|
constructor() {
|
|
|
|
super('spb', {
|
2019-03-22 00:11:34 +01:00
|
|
|
aliases: ['spb'],
|
2019-03-30 04:43:44 +01:00
|
|
|
category: 'fun',
|
2019-11-09 12:04:01 +01:00
|
|
|
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
|
2019-03-21 20:40:55 +01:00
|
|
|
args: [
|
|
|
|
{
|
|
|
|
id: 'link',
|
2020-07-16 09:24:44 +02:00
|
|
|
type: 'url',
|
2019-06-23 03:41:59 +02:00
|
|
|
prompt: {
|
|
|
|
start: 'Need a shitpostbot5000 template link!',
|
|
|
|
}
|
2019-03-21 20:40:55 +01:00
|
|
|
}
|
|
|
|
],
|
|
|
|
description: {
|
|
|
|
content: 'Generate a meme from template you send with spb5k (ONLY WORK WITH TEMPLATES)',
|
|
|
|
usage: '',
|
|
|
|
examples: ['']
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async exec(message, args) {
|
2020-07-16 09:24:44 +02:00
|
|
|
if (!args.link || !args.link.href.includes('shitpostbot.com/template/')) {
|
2021-07-23 04:19:47 +02:00
|
|
|
return message.reply('Need a Shitpostbot 5000 template link!\nYou can find them here! <https://www.shitpostbot.com/gallery/templates>');
|
2019-03-21 20:40:55 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 09:24:44 +02:00
|
|
|
let link = args.link.href.replace('template', 'preview');
|
2019-03-21 20:40:55 +01:00
|
|
|
|
|
|
|
fetch(link)
|
|
|
|
.then(res => {
|
2019-11-04 14:41:45 +01:00
|
|
|
const dest = fs.createWriteStream(`${os.tmpdir()}/${message.id}.jpg`);
|
2019-03-21 20:40:55 +01:00
|
|
|
res.body.pipe(dest);
|
2019-03-21 20:57:51 +01:00
|
|
|
dest.on('finish', () => {
|
2021-07-23 04:19:47 +02:00
|
|
|
return message.reply({files: [`${os.tmpdir()}/${message.id}.jpg`]});
|
2019-03-21 20:57:51 +01:00
|
|
|
});
|
2019-03-21 20:40:55 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = spbCommand;
|