-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
245 lines (216 loc) · 6.64 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
const { Client, Partials, Collection, ActivityType, PermissionsBitField } = require("discord.js");
const { token, channelId } = require("./config.json");
const Mongo = require("./handlers/Mongo");
const Event = require("./handlers/Event");
const Command = require("./handlers/Command");
const Component = require("./handlers/Component");
const SlashUpdate = require("./handlers/SlashUpdate");
const GuildDB = require("./db/guilds");
const UserDB = require("./db/users");
const i18next = require("i18next");
const resources = require("./locales/resources");
const { Options } = require("discord.js");
/**
* @type {import("./typings").MainClient}
* @description The main client of the program
*/
const client = new Client({
failIfNotExists: false,
allowedMentions: { parse: [ "roles", "users", "everyone" ] },
intents: [53608447], // All Intents
partials: [
Partials.Channel,
Partials.GuildMember,
Partials.GuildScheduledEvent,
Partials.Message,
Partials.Reaction,
Partials.ThreadMember,
Partials.User
],
ws: { large_threshold: 100 },
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 100, // Maximum 100 messages in the cache
GuildMemberManager: 50, // Maximum 50 participants in the cache
ReactionManager: 0, // Reaction cache is disabled
}),
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 1_800, // Clearing the message cache every 30 minutes
lifetime: 900, // Delete messages older than 15 minutes
},
users: {
interval: 1_800, // Clearing the user cache every 30 minutes
filter: () => user => user.bot && user.id !== user.client.user.id,
},
guildMembers: {
interval: 1_800, // Clearing the participant cache every 30 minutes
filter: () => member => member.bot && member.id !== member.client.user.id,
},
},
presence: {
activities: [{
name: "custom",
state: "by GamesTwoLife",
type: ActivityType.Custom,
}]
}
});
client.i18n = i18next.init({
fallbackLng: 'en',
defaultNS: 'common',
interpolation: {
escapeValue: false,
},
resources: {
en: resources.en,
uk: resources.uk
}
});
client.commands = new Collection();
client.cooldowns = new Collection();
client.components = new Collection();
client.dbguild = GuildDB;
client.dbuser = UserDB;
Mongo();
// Anti-crash
process.on('unhandledRejection', async (error) => {
const channel = client.channels.cache.get(channelId);
if (!channel || channel && !channel.permissionsFor(client.user?.id).has([PermissionsBitField.Flags.ManageChannels, PermissionsBitField.Flags.ManageWebhooks])) return console.error(error);
try {
const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.find(wh => wh.owner === client.user);
if (!webhook) {
await channel.createWebhook({
name: `${client.user?.username} Logs`,
avatar: client.user?.avatarURL(),
}).then(async (webhook) => {
await webhook.send({
embeds: [{
color: 0xff0000,
title: 'Unhandled Rejection',
description: `\`\`\`js\n${error.stack}\n\`\`\``
}],
}).catch(() => {});
}).catch(() => {});
return;
}
await webhook.send({
embeds: [{
color: 0xff0000,
title: 'Unhandled Rejection',
description: `\`\`\`js\n${error.stack}\n\`\`\``
}],
}).catch(() => {});
} catch (err) {
console.error(error);
console.error('Error trying to send a message: ', err);
}
});
process.on('uncaughtException', async (error) => {
const channel = client.channels.cache.get(channelId);
if (!channel || channel && !channel.permissionsFor(client.user?.id).has([PermissionsBitField.Flags.ManageChannels, PermissionsBitField.Flags.ManageWebhooks])) return console.error(error);
try {
const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.find(wh => wh.owner === client.user);
if (!webhook) {
await channel.createWebhook({
name: `${client.user?.username} Logs`,
avatar: client.user?.avatarURL(),
}).then(async (webhook) => {
await webhook.send({
embeds: [{
color: 0xff0000,
title: 'Uncaught Exception',
description: `\`\`\`js\n${error.stack}\n\`\`\``
}],
}).catch(() => {});
}).catch(() => {});
return;
}
await webhook.send({
embeds: [{
color: 0xff0000,
title: 'Uncaught Exception',
description: `\`\`\`js\n${error.stack}\n\`\`\``
}],
}).catch(() => {});
} catch (err) {
console.error(error);
console.error('Error trying to send a message: ', err);
}
});
process.on('rejectionHandled', async (error) => {
const channel = client.channels.cache.get(channelId);
if (!channel || channel && !channel.permissionsFor(client.user?.id).has([PermissionsBitField.Flags.ManageChannels, PermissionsBitField.Flags.ManageWebhooks])) return console.error(error);
try {
const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.find(wh => wh.owner === client.user);
if (!webhook) {
await channel.createWebhook({
name: `${client.user?.username} Logs`,
avatar: client.user?.avatarURL(),
}).then(async (webhook) => {
await webhook.send({
embeds: [{
color: 0xff0000,
title: 'Rejection Handled',
description: `\`\`\`js\n${error.stack}\n\`\`\``
}],
}).catch(() => {});
}).catch(() => {});
return;
}
await webhook.send({
embeds: [{
color: 0xff0000,
title: 'Rejection Handled',
description: `\`\`\`js\n${error.stack}\n\`\`\``
}],
}).catch(() => {});
} catch (err) {
console.error(error);
console.error('Error trying to send a message: ', err);
}
});
process.on('warning', async (warning) => {
const channel = client.channels.cache.get(channelId);
if (!channel || channel && !channel.permissionsFor(client.user?.id).has([PermissionsBitField.Flags.ManageChannels, PermissionsBitField.Flags.ManageWebhooks])) return console.error(warning);
try {
const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.find(wh => wh.owner === client.user);
if (!webhook) {
await channel.createWebhook({
name: `${client.user?.username} Logs`,
avatar: client.user?.avatarURL(),
}).then(async (webhook) => {
await webhook.send({
embeds: [{
color: 0xff0000,
title: 'Warning',
description: `\`\`\`js\n${warning.stack}\n\`\`\``
}],
}).catch(() => {});
}).catch(() => {});
return;
}
await webhook.send({
embeds: [{
color: 0xff0000,
title: 'Warning',
description: `\`\`\`js\n${warning.stack}\n\`\`\``
}],
}).catch(() => {});
} catch (err) {
console.error(warning);
console.error('Error trying to send a message: ', err);
}
});
(async () => {
await Event(client);
await Command(client);
await Component(client);
await SlashUpdate(client);
})()
client.login(token);