|
@ -10,11 +10,13 @@ class Bot { |
|
|
config: any; |
|
|
config: any; |
|
|
buildInfo: string; |
|
|
buildInfo: string; |
|
|
connected: boolean; |
|
|
connected: boolean; |
|
|
|
|
|
startTime: Date; |
|
|
|
|
|
|
|
|
constructor(config, buildInfo) { |
|
|
constructor(config, buildInfo) { |
|
|
this.config = config; |
|
|
this.config = config; |
|
|
this.buildInfo = buildInfo; |
|
|
this.buildInfo = buildInfo; |
|
|
this.connected = false; |
|
|
this.connected = false; |
|
|
|
|
|
this.startTime = new Date(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -79,28 +81,28 @@ class Bot { |
|
|
|
|
|
|
|
|
let attemptPasswordLogin = (botClient, botConfig) => { |
|
|
let attemptPasswordLogin = (botClient, botConfig) => { |
|
|
return botClient.loginWithPassword(botConfig.userId, botConfig.userPassword) |
|
|
return botClient.loginWithPassword(botConfig.userId, botConfig.userPassword) |
|
|
.then((data) => { |
|
|
|
|
|
logger.info("Successfully authenticated with password %o", data); |
|
|
|
|
|
return startServerConnection(); |
|
|
|
|
|
}, (err) => { |
|
|
|
|
|
logger.error("Failed to authenticate with password %o", err); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
.then((data) => { |
|
|
|
|
|
logger.info("Successfully authenticated with password %o", data); |
|
|
|
|
|
return startServerConnection(); |
|
|
|
|
|
}, (err) => { |
|
|
|
|
|
logger.error("Failed to authenticate with password %o", err); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
logger.info("Authenticating With Server"); |
|
|
logger.info("Authenticating With Server"); |
|
|
if (typeof botConfig.accessToken !== 'undefined') { |
|
|
if (typeof botConfig.accessToken !== 'undefined') { |
|
|
await botClient.loginWithToken(this.config.accessToken) |
|
|
await botClient.loginWithToken(this.config.accessToken) |
|
|
.then((data) => { |
|
|
|
|
|
logger.info("Successfully authenticated with access token %o", data); |
|
|
|
|
|
return startServerConnection(); |
|
|
|
|
|
}, (err) => { |
|
|
|
|
|
logger.error("Failed to authenticate with access token %o", err); |
|
|
|
|
|
if (typeof botConfig.userPassword !== 'undefined') { |
|
|
|
|
|
return attemptPasswordLogin(botClient, botConfig); |
|
|
|
|
|
} else { |
|
|
|
|
|
logger.error("No fallback password provided!"); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
.then((data) => { |
|
|
|
|
|
logger.info("Successfully authenticated with access token %o", data); |
|
|
|
|
|
return startServerConnection(); |
|
|
|
|
|
}, (err) => { |
|
|
|
|
|
logger.error("Failed to authenticate with access token %o", err); |
|
|
|
|
|
if (typeof botConfig.userPassword !== 'undefined') { |
|
|
|
|
|
return attemptPasswordLogin(botClient, botConfig); |
|
|
|
|
|
} else { |
|
|
|
|
|
logger.error("No fallback password provided!"); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} else if (typeof botConfig.userPassword !== 'undefined') { |
|
|
} else if (typeof botConfig.userPassword !== 'undefined') { |
|
|
await attemptPasswordLogin(botClient, botConfig); |
|
|
await attemptPasswordLogin(botClient, botConfig); |
|
|
} else { |
|
|
} else { |
|
@ -151,7 +153,7 @@ class Bot { |
|
|
this.config.statusRooms.forEach(roomId => { |
|
|
this.config.statusRooms.forEach(roomId => { |
|
|
logger.debug("Notifying %s of startup", roomId); |
|
|
logger.debug("Notifying %s of startup", roomId); |
|
|
promises.push(this.client.sendMessage( |
|
|
promises.push(this.client.sendMessage( |
|
|
roomId, message.createBasic("Started with version: " + this.buildInfo, message.types.NOTICE) |
|
|
|
|
|
|
|
|
roomId, message.createBasic(`Started at ${utility.toISODateString(this.startTime)} with version: ${this.buildInfo}`, message.types.NOTICE) |
|
|
).then(() => { |
|
|
).then(() => { |
|
|
logger.debug("Notified %s of startup", roomId); |
|
|
logger.debug("Notified %s of startup", roomId); |
|
|
}, (err) => { |
|
|
}, (err) => { |
|
@ -170,7 +172,7 @@ class Bot { |
|
|
this.config.statusRooms.forEach(roomId => { |
|
|
this.config.statusRooms.forEach(roomId => { |
|
|
logger.debug("Notifying %s of shutdown", roomId); |
|
|
logger.debug("Notifying %s of shutdown", roomId); |
|
|
promises.push(this.client.sendMessage( |
|
|
promises.push(this.client.sendMessage( |
|
|
roomId, message.createBasic("Shutting down", message.types.NOTICE) |
|
|
|
|
|
|
|
|
roomId, message.createBasic(`Shutting down at ${utility.toISODateString(new Date())} with version: ${this.buildInfo}`, message.types.NOTICE) |
|
|
).then(() => { |
|
|
).then(() => { |
|
|
logger.debug("Notified %s of shutdown", roomId); |
|
|
logger.debug("Notified %s of shutdown", roomId); |
|
|
}, (err) => { |
|
|
}, (err) => { |
|
|