-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
60 lines (45 loc) · 1.47 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
const config = require("./config.json");
const { checkIgnored, checkAllowed } = require("./lib/utils");
const { Responder } = require("./lib/Responder.js");
const responder = new Responder();
const { Aggregator } = require("./lib/Aggregator.js");
const aggregator = new Aggregator();
const Discord = require("discord.js");
const client = new Discord.Client();
client.login(config.token);
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on("disconnect", () => {
console.warn(`We were disconnected`);
client.login(config.token);
});
client.on("message", async message => {
const isIgnored = checkIgnored(message, client);
const isAllowed = checkAllowed(message, config.channel);
if (isIgnored) return null;
/// get response
const command = message.content;
const store = aggregator.getStore();
const { foundResponse, response } = responder.getResponse(command, store);
if (foundResponse) {
const { text, reaction } = response;
const foundText = !!text;
const foundReaction = !!reaction;
if (isAllowed) {
if (foundReaction) await message.react(reaction);
if (foundText) await message.reply(response.text);
} else {
if (foundText) await message.author.send(response.text);
await message.react("👋");
setTimeout(() => {
message.delete();
}, 3000);
}
} else {
await message.react("❓");
setTimeout(() => {
message.delete();
}, 3000);
}
});