forked from nazedev/hitori
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
28 lines (27 loc) · 774 Bytes
/
start.js
File metadata and controls
28 lines (27 loc) · 774 Bytes
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
const path = require('path');
const chalk = require('chalk');
const { spawn } = require('child_process');
function start() {
let args = [path.join(__dirname, 'index.js'), ...process.argv.slice(2)]
let p = spawn(process.argv[0], args, {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
}).on('message', data => {
if (data === 'reset') {
console.log(chalk.yellow.bold('[BOT] Restarting...'))
p.kill()
start()
delete p
} else if (data === 'uptime') {
p.send(process.uptime())
}
}).on('exit', code => {
if (code !== 0) {
console.error(chalk.red.bold(`[BOT] Exited with code: ${code}`))
start()
} else {
console.log(chalk.green.bold('[BOT] Process exited cleanly. Goodbye!'))
process.exit(0)
}
})
}
start()