f0ckv1/bot.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-10-07 01:03:08 +00:00
var forever = require(__dirname+'/node_modules/forever-monitor');
var fs = require(__dirname+'/node_modules/fs-extra');
2016-08-31 19:31:59 +00:00
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;
};
2016-10-07 01:03:08 +00:00
var log_forever = __dirname+'/log/forever_'+getDateTimeString()+'.log';
var log_bot = __dirname+'/log/bot_'+getDateTimeString()+'.log';
var err_bot = __dirname+'/log/err_'+getDateTimeString()+'.log';
2016-08-31 19:31:59 +00:00
var putlog = (msg) => {
2016-08-31 20:21:12 +00:00
fs.appendFileSync(log_forever, msg, 'utf8');
2016-08-31 19:31:59 +00:00
};
2016-10-07 01:03:08 +00:00
var child = new (forever.Monitor)(__dirname+'/src/main.js', {
2016-08-31 20:21:12 +00:00
max: 1,
2016-09-08 15:42:38 +00:00
silent: false,
2016-10-07 01:03:08 +00:00
cwd: __dirname,
2016-08-31 20:21:12 +00:00
args: [],
2016-09-10 13:34:01 +00:00
spinSleepTime: 2000,
2016-08-31 20:21:12 +00:00
watch: true,
watchIgnoreDotFiles: true,
watchIgnorePatterns: [
2016-09-10 13:34:01 +00:00
'*.log', 'b/*', 't/*', 'node_modules/*'
2016-08-31 20:21:12 +00:00
],
watchDirectory: __dirname,
outFile: log_bot,
2016-09-14 22:05:18 +00:00
errFile: err_bot
2016-08-31 19:31:59 +00:00
});
child.on('watch:restart', (info) => {
2016-08-31 20:21:12 +00:00
putlog('Restaring bot because ' + info.stat + ' changed\n');
2016-08-31 19:31:59 +00:00
});
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');
2016-09-01 07:56:53 +00:00
child.restart();
2016-08-31 19:31:59 +00:00
});
child.start();