|
|
@ -17,7 +17,6 @@ class Bot { |
|
|
|
logger.info("Creating Matrix Client") |
|
|
|
this.client = sdk.createClient({ |
|
|
|
baseUrl: this.config.baseUrl, |
|
|
|
accessToken: this.config.accessToken, |
|
|
|
userId: this.config.userId |
|
|
|
}); |
|
|
|
|
|
|
@ -60,8 +59,39 @@ class Bot { |
|
|
|
async connect() { |
|
|
|
// logger.info("Initializing Crypto");
|
|
|
|
// await bot.client.initCrypto();
|
|
|
|
logger.info("Starting Matrix SDK Client"); |
|
|
|
await this.client.startClient(); |
|
|
|
let botClient = this.client; |
|
|
|
let botConfig = this.config; |
|
|
|
|
|
|
|
let startServerConnection = async () => { |
|
|
|
logger.info("Starting Matrix SDK Client"); |
|
|
|
await this.client.startClient(); |
|
|
|
} |
|
|
|
|
|
|
|
let connectWithPassword = (err, data) => { |
|
|
|
if (err === null) { |
|
|
|
logger.info("Successfully authenticated with password %o", data); |
|
|
|
startServerConnection(); |
|
|
|
} else { |
|
|
|
logger.error("Failed to authenticate with password %o", err); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let connectWithToken = (err, data) => { |
|
|
|
if (err === null) { |
|
|
|
logger.info("Successfully authenticated with access token %o", data); |
|
|
|
startServerConnection(); |
|
|
|
} else { |
|
|
|
logger.error("Failed to authenticate with access token %o", err); |
|
|
|
if (typeof botConfig.userPassword !== 'undefined') { |
|
|
|
botClient.loginWithPassword(botConfig.userId, botConfig.userPassword, connectWithPassword); |
|
|
|
} else { |
|
|
|
logger.error("No fallback password provided!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("Authenticating With Server"); |
|
|
|
botClient.loginWithToken(this.config.accessToken, connectWithToken); |
|
|
|
} |
|
|
|
|
|
|
|
sendStatusStartup() { |
|
|
|