muh
This commit is contained in:
parent
7c87736cb3
commit
205ede37a2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
node_modules/
|
||||
cfg/*.json
|
||||
b/
|
||||
log/*.log
|
||||
|
47
bot.js
Normal file
47
bot.js
Normal file
@ -0,0 +1,47 @@
|
||||
var forever = require('forever-monitor');
|
||||
var fs = require('fs-extra');
|
||||
|
||||
var getDateTimeString = () => {
|
||||
var date = new Date();
|
||||
var hour = date.getHours();
|
||||
hour = (hour < 10 ? "0" : "") + hour;
|
||||
var min = date.getMinutes();
|
||||
min = (min < 10 ? "0" : "") + min;
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth() + 1;
|
||||
month = (month < 10 ? "0" : "") + month;
|
||||
var day = date.getDate();
|
||||
day = (day < 10 ? "0" : "") + day;
|
||||
return year + "-" + month + "-" + day + "_" + hour + "-" + min;
|
||||
};
|
||||
var log = './log/bot_'+getDateTimeString()+'.log';
|
||||
var putlog = (msg) => {
|
||||
fs.appendFileSync(log, msg, 'utf8');
|
||||
};
|
||||
|
||||
var child = new (forever.Monitor)('./src/main.js', {
|
||||
max: 3,
|
||||
silent: false,
|
||||
args: []
|
||||
});
|
||||
|
||||
child.on('watch:restart', (info) => {
|
||||
putlog('Restaring bot because ' + info.file + ' changed\n');
|
||||
});
|
||||
child.on('restart', () => {
|
||||
putlog('restarting bot for ' + child.times + ' time\n');
|
||||
});
|
||||
child.on('start', () => {
|
||||
putlog('starting bot\n');
|
||||
});
|
||||
child.on('exit:code', (code) => {
|
||||
putlog('detected bot exited with code ' + code + '\n');
|
||||
});
|
||||
child.on('stdout', (data) => {
|
||||
putlog(data);
|
||||
});
|
||||
child.on('stderr', (data) => {
|
||||
putlog(data);
|
||||
});
|
||||
|
||||
child.start();
|
0
log/.gitkeep
Normal file
0
log/.gitkeep
Normal file
@ -3,11 +3,12 @@
|
||||
"version": "0.1.1",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
"start": "node src/main.js"
|
||||
"start": "node ./bot.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"coffea": "^0.4.24",
|
||||
"du": "^0.1.0",
|
||||
"forever-monitor": "^1.7.0",
|
||||
"fs-extra": "^0.30.0",
|
||||
"mime": "^1.3.4",
|
||||
"mysql": "^2.11.1",
|
||||
@ -22,4 +23,4 @@
|
||||
},
|
||||
"author": "Flummi & jkhsjdhjs",
|
||||
"license": "WTFPL"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user