|
|
@ -71,6 +71,16 @@ class Bot { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
let attemptPasswordLogin = (botClient, botConfig) => { |
|
|
|
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); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("Authenticating With Server"); |
|
|
|
if (typeof botConfig.accessToken !== 'undefined') { |
|
|
|
await botClient.loginWithToken(this.config.accessToken) |
|
|
@ -80,25 +90,13 @@ class Bot { |
|
|
|
}, (err) => { |
|
|
|
logger.error("Failed to authenticate with access token %o", err); |
|
|
|
if (typeof botConfig.userPassword !== 'undefined') { |
|
|
|
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); |
|
|
|
}); |
|
|
|
return attemptPasswordLogin(botClient, botConfig); |
|
|
|
} else { |
|
|
|
logger.error("No fallback password provided!"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (typeof botConfig.userPassword !== 'undefined') { |
|
|
|
await 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); |
|
|
|
}); |
|
|
|
await attemptPasswordLogin(botClient, botConfig); |
|
|
|
} else { |
|
|
|
logger.error("No authentication credentials available!"); |
|
|
|
process.exit(1); |
|
|
@ -169,6 +167,8 @@ class Bot { |
|
|
|
roomId, message.createBasic("Shutting down", message.types.NOTICE) |
|
|
|
).then(() => { |
|
|
|
logger.debug("Notified %s of shutdown", roomId); |
|
|
|
}, (err) => { |
|
|
|
logger.error("Unable to send message to room %s because %s", roomId, err.errcode); |
|
|
|
})); |
|
|
|
}); |
|
|
|
} else { |
|
|
|