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
80
81
82
83
84
85
86
87
88
const dotenv = require("dotenv");
const express = require("express");
const app = express();
const Discord = require('discord.js');
const client = new Discord.Client();
app.listen(() => console.log("Server started"));
app.use('/ping', (req, res) => {
res.send(new Date());
});
app.use('/', express.static(__dirname + '/client/'));
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity('$help', { type: 'playing' });
setInterval(() => {
const channel = client.channels.get("509221147880062976");
channel.send("Meme time!!").then(async msg => {
await commands.meme.run(["general"], msg);
});
}, 1000 * 60 * 30)
});
const commands = require('./commands.js');
const admin = require('./admin.js');
const prefix = require('./prefix.js');
const admins = [
"439052807790657557"
];
const memeChannels = [
"509221125541330954",
"509221147880062976"
]
client.on('message', async msg => {
if (!msg.author.bot) {
if (memeChannels.includes(msg.channel.id))
if (msg.attachments.size > 0)
if (!msg.member.roles.has("509316148186316800")) {
msg.member.addRole("509316148186316800");
msg.channel.send(`Congratz <@${msg.author.id}>, you're officially a memer!`);
}
if (msg.content.startsWith(prefix.g(msg))) {
const params = lex(msg.content.substring(prefix.g(msg).length));
const cmd = params
.shift()
.toLowerCase()
if (commands[cmd]) {
const result = await commands[cmd].run(params, msg);
if (result) msg.channel.send(result)
.then(() => { }, rej => msg.author.send(result));
} else if (admin[cmd] && admins.includes(msg.author.id)) {
admin[cmd](params, msg, client);
} else msg.channel.send("Invalid command: " + cmd + "\nType `" + prefix.g(msg) + "help` for help");
}
}
});
client.login(process.env.token);
function lex(msg) {
const params = [];
let tmp = '';
let inQuotes = false;
for (let c of msg) {
if (c == '`') inQuotes = !inQuotes;
else if (c == ' ' && !inQuotes) {
if (tmp.length) params.push(tmp);
tmp = '';
} else tmp += c;
}
if (tmp.length) params.push(tmp);
return params;
}