Repository navigation
Expand file tree
/
Copy pathbot.js
More file actions
489 lines (429 loc) · 17.4 KB
/
Copy pathbot.js
File metadata and controls
489 lines (429 loc) · 17.4 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/**
* ╦ ╦╦═╗╔═╗╦╔╦╗╦ ╦
* ║║║╠╦╝╠═╣║ ║ ╠═╣
* ╚╩╝╩╚═╩ ╩╩ ╩ ╩ ╩
*
* Wraith Discord Bot
* Created by 8ivq (https://github.com/8ivq)
* Repository: https://github.com/8ivq/wraith
* License: MIT
*
* @author 8ivq
* @version 2.0.0
*/
const { Client, GatewayIntentBits, ChannelType, PermissionFlagsBits, ActivityType } = require('discord.js');
const config = require('./config');
const { tempChannels, handleModerationCommand, handleVCCommand, handleTextCommand, handleGiveawayCommand, handleEventCommand, handleSecurityCommand, handleLockCommand } = require('./commands');
const { handleHelpCommand } = require('./commands/help');
const { handleUtilityCommand } = require('./commands/utility');
const { handleMemberJoin, handleMessage, logCommand } = require('./utils/security');
const { setupInviteTracking, createVerificationChannel, handleVerificationButton } = require('./utils/verification');
const { handleVerificationCommand } = require('./commands/verification');
const { createTicket, claimTicket, setPriority, closeTicket, scanExistingTickets } = require('./utils/ticketManager');
const { handleTicketCommand } = require('./commands/ticket');
const { handleReminderCommand } = require('./commands/reminder');
const { handleThreadCommand } = require('./commands/thread');
const { handleHistoryCommand, handleEnhancedJail } = require('./commands/history');
const { handleMoveallCommand, handleStripstaffCommand, handleTimeoutListCommand } = require('./commands/admin');
const { WraithPanel } = require('./panel/server');
// Startup banner - Wraith by 8ivq
const WRAITH_BANNER = `
\x1b[38;5;135m╦ ╦╦═╗╔═╗╦╔╦╗╦ ╦\x1b[0m
\x1b[38;5;141m║║║╠╦╝╠═╣║ ║ ╠═╣\x1b[0m
\x1b[38;5;147m╚╩╝╩╚═╩ ╩╩ ╩ ╩ ╩\x1b[0m
\x1b[38;5;245m────────────────────────────\x1b[0m
\x1b[38;5;255mDiscord Bot\x1b[0m \x1b[38;5;245m•\x1b[0m \x1b[38;5;141mv2.0.0\x1b[0m
\x1b[38;5;245mCreated by\x1b[0m \x1b[38;5;135m8ivq\x1b[0m
\x1b[38;5;245mgithub.com/8ivq/wraith\x1b[0m
\x1b[38;5;245m────────────────────────────\x1b[0m
`;
console.log(WRAITH_BANNER);
if (!config.isConfigured()) {
console.error('❌ Bot is not configured! Please run: node setup.js');
process.exit(1);
}
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildInvites,
]
});
// Initialize Web Panel
let panel = null;
const PANEL_PORT = process.env.PANEL_PORT || 3000;
client.once('clientReady', () => {
console.log(`✅ Bot is online as ${client.user.tag}`);
console.log(`📊 Serving ${client.guilds.cache.size} server(s)`);
// Show config stats
const stats = config.getStats();
console.log(`⚙️ Configured: ${stats.configured}/${stats.total} guilds`);
// Set bot status
client.user.setPresence({
activities: [{
name: `${client.guilds.cache.size} servers`,
type: ActivityType.Watching
}],
status: 'dnd'
});
// Setup invite tracking and scan existing tickets for all guilds
client.guilds.cache.forEach(async guild => {
setupInviteTracking(guild);
const guildConfig = config.getGuildConfig(guild.id);
await scanExistingTickets(guild, guildConfig);
});
// Start Web Panel
try {
panel = new WraithPanel(client, config, PANEL_PORT);
panel.start();
console.log(`🌐 Panel API running at http://localhost:${PANEL_PORT}`);
console.log(`🖥️ Web Panel UI: http://localhost:3001`);
} catch (err) {
console.error('❌ Failed to start web panel:', err.message);
}
});
// Guild join event - initialize config for new server
client.on('guildCreate', async (guild) => {
console.log(`➕ Joined new server: ${guild.name} (${guild.id})`);
// Initialize guild config with defaults
config.loadGuildConfig(guild.id);
// Update bot status
client.user.setPresence({
activities: [{
name: `${client.guilds.cache.size} servers`,
type: ActivityType.Watching
}],
status: 'dnd'
});
});
// Guild leave event - optionally clean up config
client.on('guildDelete', async (guild) => {
console.log(`➖ Left server: ${guild.name} (${guild.id})`);
// Note: We keep the config in case bot is re-added
// To delete: config.deleteGuildConfig(guild.id);
// Update bot status
client.user.setPresence({
activities: [{
name: `${client.guilds.cache.size} servers`,
type: ActivityType.Watching
}],
status: 'dnd'
});
});
// Join to Create functionality
client.on('voiceStateUpdate', async (oldState, newState) => {
const guild = newState.guild || oldState.guild;
const guildConfig = config.getGuildConfig(guild.id);
// User joins the Join to Create channel
if (newState.channelId === guildConfig.joinToCreateChannelId) {
const member = newState.member;
try {
const newChannel = await guild.channels.create({
name: `${member.user.username}'s channel`,
type: ChannelType.GuildVoice,
parent: guildConfig.categoryId,
permissionOverwrites: [
{
id: member.id,
allow: [
PermissionFlagsBits.ManageChannels,
PermissionFlagsBits.MoveMembers,
PermissionFlagsBits.MuteMembers,
],
},
],
});
await member.voice.setChannel(newChannel);
// Find the associated text channel and lock it to owner only
const textChannel = guild.channels.cache.find(
c => c.name === 'voice-chat' && c.parentId === guildConfig.categoryId && c.type === ChannelType.GuildText
);
if (textChannel) {
// Lock text channel to owner only
await textChannel.permissionOverwrites.edit(guild.id, {
SendMessages: false,
});
await textChannel.permissionOverwrites.edit(member.id, {
SendMessages: true,
});
}
tempChannels.set(newChannel.id, {
ownerId: member.id,
channelId: newChannel.id,
textChannelId: textChannel?.id,
guildId: guild.id,
});
console.log(`✅ Created temp channel: ${newChannel.name} in ${guild.name}`);
} catch (error) {
console.error('❌ Error creating voice channel:', error);
}
}
// Owner leaves a temp channel - allow claiming
if (oldState.channel && tempChannels.has(oldState.channelId)) {
const channelData = tempChannels.get(oldState.channelId);
// If owner left and channel is not empty, mark as claimable
if (oldState.member.id === channelData.ownerId && oldState.channel.members.size > 0) {
channelData.ownerId = null; // Mark as claimable
tempChannels.set(oldState.channelId, channelData);
// Remove owner's text permission
if (channelData.textChannelId) {
const textChannel = oldState.guild.channels.cache.get(channelData.textChannelId);
if (textChannel) {
await textChannel.permissionOverwrites.delete(oldState.member.id).catch(() => {});
}
}
console.log(`👑 Channel ${oldState.channel.name} is now claimable`);
}
// Delete if empty
if (oldState.channel.members.size === 0) {
try {
// Clean up text channel permissions
if (channelData.textChannelId) {
const textChannel = oldState.guild.channels.cache.get(channelData.textChannelId);
if (textChannel) {
// Reset text channel to default (everyone can send)
await textChannel.permissionOverwrites.edit(oldState.guild.id, {
SendMessages: null,
}).catch(() => {});
// Remove owner override if exists
if (channelData.ownerId) {
await textChannel.permissionOverwrites.delete(channelData.ownerId).catch(() => {});
}
}
}
await oldState.channel.delete();
tempChannels.delete(oldState.channelId);
console.log(`🗑️ Deleted empty temp channel`);
} catch (error) {
console.error('❌ Error deleting voice channel:', error);
}
}
}
});
// Member join event
client.on('guildMemberAdd', async (member) => {
const guildConfig = config.getGuildConfig(member.guild.id);
// Create verification channel if enabled
if (guildConfig.verificationEnabled) {
await createVerificationChannel(member, guildConfig);
return; // Don't send welcome message until verified
}
// Security checks (anti-raid, account filter, quarantine)
await handleMemberJoin(member, guildConfig);
if (!guildConfig.welcomeChannelId) return;
const channel = member.guild.channels.cache.get(guildConfig.welcomeChannelId);
if (!channel) return;
try {
const embed = {
color: 0x2ECC71,
title: '👋 Welcome!',
description: `${member} just joined the server!`,
thumbnail: { url: member.user.displayAvatarURL({ dynamic: true, size: 256 }) },
fields: [
{ name: 'Account Created', value: `<t:${Math.floor(member.user.createdTimestamp / 1000)}:R>`, inline: true },
{ name: 'Member Count', value: `${member.guild.memberCount}`, inline: true }
],
footer: { text: `ID: ${member.id}` },
timestamp: new Date()
};
await channel.send({ embeds: [embed] });
} catch (error) {
console.error('Error sending welcome message:', error);
}
});
// Member leave event
client.on('guildMemberRemove', async (member) => {
const guildConfig = config.getGuildConfig(member.guild.id);
if (!guildConfig.leaveChannelId) return;
const channel = member.guild.channels.cache.get(guildConfig.leaveChannelId);
if (!channel) return;
try {
const embed = {
color: 0xE74C3C,
title: '👋 Goodbye',
description: `${member.user.tag} just left the server.`,
thumbnail: { url: member.user.displayAvatarURL({ dynamic: true, size: 256 }) },
fields: [
{ name: 'Joined', value: member.joinedAt ? `<t:${Math.floor(member.joinedTimestamp / 1000)}:R>` : 'Unknown', inline: true },
{ name: 'Member Count', value: `${member.guild.memberCount}`, inline: true }
],
footer: { text: `ID: ${member.id}` },
timestamp: new Date()
};
await channel.send({ embeds: [embed] });
} catch (error) {
console.error('Error sending leave message:', error);
}
});
// Booster event (detected via role update)
client.on('guildMemberUpdate', async (oldMember, newMember) => {
const guildConfig = config.getGuildConfig(newMember.guild.id);
if (!guildConfig.boosterChannelId) return;
const channel = newMember.guild.channels.cache.get(guildConfig.boosterChannelId);
if (!channel) return;
try {
// Check if member started boosting
const oldBoost = oldMember.premiumSince;
const newBoost = newMember.premiumSince;
if (!oldBoost && newBoost) {
// Member just started boosting
const embed = {
color: 0xFF73FA,
title: '💎 Server Boosted!',
description: `${newMember} just boosted the server!`,
thumbnail: { url: newMember.user.displayAvatarURL({ dynamic: true, size: 256 }) },
fields: [
{ name: 'Boost Count', value: `${newMember.guild.premiumSubscriptionCount || 0}`, inline: true },
{ name: 'Boost Level', value: `Level ${newMember.guild.premiumTier}`, inline: true }
],
footer: { text: 'Thank you for your support! 💜' },
timestamp: new Date()
};
await channel.send({ content: `${newMember}`, embeds: [embed] });
}
} catch (error) {
console.error('Error sending boost message:', error);
}
});
// Button interaction handler (for verification and ticket systems)
client.on('interactionCreate', async (interaction) => {
if (!interaction.isButton()) return;
const guildConfig = config.getGuildConfig(interaction.guild.id);
if (interaction.customId.startsWith('verify_')) {
await handleVerificationButton(interaction, guildConfig);
} else if (interaction.customId.startsWith('ticket_create_')) {
// Extract category from button ID
const category = interaction.customId.replace('ticket_create_', '');
const result = await createTicket(interaction.member, category, guildConfig);
if (result.success) {
await interaction.reply({ content: result.message, ephemeral: true });
} else {
await interaction.reply({ content: result.message, ephemeral: true });
}
} else if (interaction.customId === 'ticket_claim') {
await claimTicket(interaction, guildConfig);
} else if (interaction.customId === 'ticket_priority') {
// Show priority selection
const { ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');
const row = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('priority_select')
.setPlaceholder('Select priority level')
.addOptions([
{ label: 'Low Priority', description: 'Non-urgent issues', value: 'low', emoji: '🟢' },
{ label: 'Medium Priority', description: 'Standard issues', value: 'medium', emoji: '🟡' },
{ label: 'High Priority', description: 'Important issues', value: 'high', emoji: '🟠' },
{ label: 'Urgent', description: 'Critical issues requiring immediate attention', value: 'urgent', emoji: '🔴' }
])
);
await interaction.reply({ content: 'Select ticket priority:', components: [row], ephemeral: true });
} else if (interaction.customId === 'ticket_close') {
await closeTicket(interaction, 'Closed via button', guildConfig);
}
});
// String select menu handler (for ticket priority)
client.on('interactionCreate', async (interaction) => {
if (!interaction.isStringSelectMenu()) return;
const guildConfig = config.getGuildConfig(interaction.guild.id);
if (interaction.customId === 'priority_select') {
const priority = interaction.values[0];
await setPriority(interaction, priority, guildConfig);
}
});
// Message commands
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (!message.guild) return; // Ignore DMs
const guildConfig = config.getGuildConfig(message.guild.id);
// Link scanner check
await handleMessage(message, guildConfig);
if (!message.content.startsWith(',')) return;
const args = message.content.slice(1).trim().split(/ +/);
const command = args.shift().toLowerCase();
// Log command for audit
await logCommand(message, command, args, guildConfig);
// Moderation commands
if (['ban', 'tempban', 'kick', 'unjail', 'mute', 'unmute', 'timeout', 'unban', 'untimeout', 'pic'].includes(command)) {
await handleModerationCommand(message, command, args);
}
// Enhanced jail with duration
else if (command === 'jail') {
await handleEnhancedJail(message, args);
}
// Text channel commands
else if (['text', 'unpic', 'clear'].includes(command)) {
await handleTextCommand(message, command, args);
}
// Help command
else if (command === 'help') {
await handleHelpCommand(message);
}
// Utility commands
else if (['av', 'avatar', 'banner', 'bnr'].includes(command)) {
await handleUtilityCommand(message, command, args);
}
// Giveaway and Poll commands
else if (['giveaway', 'poll'].includes(command)) {
await handleGiveawayCommand(message, command, args);
}
// Event configuration commands
else if (['setwelcome', 'setleave', 'setbooster', 'eventconfig'].includes(command)) {
await handleEventCommand(message, command, args);
}
// Verification commands
else if (command === 'verify') {
await handleVerificationCommand(message, args, guildConfig);
}
// Security commands
else if (['antiraid', 'accountfilter', 'linkscanner', 'quarantine', 'altdetection', 'securityconfig', 'setauditlog', 'threat', 'whitelist', 'securitylogs', 'resetthreat'].includes(command)) {
await handleSecurityCommand(message, command, args, guildConfig);
}
// Lock/Unlock/Lockdown commands
else if (['unlock', 'lockdown'].includes(command)) {
await handleLockCommand(message, command, args, guildConfig);
}
// Ticket commands
else if (command === 'ticket') {
await handleTicketCommand(message, args, guildConfig);
}
// Voice channel commands - All require being in temp VC
else if (['vc'].includes(command)) {
await handleVCCommand(message, command, args, guildConfig);
}
// Reminder commands
else if (['remind', 'reminders'].includes(command)) {
await handleReminderCommand(message, command, args, client);
}
// Thread commands
else if (command === 'thread') {
await handleThreadCommand(message, args);
}
// History/Moderation tracking commands
else if (['history', 'moderationhistory', 'modstats', 'reason', 'warn', 'warnings', 'jaillist'].includes(command)) {
await handleHistoryCommand(message, command, args);
}
// Admin commands
else if (command === 'moveall') {
await handleMoveallCommand(message, args);
}
else if (command === 'stripstaff') {
await handleStripstaffCommand(message, args);
}
// Timeout list
else if (command === 'timeout' && args[0]?.toLowerCase() === 'list') {
await handleTimeoutListCommand(message);
}
else {
const embed = {
color: 0xFF0000,
description: '❌ **Unknown command!** Use `,help` to see all commands.'
};
message.reply({ embeds: [embed] });
}
});
client.login(config.getToken());