-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·165 lines (147 loc) · 4.81 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
const { Client, Partials, GatewayIntentBits, EmbedBuilder } = require("discord.js");
require("dotenv").config();
const { readdirSync } = require("fs");
const fs = require("fs");
const yaml = require("js-yaml");
const Enmap = require("enmap");
const express = require("express");
const playerRoutes = require("./routes/playerRoutes.js");
const leagueRoutes = require("./routes/leagueRoutes.js");
const { QuickDB } = require("quick.db");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.MessageContent,
],
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction,
Partials.User,
Partials.GuildMember,
],
});
client.db = new QuickDB();
client.conf = yaml.load(fs.readFileSync("./settings/config.yml", "utf8"));
client.commands = new Enmap();
client.slashCommands = new Enmap();
client.slashArray = [];
client.cmdCooldowns = [];
client.afk = new Enmap();
client.categories = new Enmap();
client.processes = new Enmap();
client.snipes = new Enmap();
client.voteBans = new Enmap();
client.talkedRecently = new Set();
client.embedBuilder = require("./utils/embedBuilder.js");
client.utils = require("./utils/utils.js");
client.paginateSelect = require("./utils/paginateSelect.js");
process.on("unhandledRejection", (error) => {
if (client.isReady()) {
let ignoreErrors = [
`DiscordAPIError: Unknown Message`,
`DiscordAPIError: Missing Permissions`,
`DiscordAPIError: Missing Access`,
`DiscordAPIError: Unknown Channel`,
`DiscordAPIError: Cannot send messages to this user`,
"DiscordAPIError: Cannot execute action on a DM channel",
];
let list = [];
for (const ignore of ignoreErrors) {
if (error.stack.includes(ignore)) list.push(true);
}
if (list.length !== 0) return null;
let errEmbed = new EmbedBuilder()
.addFields({ name: "Error Occurred", value: `\`\`\`xl\n${error.stack}\n\`\`\``, inline: false })
.setColor("#e24c4b")
.setFooter({ text: `${error.name}` })
.setTimestamp();
let channel = client.channels.cache.get("512277268597309440");
if (channel) channel.send({ embeds: [errEmbed] });
}
console.log(error.stack);
});
process.on("uncaughtException", (error) => {
if (client.isReady()) {
let ignoreErrors = [
`DiscordAPIError: Unknown Message`,
`DiscordAPIError: Missing Permissions`,
`DiscordAPIError: Missing Access`,
`DiscordAPIError: Unknown Channel`,
`DiscordAPIError: Cannot send messages to this user`,
"DiscordAPIError: Cannot execute action on a DM channel",
];
let list = [];
for (const ignore of ignoreErrors) {
if (error.stack.includes(ignore)) list.push(true);
}
if (list.length !== 0) return null;
let errEmbed = new EmbedBuilder()
.addFields({ name: "Error Occurred", value: `\`\`\`xl\n${error.stack}\n\`\`\``, inline: false })
.setColor("#e24c4b")
.setFooter({ text: `${error.name}` })
.setTimestamp();
if (client.isReady) {
let channel = client.channels.cache.get("512277268597309440");
if (channel) channel.send({ embeds: [errEmbed] });
}
}
console.log(error.stack);
});
// Commands //
for (const d of readdirSync("./commands/")) {
client.categories.set(
d,
readdirSync(`./commands/${d}`).map((s) => s.split(".")[0])
);
for (const f of readdirSync(`./commands/${d}`)) {
const commandData = require(`./commands/${d}/${f}`);
if (commandData.slash == true) {
client.slashCommands.set(commandData.name, {
...commandData,
category: d,
});
client.slashArray.push(commandData);
}
client.commands.set(commandData.name, {
...commandData,
category: d,
});
}
}
// Events //
for (const evt of readdirSync("./events"))
client.on(
evt.split(".")[0],
require(`./events/${evt}`).bind(null, client)
);
// Express Server //
if(client.conf.Settings.Server == true) {
const app = express();
app.use(express.json());
app.use(async(req, res, next) => {
res.client = client;
next();
});
app.use("/players", playerRoutes);
app.use("/leagues", leagueRoutes);
app.listen(
client.conf.Settings.Port || 7070,
() =>
`[SERVER] Server has started on port ${
client.conf.Settings.port || 7070
}.`
);
}
client
.login(process.env.TOKEN)
.catch(() => console.log(`\x1b[0;37m[${date.toLocaleDateString()} ${date.toLocaleTimeString()}] \x1b[0;31m[Error] \x1b[0;37mInvalid token provided in Config`));