This commit is contained in:
Flummi 2016-08-31 21:31:59 +02:00
parent 7c87736cb3
commit 205ede37a2
4 changed files with 51 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules/
cfg/*.json
b/
log/*.log

47
bot.js Normal file
View 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
View File

View 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",