implement new sendTo method

This commit is contained in:
Evert Prants 2021-10-02 11:21:49 +03:00
parent 43c1edb907
commit 83abe6cc75
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
5 changed files with 1731 additions and 145 deletions

View File

@ -3,7 +3,7 @@
"name": "matrix",
"description": "Matrix.org Service for Squeebot 3",
"tags": ["service", "matrix"],
"version": "1.0.0",
"version": "1.0.1",
"dependencies": ["control?"],
"npmDependencies": ["matrix-bot-sdk@0.5.12"]
"npmDependencies": ["matrix-bot-sdk@0.5.19"]
}

View File

@ -180,26 +180,36 @@ class MatrixProtocol extends Protocol {
}
public resolve(msg: MatrixMessageAdapter, ...data: any[]): void {
let response = util.format(data[0], ...data.slice(1));
if (!response || !msg.target) {
if (!msg.target) {
return;
}
this.sendTo(msg.target.id, ...data);
}
public async sendTo(target: string, ...data: any[]): Promise<boolean> {
let response = util.format(data[0], ...data.slice(1));
if (!response || !target) {
return false;
}
if (Array.isArray(data[0])) {
try {
response = this.format.compose(data[0]);
} catch (e) {
} catch (e: any) {
logger.error('[%s] Failed to compose message:', this.fullName, e.message);
return;
return false;
}
}
this.client?.sendMessage(msg.target.id, {
await this.client?.sendMessage(target, {
msgtype: 'm.text',
body: this.format.strip(response),
format: 'org.matrix.custom.html',
formatted_body: response.replace('\n', '<br />'),
});
return true;
}
}

1844
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,8 +11,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"@squeebot/core": "^3.1.1",
"matrix-bot-sdk": "^0.5.12",
"typescript": "^4.1.3"
"@squeebot/core": "^3.3.2",
"matrix-bot-sdk": "^0.5.19",
"typescript": "^4.4.2"
}
}

View File

@ -3,7 +3,7 @@
"plugins": [
{
"name": "matrix",
"version": "1.0.0"
"version": "1.0.1"
}
],
"typescript": true