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