Browse Source

Additional error handling and code cleanup

develop
Drew Short 4 years ago
parent
commit
c13c8fdc64
  1. 5
      README.md
  2. 28
      bot/bot.js

5
README.md

@ -21,7 +21,7 @@ npm install
### Requirements:
Nodejs 12 LTS
NodeJS 12 LTS
OR
@ -32,11 +32,12 @@ Docker
```bash
npm install
#<make changes>
./entrypoint.sh run
./scripts/run_development_local.sh
```
#### Docker:
```bash
#<make changes>
./scripts/run_development_docker.sh
```

28
bot/bot.js

@ -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 {

Loading…
Cancel
Save