-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrain.js
More file actions
246 lines (232 loc) · 6.96 KB
/
brain.js
File metadata and controls
246 lines (232 loc) · 6.96 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
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
const Discord = require("discord.js");
const fs = require("fs");
const { Manager } = require("erela.js");
const Spotify = require("erela.js-spotify");
const Facebook = require("erela.js-facebook");
const Deezer = require("erela.js-deezer");
const AppleMusic = require("erela.js-apple");
// Discord client
const client = new Discord.Client({
allowedMentions: {
parse: ["users", "roles"],
repliedUser: true,
},
autoReconnect: true,
disabledEvents: ["TYPING_START"],
partials: [
Discord.Partials.Channel,
Discord.Partials.GuildMember,
Discord.Partials.Message,
Discord.Partials.Reaction,
Discord.Partials.User,
Discord.Partials.GuildScheduledEvent,
],
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildBans,
Discord.GatewayIntentBits.GuildEmojisAndStickers,
Discord.GatewayIntentBits.GuildIntegrations,
Discord.GatewayIntentBits.GuildWebhooks,
Discord.GatewayIntentBits.GuildInvites,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.GuildMessageTyping,
Discord.GatewayIntentBits.DirectMessages,
Discord.GatewayIntentBits.DirectMessageReactions,
Discord.GatewayIntentBits.DirectMessageTyping,
Discord.GatewayIntentBits.GuildScheduledEvents,
Discord.GatewayIntentBits.MessageContent,
],
restTimeOffset: 0,
});
const clientID = process.env.SPOTIFY_CLIENT_ID;
const clientSecret = process.env.SPOTIFY_CLIENT_SECRET;
if (clientID && clientSecret) {
// Lavalink client
client.player = new Manager({
plugins: [
new AppleMusic(),
new Deezer(),
new Facebook(),
new Spotify({
clientID,
clientSecret,
}),
],
nodes: [
{
host: process.env.LAVALINK_HOST || "lava.link",
port: parseInt(process.env.LAVALINK_PORT) || 80,
password: process.env.LAVALINK_PASSWORD || "MagneumDev",
secure: Boolean(process.env.LAVALINK_SECURE) || false,
},
{
host: "lavalink.techpoint.world",
port: 80,
password: "techpoint",
},
],
send(id, payload) {
const guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
});
} else {
// Lavalink client
client.player = new Manager({
plugins: [new AppleMusic(), new Deezer(), new Facebook()],
nodes: [
{
host: process.env.LAVALINK_HOST || "lava.link",
port: parseInt(process.env.LAVALINK_PORT) || 80,
password: process.env.LAVALINK_PASSWORD || "MagneumDev",
secure: Boolean(process.env.LAVALINK_SECURE) || false,
},
],
send(id, payload) {
const guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
});
}
const events = fs
.readdirSync(`./events/music`)
.filter((files) => files.endsWith(".js"));
for (const file of events) {
const event = require(`./events/music/${file}`);
client.player
.on(file.split(".")[0], event.bind(null, client))
.setMaxListeners(0);
}
// Connect to database
require("./database/connect")();
// Client settings
client.config = require("./config/bot");
client.changelogs = require("./config/changelogs");
client.emotes = require("./database/json/emojis.json");
client.webhooks = require("./database/json/webhooks.json");
const webHooksArray = [
"startLogs",
"shardLogs",
"errorLogs",
"dmLogs",
"voiceLogs",
"serverLogs",
"serverLogs2",
"commandLogs",
"consoleLogs",
"warnLogs",
"voiceErrorLogs",
"creditLogs",
"evalLogs",
"interactionLogs",
];
// Check if .env webhook_id and webhook_token are set
if (process.env.WEBHOOK_ID && process.env.WEBHOOK_TOKEN) {
for (const webhookName of webHooksArray) {
client.webhooks[webhookName].id = process.env.WEBHOOK_ID;
client.webhooks[webhookName].token = process.env.WEBHOOK_TOKEN;
}
}
client.commands = new Discord.Collection();
client.playerManager = new Map();
client.triviaManager = new Map();
client.queue = new Map();
// Webhooks
const consoleLogs = new Discord.WebhookClient({
id: client.webhooks.consoleLogs.id,
token: client.webhooks.consoleLogs.token,
});
const warnLogs = new Discord.WebhookClient({
id: client.webhooks.warnLogs.id,
token: client.webhooks.warnLogs.token,
});
// Load handlers
fs.readdirSync("./handlers").forEach((dir) => {
fs.readdirSync(`./handlers/${dir}`).forEach((handler) => {
require(`./handlers/${dir}/${handler}`)(client);
});
});
client.login(process.env.DISCORD_TOKEN);
process.on("unhandledRejection", (error) => {
console.error("Unhandled promise rejection:", error);
if (error)
if (error.length > 950)
error = error.slice(0, 950) + "... view console for details";
if (error.stack)
if (error.stack.length > 950)
error.stack = error.stack.slice(0, 950) + "... view console for details";
if (!error.stack) return;
const embed = new Discord.EmbedBuilder()
.setTitle(`🚨・Unhandled promise rejection`)
.addFields([
{
name: "Error",
value: error ? Discord.codeBlock(error) : "No error",
},
{
name: "Stack error",
value: error.stack ? Discord.codeBlock(error.stack) : "No stack error",
},
])
.setColor(client.config.colors.normal);
consoleLogs
.send({
username: "Bot Logs",
embeds: [embed],
})
.catch(() => {
console.log("Error sending unhandledRejection to webhook");
console.log(error);
});
});
process.on("warning", (warn) => {
console.warn("Warning:", warn);
const embed = new Discord.EmbedBuilder()
.setTitle(`🚨・New warning found`)
.addFields([
{
name: `Warn`,
value: `\`\`\`${warn}\`\`\``,
},
])
.setColor(client.config.colors.normal);
warnLogs
.send({
username: "Bot Logs",
embeds: [embed],
})
.catch(() => {
console.log("Error sending warning to webhook");
console.log(warn);
});
});
client.on(Discord.ShardEvents.Error, (error) => {
console.log(error);
if (error)
if (error.length > 950)
error = error.slice(0, 950) + "... view console for details";
if (error.stack)
if (error.stack.length > 950)
error.stack = error.stack.slice(0, 950) + "... view console for details";
if (!error.stack) return;
const embed = new Discord.EmbedBuilder()
.setTitle(`🚨・A websocket connection encountered an error`)
.addFields([
{
name: `Error`,
value: `\`\`\`${error}\`\`\``,
},
{
name: `Stack error`,
value: `\`\`\`${error.stack}\`\`\``,
},
])
.setColor(client.config.colors.normal);
consoleLogs.send({
username: "Bot Logs",
embeds: [embed],
});
});