-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
246 lines (218 loc) ยท 8.31 KB
/
index.ts
File metadata and controls
246 lines (218 loc) ยท 8.31 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
// index.ts
import {
Client,
GatewayIntentBits,
ActivityType,
EmbedBuilder,
MessageFlags,
Interaction,
} from "discord.js";
import { Logger } from "./src/utils/logger";
import { CommandHandler } from "./src/handlers/commandHandler";
import { BlacklistManager } from "./src/handlers/blacklistMembers";
import "dotenv/config";
// Add CommandHandler to Client type
declare module "discord.js" {
interface Client {
commandHandler: CommandHandler;
}
}
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
],
});
// Attach command handler to client
const commandHandler = new CommandHandler(client);
client.commandHandler = commandHandler;
// Initialize the webhook logger
Logger.setWebhook(process.env.WEBHOOK_URL!);
// Fun status messages with emojis
const statusMessages = [
{ text: "for new members ๐", type: ActivityType.Watching },
{ text: "git push --force ๐ป", type: ActivityType.Watching },
{ text: "hugs being shared ๐ค", type: ActivityType.Watching },
{ text: "kisses being blown ๐", type: ActivityType.Watching },
{ text: "air kisses flying โจ", type: ActivityType.Watching },
{ text: "waves to members ๐", type: ActivityType.Watching },
{ text: "the server grow ๐ฑ", type: ActivityType.Watching },
{ text: "commit messages ๐ฅ๏ธ", type: ActivityType.Watching },
];
function updateStatus() {
const randomStatus =
statusMessages[Math.floor(Math.random() * statusMessages.length)];
client.user?.setActivity(randomStatus.text, { type: randomStatus.type });
}
client.once("ready", async (c) => {
const shardInfo = client.shard
? ` on shard [${client.shard.ids.join(", ")}]`
: "";
await Logger.startupBanner("JamUtilities", "2.0.0");
BlacklistManager.getInstance();
await Logger.info("Blacklist manager initialized");
await Logger.ready(
"BOT STATISTICS",
[
`๐ค Logged in as ${c.user.tag}${shardInfo}`,
`๐ Spreading chaos in ${c.guilds.cache.size} guilds`,
`๐ฅ Tormenting ${c.users.cache.size} users`,
`๐พ Consuming ${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)}MB of RAM`,
`โก Powered by Node ${process.version}`,
`๐ฎ ${client.commandHandler.getCommands().size} commands loaded`,
`๐ง Command Modes:`,
` โข Slash Commands: ${client.commandHandler.isSlashEnabled() ? "โ
" : "โ"}`,
` โข Prefix Commands: ${client.commandHandler.isPrefixEnabled() ? "โ
" : "โ"}`,
client.commandHandler.isPrefixEnabled()
? ` โข Prefix: ${client.commandHandler.getPrefix()}`
: "",
].filter(Boolean),
);
updateStatus();
await Logger.info(`Initial status set - Let the games begin!`);
try {
await client.commandHandler.loadCommands();
await Logger.success(`Commands loaded successfully!`);
if (client.commandHandler.isSlashEnabled()) {
await client.commandHandler.registerCommands();
await Logger.success(`Commands registered with Discord API!`);
}
} catch (error) {
await Logger.fatal("Failed to initialize commands: ", error);
process.exit(1);
}
await Logger.ready("SYSTEM INFO", [
`๐ฅ๏ธ Platform: ${process.platform}`,
`โ๏ธ Architecture: ${process.arch}`,
`๐ PID: ${process.pid}`,
`๐ Process Uptime: ${Math.floor(process.uptime())}s`,
`๐ฏ Discord.js Version: ${require("discord.js").version}`,
]);
const chaosMessages = [
"๐ค Beep boop, time to ruin someone's day!",
"๐ Ready to cause psychological damage!",
"๐ญ Time to play with human emotions!",
"๐ช๏ธ Chaos mode activated successfully!",
"๐ฅ Ready to set the world on fire!",
"๐ช Let the circus begin!",
"๐ The Joker has entered the chat!",
"๐ฎ Game on, prepare for trouble!",
"๐ซ Chaos generator initialized!",
"๐ Ready to spread colorful destruction!",
];
await Logger.event(
chaosMessages[Math.floor(Math.random() * chaosMessages.length)],
);
});
// Handle Slash Commands
client.on("interactionCreate", async (interaction: Interaction) => {
if (interaction.isChatInputCommand()) {
await client.commandHandler.handleCommand(interaction);
}
});
// Handle Prefix Commands
client.on("messageCreate", async (message) => {
// First check if message starts with prefix or is from a bot
if (
!message.content.startsWith(process.env.PREFIX || "jam!") ||
message.author.bot
)
return;
// Then check blacklist for non-owner users
if (message.author.id !== process.env.OWNER_ID) {
const blacklistManager = BlacklistManager.getInstance();
if (blacklistManager.isBlacklisted(message.author.id)) {
const blacklistInfo = blacklistManager.getBlacklistInfo(
message.author.id,
);
await message.reply({
embeds: [
new EmbedBuilder()
.setColor("#ff3838")
.setTitle("Access Denied")
.setDescription(
"You are blacklisted from using this bot.",
)
.addFields(
{
name: "Username",
value: blacklistInfo?.username || "Unknown",
inline: true,
},
{
name: "Reason",
value:
blacklistInfo?.reason ||
"No reason provided",
inline: true,
},
{
name: "Blacklisted Since",
value: `<t:${Math.floor(blacklistInfo!.timestamp)}:R>`,
inline: true,
},
)
.setFooter({
text: "Contact the bot owner if you think this is a mistake",
}),
],
});
return;
}
}
await client.commandHandler.handlePrefixCommand(message);
});
client.on("guildCreate", (guild) => {
Logger.event(
`๐ New guild joined: ${guild.name} (Total: ${client.guilds.cache.size})`,
);
Logger.ready("NEW GUILD INFO", [
`๐ Name: ${guild.name}`,
`๐ Owner: ${guild.ownerId}`,
`๐ฅ Members: ${guild.memberCount}`,
`๐ ID: ${guild.id}`,
]);
});
client.on("guildDelete", (guild) => {
Logger.event(
`๐ Removed from guild: ${guild.name} (Total: ${client.guilds.cache.size})`,
);
});
client.on("error", (error) => {
Logger.fatal("Discord client error occurred: ", error);
});
process.on("unhandledRejection", (error) => {
Logger.fatal("โ Unhandled Promise Rejection: ", error);
});
process.on("uncaughtException", (error) => {
Logger.fatal("๐ฅ Uncaught Exception (Bot will restart): ", error);
});
process.on("SIGINT", () => {
Logger.warn("Received SIGINT signal. Cleaning up...");
BlacklistManager.getInstance().cleanup();
client.destroy();
process.exit(0);
});
process.on("SIGTERM", () => {
Logger.warn("Received SIGTERM signal. Cleaning up...");
BlacklistManager.getInstance().cleanup();
client.destroy();
process.exit(0);
});
// Status update interval
setInterval(updateStatus, 3 * 60 * 1000); // Every 3 minutes
Logger.info("Initializing bot...");
client
.login(process.env.DISCORD_TOKEN)
.then(() => Logger.info("Discord connection established!"))
.catch((error) => {
Logger.fatal("Failed to start the chaos engine: ", error);
process.exit(1);
});