diff --git a/assets/json/xiao.json b/assets/json/xiao.json index 1fa31c16..7bbf1512 100644 --- a/assets/json/xiao.json +++ b/assets/json/xiao.json @@ -23,5 +23,6 @@ "https://i.imgur.com/kG6Qp9U.jpg", "https://i.imgur.com/JK66QjX.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" ] diff --git a/commands/image-edit/meme.js b/commands/image-edit/meme.js index 00ac7a60..dbc8248c 100644 --- a/commands/image-edit/meme.js +++ b/commands/image-edit/meme.js @@ -1,7 +1,5 @@ const { Command } = require('discord.js-commando'); const snekfetch = require('snekfetch'); -const { list } = require('../../structures/Util'); -const { IMGFLIP_USER, IMGFLIP_PASS } = process.env; module.exports = class MemeCommand extends Command { constructor(client) { @@ -16,27 +14,27 @@ module.exports = class MemeCommand extends Command { key: 'type', prompt: 'What meme type do you want to use?', type: 'string', - parse: type => type.toLowerCase() + parse: type => encodeURIComponent(type) }, { key: 'top', prompt: 'What should the top row of the meme to be?', type: 'string', - default: ' ', validate: top => { if (top.length < 200) return true; return 'Invalid top text, please keep the top text under 200 characters.'; - } + }, + parse: top => encodeURIComponent(top) }, { key: 'bottom', prompt: 'What should the bottom row of the meme to be?', type: 'string', - default: ' ', validate: bottom => { if (bottom.length < 200) return true; 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 }) { try { - const memes = await snekfetch.get('https://api.imgflip.com/get_memes'); - const memeList = memes.body.data.memes; - if (type === 'list') return msg.say(list(memeList.map(meme => meme.name), 'or'), { split: { char: ' ' } }); - if (!memeList.some(meme => meme.name.toLowerCase() === type)) { - 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] }); + const search = await snekfetch.get(`https://memegen.link/api/search/${type}`); + if (!search.body.length) return msg.say('Could not find any results.'); + const { body } = await snekfetch.get(search.body[0].template.blank.replace(/\/_/, `/${top}/${bottom}`)); + return msg.say({ files: [{ attachment: body, name: 'meme.jpg' }] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/package.json b/package.json index ab53f2b5..44abd14e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "46.1.2", + "version": "46.1.3", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {