This repository has been archived by the owner on Aug 31, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
cajunbot.js
67 lines (58 loc) · 1.91 KB
/
cajunbot.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
require('dotenv').config()
var fs = require('fs');
//jace was here 02.05.2021
var Discord = require('discord.js');
var client = new Discord.Client();
var token = process.env.DISCORD_BOT_TOKEN
client.login(token);
var site = require('./site');
var responses = {};
var reactions = {};
var responsesDirectory = './responses/';
var reactionDirectory = "./reactions/";
fs.readdir(responsesDirectory, function (err, files) {
files.forEach(function (file) {
try {
responses[file] = require(responsesDirectory + file);
} catch (e) {
// console.log(e);
}
});
});
fs.readdir(reactionDirectory, function (err, files) {
files.forEach(function (file) {
try {
reactions[file] = require(reactionDirectory + file);
} catch (e) {
// console.log(e);
}
});
});
client.on("message", function (msg) {
for (var response in responses) {
responses[response].command({client, msg, responses, reactions});
}
});
client.on('ready', () => { // When the bot is ready
console.log('CajonBot Ready!'); // Log "Ready!"
//require('./integrations/timetable').start(bot).command();//disabled after token was revoked
//require('./integrations/errorkb').start(client, true, true); //disabled after hi moved to support
});
client.on("messageReactionAdd", async (reaction, user) => {
console.log(reaction);
// When we receive a reaction we check if the reaction is partial or not
if (reaction.partial) {
// If the message this reaction belongs to was removed the fetching might result in an API error, which we need to handle
try {
await reaction.fetch();
} catch (error) {
console.error("Something went wrong when fetching the message: ", error);
// Return as `reaction.message.author` may be undefined/null
return;
}
}
for (var reactionE in reactions) {
reactions[reactionE].react(reaction);
}
});
process.on('unhandledRejection', console.error);