-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeme.js
51 lines (49 loc) · 1.37 KB
/
meme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(() => {
const got = require("got");
const cheerio = require("cheerio");
const conf = require("./conf.json");
const { MessageEmbed } = require('discord.js');
const api_url = "http://api.memegenerator.net"
async function makeMeme(args) {
var mconf = conf["memegenerator.net"];
var text = args.join(" ").split("|");
// force a single line of text to be on the lower line
if(text.length == 1) {
text[1] = text[0];
text[0] = "";
}
var params = {
"username": mconf["username"],
"password": mconf["password"],
"apiKey": mconf["api_key"],
"generatorID": mconf["generatorID"],
"imageID": mconf["imageID"],
"text0": text[0],
"text1": text[1]
}
try {
let response = await got(api_url + "/Instance_Create", {
"method": "POST",
"searchParams": params
}).json()
if (!response["success"]) {
console.log(response)
return "*barf* :sick:"
}
const instanceUrl = response["result"]["instanceUrl"]
try {
response = await got(instanceUrl)
} catch (err) {
console.log(`Failed to load ${url}: ${err}`);
return "agruhm, phruhm! :coke:"
}
const $ = cheerio.load(response.body);
const jpgurl = $(".meme-image img").attr('src');
return new MessageEmbed().setImage(jpgurl)
} catch (err) {
console.log(`Failed to load ${url}: ${err}`)
return "*snort, snort* :coke:"
}
}
module.exports.makeMeme = makeMeme;
})();