|
@ -67,7 +67,7 @@ class Bot { |
|
|
let startServerConnection = async () => { |
|
|
let startServerConnection = async () => { |
|
|
logger.info("Starting Matrix SDK Client"); |
|
|
logger.info("Starting Matrix SDK Client"); |
|
|
await this.client.startClient(); |
|
|
await this.client.startClient(); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let connectWithPassword = (err, data) => { |
|
|
let connectWithPassword = (err, data) => { |
|
|
if (err === null) { |
|
|
if (err === null) { |
|
@ -96,7 +96,7 @@ class Bot { |
|
|
botClient.loginWithToken(this.config.accessToken, connectWithToken); |
|
|
botClient.loginWithToken(this.config.accessToken, connectWithToken); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
updateAvatar(avatarFile, overwrite=false) { |
|
|
|
|
|
|
|
|
updateAvatar(avatarFile, overwrite = false) { |
|
|
let matrixClient = this.client; |
|
|
let matrixClient = this.client; |
|
|
let botConfig = this.config; |
|
|
let botConfig = this.config; |
|
|
let promises = [Promise.resolve(true)]; |
|
|
let promises = [Promise.resolve(true)]; |
|
@ -104,7 +104,7 @@ class Bot { |
|
|
promises.push(this.client.getProfileInfo(this.config.userId, "avatar_url") |
|
|
promises.push(this.client.getProfileInfo(this.config.userId, "avatar_url") |
|
|
.then((existingAvatarUrl) => { |
|
|
.then((existingAvatarUrl) => { |
|
|
logger.info("Recieved avatar_url: %o", existingAvatarUrl); |
|
|
logger.info("Recieved avatar_url: %o", existingAvatarUrl); |
|
|
if (typeof existingAvatarUrl !== 'undefined' && typeof existingAvatarUrl == 'object' |
|
|
|
|
|
|
|
|
if (typeof existingAvatarUrl !== 'undefined' && typeof existingAvatarUrl == 'object' |
|
|
&& existingAvatarUrl.constructor === Object && Object.keys(existingAvatarUrl).length !== 0 |
|
|
&& existingAvatarUrl.constructor === Object && Object.keys(existingAvatarUrl).length !== 0 |
|
|
&& !overwrite) { |
|
|
&& !overwrite) { |
|
|
logger.info("Avatar already set"); |
|
|
logger.info("Avatar already set"); |
|
@ -117,13 +117,13 @@ class Bot { |
|
|
type: "image/jpeg", |
|
|
type: "image/jpeg", |
|
|
rawResponse: false |
|
|
rawResponse: false |
|
|
}).then((uploadedAvatar) => { |
|
|
}).then((uploadedAvatar) => { |
|
|
logger.info("Uploaded avatar %o", uploadedAvatar); |
|
|
|
|
|
matrixClient.setAvatarUrl(uploadedAvatar.content_uri) |
|
|
|
|
|
.then(() => { |
|
|
|
|
|
logger.info("Updated %s avatar to %s", botConfig.userId, uploadedAvatar.content_uri); |
|
|
|
|
|
return true; |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
logger.info("Uploaded avatar %o", uploadedAvatar); |
|
|
|
|
|
matrixClient.setAvatarUrl(uploadedAvatar.content_uri) |
|
|
|
|
|
.then(() => { |
|
|
|
|
|
logger.info("Updated %s avatar to %s", botConfig.userId, uploadedAvatar.content_uri); |
|
|
|
|
|
return true; |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
})); |
|
|
})); |
|
|
} else { |
|
|
} else { |
|
|