forked from harshendram/Advanced-Discord-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
278 lines (239 loc) · 8.18 KB
/
index.js
File metadata and controls
278 lines (239 loc) · 8.18 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
const {
Client,
Collection,
GatewayIntentBits,
Partials,
ActivityType,
PresenceUpdateStatus,
} = require("discord.js");
const Database = require("./utils/database");
const { HookBus } = require("./core/HookBus");
const { PluginManager } = require("./core/PluginManager");
const { startApiServer } = require("./core/api/server");
const { createLogger } = require("./core/logger");
const TaskScheduler = require("./utils/scheduler");
require("dotenv").config();
// 🚀 Create VAISH - Ultra Modern Discord Bot
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences, // For advanced user tracking
],
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction,
Partials.User,
Partials.GuildMember,
],
});
// 💎 Bot Configuration
client.commands = new Collection();
client.cooldowns = new Collection();
// 🎨 VAISH Brand Colors - Ultra Modern Design
client.colors = {
primary: "#6366F1", // Indigo-500 - Modern primary
secondary: "#8B5CF6", // Violet-500 - Rich secondary
success: "#10B981", // Emerald-500 - Clean success
error: "#EF4444", // Red-500 - Clear error
warning: "#F59E0B", // Amber-500 - Attention warning
info: "#3B82F6", // Blue-500 - Information
dark: "#1F2937", // Gray-800 - Dark theme
light: "#F9FAFB", // Gray-50 - Light theme
accent: "#EC4899", // Pink-500 - Accent color
gradient: {
primary: "linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%)",
success: "linear-gradient(135deg, #10B981 0%, #059669 100%)",
error: "linear-gradient(135deg, #EF4444 0%, #DC2626 100%)",
},
};
// 🤖 VAISH Bot Profile
client.profile = {
name: "VAISH",
version: "2.0.0",
description: "Ultra-modern AI-powered Discord bot with advanced features",
author: "VAISH Development Team",
website: "https://VAISH-bot.com",
github: "https://github.com/VAISH-bot/discord-bot",
support: "https://discord.gg/VAISH-support",
features: [
"🤖 Advanced AI Assistant (Google Gemini)",
"💎 Points & Rewards System",
"📊 XP & Leveling with Role Rewards",
"🎫 Professional Ticket System",
"🛡️ Smart Moderation & Anti-Raid",
"🎮 Interactive Games & Entertainment",
"📈 Analytics & Server Insights",
"⚡ Lightning-fast Performance",
],
stats: {
commands: 46,
categories: 10,
uptime: 0,
servers: 0,
users: 0,
},
};
// 🗃️ Database singleton
let db;
let scheduler;
let pluginManager;
let hookBus;
// 🔄 Dynamic Activity Status for VAISH
const activities = [
{ name: "🤖 AI Assistant | /aiassistant", type: ActivityType.Playing },
{ name: "💎 Points & Rewards | /points", type: ActivityType.Watching },
{ name: "🎫 Ticket Support | /ticket", type: ActivityType.Listening },
{ name: "📊 Server Analytics | /serverinfo", type: ActivityType.Watching },
{ name: "🎮 Fun Games | /8ball", type: ActivityType.Playing },
{ name: "🛡️ Smart Moderation | /antiraid", type: ActivityType.Watching },
{ name: "⚡ 27 Commands Available | /help", type: ActivityType.Playing },
];
let currentActivity = 0;
// 🎯 Initialize Database Connection
async function initializeDatabase() {
try {
db = await Database.getInstance();
console.log("🗃️ VAISH Database initialized successfully");
// Update bot stats
client.profile.stats.uptime = Date.now();
return db;
} catch (error) {
console.error("❌ VAISH Database initialization failed:", error);
process.exit(1);
}
}
// 🚀 VAISH Startup Sequence
client.once("ready", async () => {
console.log(`
╔═══════════════════════════════════════════════════════════════╗
║ 🤖 VAISH BOT ONLINE 🤖 ║
╠═══════════════════════════════════════════════════════════════╣
║ Name: ${client.user.tag.padEnd(49)} ║
║ ID: ${client.user.id.padEnd(51)} ║
║ Servers: ${client.guilds.cache.size.toString().padEnd(47)} ║
║ Users: ${client.guilds.cache
.reduce((a, g) => a + g.memberCount, 0)
.toString()
.padEnd(49)} ║
║ Commands: ${client.commands.size.toString().padEnd(46)} ║
║ Latency: ${client.ws.ping.toString().padEnd(47)} ms║
╠═══════════════════════════════════════════════════════════════╣
║ 🚀 Ultra-Modern AI-Powered Discord Bot ║
║ 💎 Advanced Features • ⚡ Lightning Fast • 🛡️ Secure ║
║ 🌟 Open Source • 📊 Analytics • 🎮 Entertainment ║
╚═══════════════════════════════════════════════════════════════╝
`);
// Initialize core systems
if (!scheduler) {
scheduler = new TaskScheduler(client);
console.log("⏰ VAISH Task Scheduler initialized");
}
// Update bot stats
client.profile.stats.servers = client.guilds.cache.size;
client.profile.stats.users = client.guilds.cache.reduce(
(a, g) => a + g.memberCount,
0,
);
// Set initial status
updateBotActivity();
// Rotate activity status every 30 seconds
setInterval(updateBotActivity, 30000);
console.log("🎯 VAISH is fully operational and ready to serve!");
});
// 🔄 Update Bot Activity Status
function updateBotActivity() {
const activity = activities[currentActivity];
client.user.setPresence({
activities: [activity],
status: PresenceUpdateStatus.Online,
});
currentActivity = (currentActivity + 1) % activities.length;
}
// 🛡️ Advanced Error Handling
process.on("unhandledRejection", (error, promise) => {
console.error("❌ Unhandled Promise Rejection:", error);
console.error("Promise:", promise);
});
process.on("uncaughtException", (error) => {
console.error("❌ Uncaught Exception:", error);
console.error("Stack:", error.stack);
// Graceful shutdown
setTimeout(() => {
console.log("🔄 VAISH is restarting due to critical error...");
process.exit(1);
}, 5000);
});
// 🎯 Graceful Shutdown Handler
process.on("SIGINT", async () => {
console.log("\n🛑 VAISH shutdown initiated...");
try {
if (db) {
await db.close();
console.log("🗃️ Database connection closed");
}
client.destroy();
console.log("🤖 VAISH client destroyed");
console.log("✅ VAISH shutdown complete");
process.exit(0);
} catch (error) {
console.error("❌ Error during shutdown:", error);
process.exit(1);
}
});
// 🚀 Initialize VAISH Bot
async function startVAISH() {
try {
console.log("🔄 Starting VAISH Bot...");
db = await initializeDatabase();
if (!scheduler) {
scheduler = new TaskScheduler(client);
console.log("⏰ VAISH Task Scheduler initialized");
}
hookBus = new HookBus(createLogger("HookBus"));
client.hooks = hookBus;
pluginManager = new PluginManager({
client,
db,
scheduler,
hooks: hookBus,
});
client.pluginManager = pluginManager;
await pluginManager.loadAll();
if (process.env.BOT_API_ENABLED === "true") {
await startApiServer({
client,
db,
pluginManager,
hooks: hookBus,
});
}
// Login to Discord
await client.login(process.env.DISCORD_TOKEN);
} catch (error) {
console.error("❌ Failed to start VAISH Bot:", error);
console.log("🔑 Please check your DISCORD_TOKEN in the .env file");
console.log("💡 Ensure your bot token is valid and has proper permissions");
process.exit(1);
}
}
// <<<<<<< HEAD
// =======
// >>>>>>> 32cde73
// // 🌐 Minimal Express server to keep Render web service alive
// const express = require("express");
// const app = express();
// const PORT = process.env.PORT || 3000;
// app.get("/", (req, res) => {
// res.send("🟢 VAISH is alive and running!");
// });
// app.listen(PORT, () => {
// console.log(`🌐 Web server running on port ${PORT}`);
// });
// 🎬 Start the show!
startVAISH();