This commit is contained in:
Daniel Odendahl Jr
2017-10-09 22:15:56 +00:00
parent 212d9586da
commit 2e4077236b
3 changed files with 12 additions and 25 deletions
+2 -1
View File
@@ -23,5 +23,6 @@
"https://i.imgur.com/kG6Qp9U.jpg", "https://i.imgur.com/kG6Qp9U.jpg",
"https://i.imgur.com/JK66QjX.jpg", "https://i.imgur.com/JK66QjX.jpg",
"https://i.imgur.com/fFsF6m7.jpg", "https://i.imgur.com/fFsF6m7.jpg",
"https://i.imgur.com/YqZmeyA.jpg" "https://i.imgur.com/YqZmeyA.jpg",
"https://i.imgur.com/StoIQzc.jpg"
] ]
+9 -23
View File
@@ -1,7 +1,5 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { list } = require('../../structures/Util');
const { IMGFLIP_USER, IMGFLIP_PASS } = process.env;
module.exports = class MemeCommand extends Command { module.exports = class MemeCommand extends Command {
constructor(client) { constructor(client) {
@@ -16,27 +14,27 @@ module.exports = class MemeCommand extends Command {
key: 'type', key: 'type',
prompt: 'What meme type do you want to use?', prompt: 'What meme type do you want to use?',
type: 'string', type: 'string',
parse: type => type.toLowerCase() parse: type => encodeURIComponent(type)
}, },
{ {
key: 'top', key: 'top',
prompt: 'What should the top row of the meme to be?', prompt: 'What should the top row of the meme to be?',
type: 'string', type: 'string',
default: ' ',
validate: top => { validate: top => {
if (top.length < 200) return true; if (top.length < 200) return true;
return 'Invalid top text, please keep the top text under 200 characters.'; return 'Invalid top text, please keep the top text under 200 characters.';
} },
parse: top => encodeURIComponent(top)
}, },
{ {
key: 'bottom', key: 'bottom',
prompt: 'What should the bottom row of the meme to be?', prompt: 'What should the bottom row of the meme to be?',
type: 'string', type: 'string',
default: ' ',
validate: bottom => { validate: bottom => {
if (bottom.length < 200) return true; if (bottom.length < 200) return true;
return 'Invalid bottom text, please keep the bottom text under 200 characters.'; return 'Invalid bottom text, please keep the bottom text under 200 characters.';
} },
parse: bottom => encodeURIComponent(bottom)
} }
] ]
}); });
@@ -44,22 +42,10 @@ module.exports = class MemeCommand extends Command {
async run(msg, { type, top, bottom }) { async run(msg, { type, top, bottom }) {
try { try {
const memes = await snekfetch.get('https://api.imgflip.com/get_memes'); const search = await snekfetch.get(`https://memegen.link/api/search/${type}`);
const memeList = memes.body.data.memes; if (!search.body.length) return msg.say('Could not find any results.');
if (type === 'list') return msg.say(list(memeList.map(meme => meme.name), 'or'), { split: { char: ' ' } }); const { body } = await snekfetch.get(search.body[0].template.blank.replace(/\/_/, `/${top}/${bottom}`));
if (!memeList.some(meme => meme.name.toLowerCase() === type)) { return msg.say({ files: [{ attachment: body, name: 'meme.jpg' }] });
return msg.say(`Invalid type, please use ${msg.usage('list')}.`);
}
const { body } = await snekfetch
.post('https://api.imgflip.com/caption_image')
.query({
template_id: memeList.find(meme => meme.name.toLowerCase() === type).id,
username: IMGFLIP_USER,
password: IMGFLIP_PASS,
text0: top,
text1: bottom
});
return msg.say({ files: [body.data.url] });
} catch (err) { } catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiaobot", "name": "xiaobot",
"version": "46.1.2", "version": "46.1.3",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Shard.js", "main": "Shard.js",
"scripts": { "scripts": {