Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -98,42 +98,28 @@ const commandsData = [
|
|
| 98 |
];
|
| 99 |
|
| 100 |
client.once('ready', async () => {
|
| 101 |
-
console.log(`[
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
for (const guild of client.guilds.cache.values()) {
|
| 105 |
const backupChannel = guild.channels.cache.find(c => c.name === 'friendlybot-storage');
|
| 106 |
if (backupChannel) {
|
| 107 |
-
|
| 108 |
-
await backupChannel.delete('Cleaning up bot backup channels');
|
| 109 |
-
console.log(`[*] Deleted backup channel in ${guild.name}`);
|
| 110 |
-
} catch (e) {
|
| 111 |
-
console.log(`[!] Failed to delete backup channel in ${guild.name}`);
|
| 112 |
-
}
|
| 113 |
-
}
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
// Auto-Scan Pending Polls
|
| 117 |
-
for (const guild of client.guilds.cache.values()) {
|
| 118 |
-
const activePollId = storage.data.active_polls[guild.id];
|
| 119 |
-
if (activePollId) {
|
| 120 |
-
console.log(`🔍 Scanning for pending poll: ${activePollId} in ${guild.name}`);
|
| 121 |
}
|
| 122 |
}
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
try {
|
| 128 |
-
console.log(`[*] Registering global commands for ${client.guilds.cache.size} servers...`);
|
| 129 |
-
|
| 130 |
-
// Register globally (this is fast and avoids per-guild rate limits)
|
| 131 |
-
await client.application.commands.set(commandsData);
|
| 132 |
-
|
| 133 |
-
console.log('[*] Global Slash commands registered successfully.');
|
| 134 |
-
} catch (e) {
|
| 135 |
-
console.error(`[!] Register Error: ${e}`);
|
| 136 |
-
}
|
| 137 |
|
| 138 |
// Auto-Friendly Background Loop
|
| 139 |
setInterval(async () => {
|
|
@@ -1385,34 +1371,38 @@ async function showAutoFriendlyPanel(interaction) {
|
|
| 1385 |
}
|
| 1386 |
}
|
| 1387 |
|
| 1388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1389 |
|
| 1390 |
-
|
| 1391 |
-
|
| 1392 |
-
console.log(`[READY] FriendlyBot is ONLINE as ${client.user.tag}!`);
|
| 1393 |
-
console.log(`[READY] ##########################################`);
|
| 1394 |
-
});
|
| 1395 |
|
| 1396 |
-
|
| 1397 |
-
|
| 1398 |
-
|
| 1399 |
-
|
| 1400 |
-
|
| 1401 |
|
| 1402 |
-
|
| 1403 |
-
|
| 1404 |
-
|
| 1405 |
-
|
| 1406 |
-
|
| 1407 |
-
|
| 1408 |
-
|
| 1409 |
-
|
| 1410 |
-
|
| 1411 |
-
|
| 1412 |
-
|
| 1413 |
-
|
| 1414 |
-
|
| 1415 |
}
|
|
|
|
|
|
|
| 1416 |
}
|
| 1417 |
|
| 1418 |
-
|
|
|
|
| 98 |
];
|
| 99 |
|
| 100 |
client.once('ready', async () => {
|
| 101 |
+
console.log(`[SYSTEM] ##########################################`);
|
| 102 |
+
console.log(`[SYSTEM] FriendlyBot is ONLINE as ${client.user.tag}`);
|
| 103 |
+
console.log(`[SYSTEM] Connected to ${client.guilds.cache.size} servers`);
|
| 104 |
+
console.log(`[SYSTEM] ##########################################`);
|
| 105 |
|
| 106 |
+
try {
|
| 107 |
+
// Clear global commands and register them once (efficient)
|
| 108 |
+
console.log(`[*] Synchronizing global application commands...`);
|
| 109 |
+
await client.application.commands.set(commandsData);
|
| 110 |
+
console.log('[*] Application commands synchronized successfully.');
|
| 111 |
+
} catch (e) {
|
| 112 |
+
console.error(`[!] Command Sync Error: ${e.message}`);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
// Auto-Scan Pending Polls & Cleanup
|
| 116 |
for (const guild of client.guilds.cache.values()) {
|
| 117 |
const backupChannel = guild.channels.cache.find(c => c.name === 'friendlybot-storage');
|
| 118 |
if (backupChannel) {
|
| 119 |
+
backupChannel.delete().catch(() => {});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
}
|
| 121 |
}
|
| 122 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
// Auto-Friendly Background Loop
|
| 125 |
setInterval(async () => {
|
|
|
|
| 1371 |
}
|
| 1372 |
}
|
| 1373 |
|
| 1374 |
+
/**
|
| 1375 |
+
* Application Entry Point
|
| 1376 |
+
*/
|
| 1377 |
+
async function initialize() {
|
| 1378 |
+
console.log("[*] Starting Web Dashboard...");
|
| 1379 |
+
server.startServer(client, commandsData);
|
| 1380 |
|
| 1381 |
+
let retryCount = 0;
|
| 1382 |
+
const maxRetryDelay = 60000; // 1 minute
|
|
|
|
|
|
|
|
|
|
| 1383 |
|
| 1384 |
+
async function login() {
|
| 1385 |
+
if (!TOKEN || TOKEN.length < 10) {
|
| 1386 |
+
console.error("[CRITICAL] Discord Token is missing or malformed.");
|
| 1387 |
+
process.exit(1);
|
| 1388 |
+
}
|
| 1389 |
|
| 1390 |
+
try {
|
| 1391 |
+
console.log(`[*] Attempting connection to Discord (Attempt ${retryCount + 1})...`);
|
| 1392 |
+
await client.login(TOKEN);
|
| 1393 |
+
} catch (err) {
|
| 1394 |
+
console.error(`[ERROR] Authentication Failed: ${err.message}`);
|
| 1395 |
+
|
| 1396 |
+
// Exponential backoff for retries
|
| 1397 |
+
retryCount++;
|
| 1398 |
+
const delay = Math.min(1000 * Math.pow(2, retryCount), maxRetryDelay);
|
| 1399 |
+
|
| 1400 |
+
console.log(`[*] Retrying in ${delay / 1000}s...`);
|
| 1401 |
+
setTimeout(login, delay);
|
| 1402 |
+
}
|
| 1403 |
}
|
| 1404 |
+
|
| 1405 |
+
login();
|
| 1406 |
}
|
| 1407 |
|
| 1408 |
+
initialize();
|