Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -8,8 +8,12 @@ const { UI } = require('./NewBotStyle');
|
|
| 8 |
const { createLineupAttachment } = require('./lineupRenderer');
|
| 9 |
const { createProfileAttachment } = require('./profileRenderer');
|
| 10 |
|
| 11 |
-
//
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
console.log(`[SYSTEM] Starting FriendlyBot v4.0 (Watchdog Relaxed: ${new Date().toISOString()})`);
|
| 15 |
|
|
@@ -40,7 +44,7 @@ const client = new Client({
|
|
| 40 |
}
|
| 41 |
});
|
| 42 |
|
| 43 |
-
console.log(`[*] Discord Client Initialized.
|
| 44 |
|
| 45 |
|
| 46 |
client.commands = new Collection();
|
|
@@ -1342,8 +1346,10 @@ setInterval(async () => {
|
|
| 1342 |
if (client.isReady()) {
|
| 1343 |
if (client.ws.status !== 0) {
|
| 1344 |
console.log("[!] Gateway issues detected. Status:", client.ws.status);
|
| 1345 |
-
console.log("[*] Performing emergency
|
| 1346 |
-
|
|
|
|
|
|
|
| 1347 |
|
| 1348 |
// Attempt to keep session alive or force a new login if really dead
|
| 1349 |
if (client.ws.status === 7 || client.ws.status === 9) { // DISCONNECTED or INVALID_SESSION
|
|
@@ -1419,8 +1425,10 @@ async function initialize() {
|
|
| 1419 |
} catch (err) {
|
| 1420 |
console.error(`[ERROR] Authentication Failed: ${err.message}`);
|
| 1421 |
|
| 1422 |
-
//
|
| 1423 |
-
|
|
|
|
|
|
|
| 1424 |
|
| 1425 |
// Exponential backoff for retries
|
| 1426 |
retryCount++;
|
|
|
|
| 8 |
const { createLineupAttachment } = require('./lineupRenderer');
|
| 9 |
const { createProfileAttachment } = require('./profileRenderer');
|
| 10 |
|
| 11 |
+
// Network hijack can break Discord auth on some environments.
|
| 12 |
+
// Keep it opt-in via env when explicitly needed.
|
| 13 |
+
const USE_NETWORK_HIJACK = process.env.ENABLE_NETWORK_HIJACK === 'true';
|
| 14 |
+
if (USE_NETWORK_HIJACK) {
|
| 15 |
+
networkFix.applyAdvancedFixes();
|
| 16 |
+
}
|
| 17 |
|
| 18 |
console.log(`[SYSTEM] Starting FriendlyBot v4.0 (Watchdog Relaxed: ${new Date().toISOString()})`);
|
| 19 |
|
|
|
|
| 44 |
}
|
| 45 |
});
|
| 46 |
|
| 47 |
+
console.log(`[*] Discord Client Initialized.`);
|
| 48 |
|
| 49 |
|
| 50 |
client.commands = new Collection();
|
|
|
|
| 1346 |
if (client.isReady()) {
|
| 1347 |
if (client.ws.status !== 0) {
|
| 1348 |
console.log("[!] Gateway issues detected. Status:", client.ws.status);
|
| 1349 |
+
console.log("[*] Performing emergency reconnect...");
|
| 1350 |
+
if (USE_NETWORK_HIJACK) {
|
| 1351 |
+
networkFix.rotateEndpoint();
|
| 1352 |
+
}
|
| 1353 |
|
| 1354 |
// Attempt to keep session alive or force a new login if really dead
|
| 1355 |
if (client.ws.status === 7 || client.ws.status === 9) { // DISCONNECTED or INVALID_SESSION
|
|
|
|
| 1425 |
} catch (err) {
|
| 1426 |
console.error(`[ERROR] Authentication Failed: ${err.message}`);
|
| 1427 |
|
| 1428 |
+
// Retry login; only rotate custom endpoint if that mode is enabled
|
| 1429 |
+
if (USE_NETWORK_HIJACK) {
|
| 1430 |
+
networkFix.rotateEndpoint();
|
| 1431 |
+
}
|
| 1432 |
|
| 1433 |
// Exponential backoff for retries
|
| 1434 |
retryCount++;
|