diff --git a/lib/chatBot.js b/lib/chatBot.js index e9f4111a..4e9df1d8 100644 --- a/lib/chatBot.js +++ b/lib/chatBot.js @@ -104,8 +104,11 @@ var ChatBot = function(username, password, options) { this.ignores = options.ignores || []; this.startTime = process.hrtime(); this.logoffTime = process.hrtime(); + this.autojoinRooms = undefined; - this.autojoinFile = options.autojoinFile || "bot." + this.name+".autojoin"; this.autojoinRooms = undefined; + if(!fs.existsSync(this.name)) { fs.mkdirSync(this.name); } + + this.autojoinFile = options.autojoinFile || this.getOrMove("bot." + this.name+".autojoin"); this.winston.add(winston.transports.Console,{ handleExceptions: false, @@ -116,8 +119,11 @@ var ChatBot = function(username, password, options) { }); if(!options.logFile || options.logFile !== false || options.logFile === null || options.logFile === undefined) { - if(options.logFile === true) { that.logFile = "bot." + that.name + ".log"; } - else { that.logFile = options.logFile; } + if(options.logFile === true || !options.logFile) { + that.logFile = that.getOrMove("bot." + that.name + ".log"); + } else { + that.logFile = options.logFile; + } that.winston.info("Chatbot "+that.name+" logging output to: " + that.logFile); that.winston.add( winston.transports.File, { @@ -150,7 +156,12 @@ var ChatBot = function(username, password, options) { this.name+".hash", this.name+".sentry" ], function(val) { - return fs.existsSync(val); + if(fs.existsSync(val)) { + return that.getOrMove(val); + } + if(fs.existsSync(that.name+"/"+val)) { + return that.name+"/"+val; + } }); if ("undefined" !== typeof sentryFile) { this.sentryFile = sentryFile; @@ -160,7 +171,7 @@ var ChatBot = function(username, password, options) { this.winston.warn("Chatbot "+that.name+": Sentry file sentry detected, but it may be incorrect as it does not claim a username. If correct, please rename to bot." + this.name + ".sentry or another supported sentry filename, or rename and define file name in config."); } else { - this.sentryFile = "bot."+this.name+".sentry"; + this.sentryFile = this.name+"/"+"bot."+this.name+".sentry"; this.winston.warn("Chatbot "+that.name+": Could not detect a sentryfile, and no guardCode defined. Using default sentryFile " + this.sentryFile + ". I hope you have a guardCode defined or steamguard disabled. "); } @@ -1078,4 +1089,10 @@ ChatBot.prototype._getClientIp = function(req) { } return ipAddress; }; +ChatBot.prototype.getOrMove = function(name) { + if(fs.existsSync(name)) { + fs.renameSync(name,bot.name+"/"+name); + } + return bot.name+"/"+name; +} exports.ChatBot = ChatBot;