-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
79 lines (72 loc) · 2.28 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const http = require('http');
const { Client, MessageAttachment } = require('discord.js');
const config = require('./config');
const client = new Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
const sendMeme = (res) => {
let str = '';
res.on('data', (chunk) => {
str += chunk;
});
res.on('end', () => {
const fullResponse = JSON.parse(str);
msg.channel.send(fullResponse.url);
});
}
/* This send a random meme from a list */
const sendRandomMeme = (res) => {
let str = '';
res.on('data', (chunk) => {
str += chunk;
});
res.on('end', () => {
const fullResponse = JSON.parse(str);
const keys = Object.keys(fullResponse);
const randomKey = keys[Math.floor(Math.random() * keys.length)];
const selectedMeme = fullResponse[randomKey];
msg.channel.send(selectedMeme.url);
});
}
const message = msg.content.toLowerCase();
if (message === 'send meme') {
http.get({
hostname: config.apiHost,
port: config.apiPort,
path: '/memes/new'
}, sendMeme);
} else if (message === 'send hot meme') {
http.get({
hostname: config.apiHost,
port: config.apiPort,
path: 'memes/hot'
}, sendMeme)
} else if (message === 'send wholesome meme') {
http.get({
hostname: config.apiHost,
port: config.apiPort,
path: 'memes/wholesomememes'
}, sendRandomMeme)
} else if (message === 'send dank meme') {
http.get({
hostname: config.apiHost,
port: config.apiPort,
path: 'memes/dankmemes'
}, sendRandomMeme)
} else if (message === 'send anime meme') {
http.get({
hostname: config.apiHost,
port: config.apiPort,
path: 'memes/goodanimemes'
}, sendRandomMeme)
} else if (message === 'send girl with mimi') {
http.get({
hostname: config.apiHost,
port: config.apiPort,
path: 'memes/kemonomimi'
}, sendRandomMeme)
}
});
client.login(config.token);