-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
275 lines (260 loc) · 8.68 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
const {
Client,
Events,
Partials,
Collection,
GatewayIntentBits,
} = require("discord.js");
const config = require("./config/config");
const colors = require("colors");
const { fetchReactions } = require("./commands/slash/General/avatemplate");
const { fetchReactions2 } = require("./commands/slash/General/avatemplate2");
const { fetchPvPReactions } = require("./commands/slash/General/pvptemplate");
const initializeDatabase = require("./database/database");
const mongoose = initializeDatabase();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildBans,
],
partials: [
Partials.Channel,
Partials.Message,
Partials.User,
Partials.GuildMember,
Partials.Reaction,
Partials.GuildScheduledEvent,
],
presence: {
activities: [
{
name: "Thinking About Albion Online",
type: 0,
},
],
status: "dnd",
},
});
// Host the bot:
require("http")
.createServer((req, res) => res.end("Ready."))
.listen(3000);
// Getting the bot token:
const AuthenticationToken = process.env.BotToken || config.Client.TOKEN;
if (!AuthenticationToken) {
console.warn(
"[CRASH] Authentication Token for Discord bot is required! Use Envrionment Secrets or config.js."
.red
);
return process.exit();
}
// Handler:
client.prefix_commands = new Collection();
client.slash_commands = new Collection();
client.user_commands = new Collection();
client.message_commands = new Collection();
client.modals = new Collection();
client.events = new Collection();
module.exports = client;
const handlers = [
"prefix",
"application_commands",
"modals",
"events",
"mongoose",
];
for (const file of handlers) {
require(`./handlers/${file}`)(client, config);
}
// Login to the bot:
client.login(AuthenticationToken).catch((err) => {
console.error("[CRASH] Something went wrong while connecting to your bot...");
console.error("[CRASH] Error from Discord API:" + err);
return process.exit();
});
// Handle errors:
process.on("unhandledRejection", async (err, promise) => {
console.error(`[ANTI-CRASH] Unhandled Rejection: ${err}`.red);
console.error(promise);
});
client.on("messageReactionAdd", async (reaction, user) => {
if (user.bot) return;
// mongodb
const db = mongoose.connection.useDb("AvaRaids");
const collectionmassage = db.collection("avaraids");
const messages = collectionmassage.find();
// For each message, check if it's still valid, and if so, continue to fetch reactions.
messages.forEach(async (messageData) => {
const now = new Date();
if (now < messageData.selectedDate) {
const channel = client.channels.cache.get(messageData.channelId); // replace with your channel ID
if (channel) {
const message = await channel.messages.fetch(messageData.messageId);
if (message) {
// Continue to fetch reactions and process them as you did before
fetchReactions(message);
}
}
} else {
// If the message is no longer valid, delete it from the database.
collectionmassage.deleteOne(
{ messageId: messageData.messageId },
function (err, res) {
if (err) throw err;
}
);
}
});
});
client.on("messageReactionRemove", async (reaction, user) => {
if (user.bot) return;
// mongodb
const db = mongoose.connection.useDb("AvaRaids");
const collectionmassage = db.collection("avaraids");
const messages = collectionmassage.find();
// For each message, check if it's still valid, and if so, continue to fetch reactions.
messages.forEach(async (messageData) => {
const now = new Date();
if (now < messageData.selectedDate) {
const channel = client.channels.cache.get(messageData.channelId); // replace with your channel ID
if (channel) {
const message = await channel.messages.fetch(messageData.messageId);
if (message) {
// Continue to fetch reactions and process them as you did before
fetchReactions(message);
}
}
} else {
// If the message is no longer valid, delete it from the database.
collectionmassage.deleteOne(
{ messageId: messageData.messageId },
function (err, res) {
if (err) throw err;
}
);
}
});
});
client.on("messageReactionAdd", async (reaction, user) => {
if (user.bot) return;
console.log("Index.js triggered");
// mongodb
const db = mongoose.connection.useDb("AvaRaids");
const collectionmassage = db.collection("avaraids");
const messages = collectionmassage.find();
// For each message, check if it's still valid, and if so, continue to fetch reactions.
messages.forEach(async (messageData) => {
const now = new Date();
if (now < messageData.selectedDate) {
const channel = client.channels.cache.get(messageData.channelId); // replace with your channel ID
if (channel) {
const message = await channel.messages.fetch(messageData.messageId);
if (message) {
// Continue to fetch reactions and process them as you did before
fetchReactions2(message);
}
}
} else {
// If the message is no longer valid, delete it from the database.
collectionmassage.deleteOne(
{ messageId: messageData.messageId },
function (err, res) {
if (err) throw err;
}
);
}
});
});
client.on("messageReactionRemove", async (reaction, user) => {
if (user.bot) return;
// mongodb
const db = mongoose.connection.useDb("AvaRaids");
const collectionmassage = db.collection("avaraids");
const messages = collectionmassage.find();
// For each message, check if it's still valid, and if so, continue to fetch reactions.
messages.forEach(async (messageData) => {
const now = new Date();
if (now < messageData.selectedDate) {
const channel = client.channels.cache.get(messageData.channelId); // replace with your channel ID
if (channel) {
const message = await channel.messages.fetch(messageData.messageId);
if (message) {
// Continue to fetch reactions and process them as you did before
fetchReactions2(message);
}
}
} else {
// If the message is no longer valid, delete it from the database.
collectionmassage.deleteOne(
{ messageId: messageData.messageId },
function (err, res) {
if (err) throw err;
}
);
}
});
});
client.on("messageReactionAdd", async (reaction, user) => {
if (user.bot) return;
// mongodb
const db = mongoose.connection.useDb("PvP");
const collectionmassage = db.collection("pvpraids");
const messages = collectionmassage.find();
// For each message, check if it's still valid, and if so, continue to fetch reactions.
messages.forEach(async (messageData) => {
const now = new Date();
if (now < messageData.selectedDate) {
const channel = client.channels.cache.get(messageData.channelId); // replace with your channel ID
if (channel) {
const message = await channel.messages.fetch(messageData.messageId);
if (message) {
// Continue to fetch reactions and process them as you did before
fetchPvPReactions(message);
}
}
} else {
// If the message is no longer valid, delete it from the database.
collectionmassage.deleteOne(
{ messageId: messageData.messageId },
function (err, res) {
if (err) throw err;
}
);
}
});
});
client.on("messageReactionRemove", async (reaction, user) => {
if (user.bot) return;
// mongodb
const db = mongoose.connection.useDb("PvP");
const collectionmassage = db.collection("pvpraids");
const messages = collectionmassage.find();
// For each message, check if it's still valid, and if so, continue to fetch reactions.
messages.forEach(async (messageData) => {
const now = new Date();
if (now < messageData.selectedDate) {
const channel = client.channels.cache.get(messageData.channelId); // replace with your channel ID
if (channel) {
const message = await channel.messages.fetch(messageData.messageId);
if (message) {
// Continue to fetch reactions and process them as you did before
fetchPvPReactions(message);
}
}
} else {
// If the message is no longer valid, delete it from the database.
collectionmassage.deleteOne(
{ messageId: messageData.messageId },
function (err, res) {
if (err) throw err;
}
);
}
});
});