-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
84 lines (69 loc) · 2.21 KB
/
Copy pathstart.js
File metadata and controls
84 lines (69 loc) · 2.21 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
const { spawn } = require('child_process');
const path = require('path');
require('dotenv').config();
console.log('🚀 Starting Crenors Discord Bot...');
console.log('📝 Made by Team Addoners');
console.log('');
// Check if .env file exists
const fs = require('fs');
if (!fs.existsSync('.env')) {
console.log('❌ .env file not found!');
console.log('📋 Please copy env.example to .env and configure your settings.');
console.log(' cp env.example .env');
process.exit(1);
}
// Check required environment variables
const requiredVars = ['BOT_TOKEN', 'BOT_OWNER_ID'];
const missingVars = requiredVars.filter(varName => !process.env[varName]);
if (missingVars.length > 0) {
console.log('❌ Missing required environment variables:');
missingVars.forEach(varName => console.log(` - ${varName}`));
console.log('');
console.log('📋 Please set these in your .env file.');
process.exit(1);
}
console.log('✅ Environment variables loaded');
console.log('🌐 Starting web editor...');
// Start web editor
const webEditor = spawn('node', ['src/web_editor/server.js'], {
stdio: 'inherit',
cwd: process.cwd()
});
webEditor.on('error', (err) => {
console.error('❌ Failed to start web editor:', err);
process.exit(1);
});
// Start bot after a short delay
setTimeout(() => {
console.log('🤖 Starting Discord bot...');
const bot = spawn('node', ['src/index.js'], {
stdio: 'inherit',
cwd: process.cwd()
});
bot.on('error', (err) => {
console.error('❌ Failed to start bot:', err);
process.exit(1);
});
bot.on('exit', (code) => {
console.log(`🤖 Bot exited with code ${code}`);
webEditor.kill();
process.exit(code);
});
// Handle graceful shutdown
process.on('SIGINT', () => {
console.log('\n🛑 Shutting down...');
bot.kill();
webEditor.kill();
process.exit(0);
});
process.on('SIGTERM', () => {
console.log('\n🛑 Shutting down...');
bot.kill();
webEditor.kill();
process.exit(0);
});
}, 2000);
webEditor.on('exit', (code) => {
console.log(`🌐 Web editor exited with code ${code}`);
process.exit(code);
});