zelin-bot / loader.mjs
Z User
v5.8.6: fix greeting spam on restart - 30min grace, channel verification, file fallback
9ef0e78
// Loader script - runs BEFORE index.js
// v5.8.4 - Resilient startup with keep-alive
process.on('unhandledRejection', (reason, promise) => {
console.warn('[Global] UnhandledRejection:', reason?.message ?? String(reason).substring(0, 100));
});
process.on('uncaughtException', (err) => {
console.error('[Global] UncaughtException:', err.message?.substring(0, 100));
if (err.message?.includes('ENOMEM') || err.message?.includes('heap')) {
process.exit(1);
}
});
console.log('[Loader] Global error handlers installed');
console.log('[Loader] Node version:', process.version);
console.log('[Loader] Platform:', process.platform, process.arch);
// Test network connectivity
const testUrls = [
'https://discordapp.com/api/v10/gateway',
'https://api.groq.com/openai/v1/models',
'https://router.huggingface.co/v1/models',
];
for (const url of testUrls) {
try {
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
console.log(`[Loader] ${url}${res.status}`);
} catch (e) {
console.warn(`[Loader] ${url} → FAILED: ${e.message?.substring(0, 60)}`);
}
}
// Keep the process alive even if the bot fails
setInterval(() => {
const mem = process.memoryUsage();
console.log(`[KeepAlive] RSS: ${(mem.rss/1024/1024).toFixed(1)}MB | Heap: ${(mem.heapUsed/1024/1024).toFixed(1)}MB | Uptime: ${Math.floor(process.uptime())}s`);
}, 60000);
// Load the bot
try {
await import('./index.js');
console.log('[Loader] Bot loaded successfully');
} catch (err) {
console.error('[Loader] Bot load error:', err.message);
console.log('[Loader] Bot failed to load, but process stays alive for health checks');
}