-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (38 loc) · 1.34 KB
/
Copy pathindex.js
File metadata and controls
44 lines (38 loc) · 1.34 KB
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
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config/config.json');
const report = require('./src/report.js');
const currentReports = new Map();
const usersOnCooldown = new Map();
client.login(config.token).then(() => {
console.log('Successfully connected to Discord!');
}).catch(error => {
console.error(error);
console.log('Shutting down process since unable to connect to Discord!');
process.exit(1);
});
if (config.questions.length === 0) {
console.log("Questions can't be empty!");
process.exit(1);
return;
}
client.on('message', message => {
if (message.channel.type != 'dm' || message.author.bot) return;
if (usersOnCooldown.has(message.author.id)) {
let value = usersOnCooldown.get(message.author.id);
if (Date.now() - value >= config.report_cooldown_in_seconds * 1000) {
usersOnCooldown.delete(message.author.id);
} else {
report.handleCooldown(value, message, config);
return;
}
}
if (currentReports.has(message.author.id)) report.handlePostReport(currentReports, usersOnCooldown, message, config, client);
else report.handleFirstBotReply(currentReports, message, config);
});
setInterval(() => {
usersOnCooldown.forEach((value, key) => {
if (Date.now() - value < config.report_cooldown_in_seconds * 1000) return;
usersOnCooldown.delete(key);
});
}, 5000);