Haha-Yes/commands/fun/spb.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

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-03-21 20:40:55 +01:00
args: [
{
id: 'link',
2019-06-23 03:41:59 +02:00
type: 'string',
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) {
if (!args.link || !args.link.includes('shitpostbot.com/template/')) {
2019-03-24 17:34:14 +01:00
return message.channel.send('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
}
let link = args.link.replace('template', 'preview');
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);
dest.on('finish', () => {
2019-11-04 14:41:45 +01:00
return message.channel.send({files: [`${os.tmpdir()}/${message.id}.jpg`]});
});
2019-03-21 20:40:55 +01:00
});
}
}
module.exports = spbCommand;