-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
168 lines (147 loc) · 5.34 KB
/
index.js
File metadata and controls
168 lines (147 loc) · 5.34 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
const Discord = require("discord.js");
require("./handlers/discordCompat");
require("dotenv").config();
const dns = require("node:dns");
const config = require(`./botconfig/config.json`);
const settings = require(`./botconfig/settings.json`);
const filters = require(`./botconfig/filters.json`);
const colors = require("colors");
const { connectMongoDB, MongoDBEnmap } = require("./databases/mongodb");
const libsodium = require("libsodium-wrappers");
const { GatewayIntentBits, Partials } = Discord;
const client = new Discord.Client({
restTimeOffset: 0,
shards: "auto",
allowedMentions: {
parse: [ ],
repliedUser: false,
},
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageTyping,
],
presence: {
status: "online",
activities: [{
name: `${config.prefix}help`,
type: Discord.ActivityType.Playing
}]
},
});
const LavalinkManagerWrapper = require("./handlers/lavalinkClient");
client.lavalink = new LavalinkManagerWrapper(client);
client.distube = {
getQueue: (guildId) => {
return client.lavalink.getQueue(guildId);
},
play: async (voiceChannel, url, options = {}) => {
return await client.lavalink.play(voiceChannel, url, options);
},
skip: async (guildId) => {
return await client.lavalink.skip(guildId);
},
stop: async (guildId) => {
return await client.lavalink.stop(guildId);
},
pause: async (guildId) => {
return await client.lavalink.pause(guildId, true);
},
resume: async (guildId) => {
return await client.lavalink.resume(guildId);
},
filters: {},
customFilters: filters,
};
const { request } = require("http");
try {
const dnsOrder = String(process.env.DNS_RESULT_ORDER || "ipv4first").trim();
dns.setDefaultResultOrder(dnsOrder);
} catch (err) {
console.warn("[DNS] Failed to set default result order:", err?.message || err);
}
const spotifyEnabled = String(process.env.SPOTIFY_API_ENABLED);
const spotifyClientId = process.env.SPOTIFY_CLIENT_ID;
const spotifyClientSecret = process.env.SPOTIFY_CLIENT_SECRET;
//Define some Global Collections
client.commands = new Discord.Collection();
client.cooldowns = new Discord.Collection();
client.slashCommands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.categories = require("fs").readdirSync(`./commands`);
client.allEmojis = require("./botconfig/emojis.json");
client.devIds = require("./handlers/devUtils").getDeveloperIds();
client.setMaxListeners(100); require('events').defaultMaxListeners = 100;
client.settings = new MongoDBEnmap();
const TicketHandler = require("./handlers/tickets");
client.ticketHandler = new TicketHandler(client);
const AutoModHandler = require("./handlers/automod");
client.automodHandler = new AutoModHandler(client);
const startKingApi = require("./handlers/kingApi");
const automodDefaults = {
automodEnabled: false,
automodLogChannelId: null,
automodLogWebhook: null,
automodLogType: "channel",
automodLogMessage: '{user} | {type} | {reason}',
automodBypassRoles: [],
automodMuteRole: null,
automodPenalty1: "none",
automodPenalty2: "mute",
automodPenalty3: "kick",
automodAntiSpamEnabled: false,
automodAntiSpamMaxMessages: 5,
automodAntiSpamMaxSeconds: 3,
automodAntiLinksEnabled: false,
automodAntiInviteEnabled: false,
automodAntiWordsEnabled: false,
automodAntiWordsList: [],
automodAntiWordsWarnMessage: "Você usou palavras proibidas neste servidor.",
automodAntiNewAccountsEnabled: false,
automodAntiNewAccountsMinDays: 1
};
async function startBot() {
try {
startKingApi(client);
await connectMongoDB();
const cachedGuildSettings = await client.settings.warmCache();
console.log(`[MongoDBEnmap] ${cachedGuildSettings} servidor(es) com settings em cache`);
client.infos = new MongoDBEnmap();
//Require the Handlers Add the antiCrash file too, if its enabled
[settings.antiCrash !== false ? "antiCrash" : null, "events", "commands", "slashCommands", "lavalinkEvents"]
.filter(Boolean)
.forEach(h => {
require(`./handlers/${h}`)(client);
})|| config.token
//Start the Bot
client.login(process.env.token || process.env.TOKEN || config.token);
// Load statuspage handler early
const statuspageHandler = require("./handlers/statuspage");
// Connect to Lavalink after bot is ready
client.once("clientReady", async () => {
try {
await client.lavalink.connect();
console.log("[Lavalink] Conectado ao servidor Lavalink");
statuspageHandler(client).load();
} catch (error) {
console.error("[Lavalink] Erro ao conectar:", error);
}
});
} catch (error) {
console.error("❌ Erro ao iniciar o bot:", error);
process.exit(1);
}
}
if (process.env.NODE_ENV === 'test') {
console.log('🧪 Test mode ativo - pulando inicialização do bot');
process.exit(0);
}
startBot();
client.on("clientReady", () => {
require("./dashboard/index.js")(client);
})