Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Move default files to automatically-generated bot.name folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Efreak committed Aug 20, 2015
1 parent b5f3433 commit f53cc5a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/chatBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, {
Expand Down Expand Up @@ -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;
Expand All @@ -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. ");
}
Expand Down Expand Up @@ -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;

0 comments on commit f53cc5a

Please sign in to comment.