forked from reactiflux/reactibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
133 lines (111 loc) · 3.54 KB
/
index.js
File metadata and controls
133 lines (111 loc) · 3.54 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require("dotenv").config();
const discord = require("discord.js");
const fetch = require("node-fetch");
const { logger, stdoutLog, channelLog } = require("./features/log");
const codeblock = require("./features/codeblock").default;
const qna = require("./features/qna").default;
const jobs = require("./features/jobs").default;
const autoban = require("./features/autoban").default;
const commands = require("./features/commands").default;
const witInvite = require("./features/wit-invite").default;
const stats = require("./features/stats").default;
const emojiMod = require("./features/emojiMod").default;
const bot = new discord.Client({ partials: ["MESSAGE", "CHANNEL"] });
bot.login(process.env.DISCORD_HASH);
const channelHandlers = {
channels: {},
addHandler: (channelId, channelHandler) => {
const handlers = channelHandlers.channels[channelId] || [];
handlers.push(channelHandler);
channelHandlers.channels[channelId] = handlers;
},
handle: (msg, user) => {
const channel = msg.channel.id;
if (channelHandlers.channels[channel]) {
channelHandlers.channels[channel].forEach(
handler =>
handler.handleMessage &&
handler.handleMessage.call(this, {
msg,
user
})
);
}
if (channelHandlers.channels["*"]) {
channelHandlers.channels["*"].forEach(handler => {
handler.handleMessage &&
handler.handleMessage.call(this, {
msg,
user
});
});
}
},
handleReaction: (reaction, user) => {
const channel = reaction.message.channel.id;
if (channelHandlers.channels[channel]) {
channelHandlers.channels[channel].forEach(
handler =>
handler.handleReaction &&
handler.handleReaction.call(this, {
reaction,
user
})
);
}
if (channelHandlers.channels["*"]) {
channelHandlers.channels["*"].forEach(
handler =>
handler.handleReaction &&
handler.handleReaction.call(this, {
reaction,
user
})
);
}
}
};
logger.add(stdoutLog);
logger.add(channelLog(bot, "479862475047567361"));
// Amplitude metrics
stats(bot);
// reactiflux
channelHandlers.addHandler("103882387330457600", jobs);
channelHandlers.addHandler("541673256596537366", witInvite); // #women-in-tech
channelHandlers.addHandler("106168778013822976", qna); // reactiflux-admin
channelHandlers.addHandler("193117606629081089", qna); // #q&a
// btm server
channelHandlers.addHandler("479862475047567361", qna); // #general
// common
channelHandlers.addHandler("*", commands);
// channelHandlers.addHandler('*', codeblock);
channelHandlers.addHandler("*", autoban);
channelHandlers.addHandler("*", emojiMod(bot));
bot.on("messageReactionAdd", async (reaction, user) => {
if (reaction.message.partial) {
try {
await reaction.message.fetch();
} catch (error) {
console.log("Something went wrong when fetching the message: ", error);
}
}
channelHandlers.handleReaction(reaction, user);
});
bot.on("message", msg => {
if (msg.author.id === bot.user.id) return;
channelHandlers.handle(msg, msg.author);
});
logger.log("INI", "Bootstrap complete");
bot.on("ready", () => {
Array.from(bot.guilds.cache).forEach(guild => {
logger.log("INI", `Bot connected to Discord server: ${guild.name}`);
});
bot.user.setActivity("for !commands", { type: "WATCHING" });
});
bot.on("error", err => {
try {
logger.log("ERR", err.message);
} catch (e) {
logger.log("ERR", err);
}
});