implement new sendTo method
This commit is contained in:
parent
43c1edb907
commit
83abe6cc75
@ -3,7 +3,7 @@
|
|||||||
"name": "matrix",
|
"name": "matrix",
|
||||||
"description": "Matrix.org Service for Squeebot 3",
|
"description": "Matrix.org Service for Squeebot 3",
|
||||||
"tags": ["service", "matrix"],
|
"tags": ["service", "matrix"],
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"dependencies": ["control?"],
|
"dependencies": ["control?"],
|
||||||
"npmDependencies": ["matrix-bot-sdk@0.5.12"]
|
"npmDependencies": ["matrix-bot-sdk@0.5.19"]
|
||||||
}
|
}
|
||||||
|
@ -180,26 +180,36 @@ class MatrixProtocol extends Protocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public resolve(msg: MatrixMessageAdapter, ...data: any[]): void {
|
public resolve(msg: MatrixMessageAdapter, ...data: any[]): void {
|
||||||
let response = util.format(data[0], ...data.slice(1));
|
if (!msg.target) {
|
||||||
if (!response || !msg.target) {
|
|
||||||
return;
|
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])) {
|
if (Array.isArray(data[0])) {
|
||||||
try {
|
try {
|
||||||
response = this.format.compose(data[0]);
|
response = this.format.compose(data[0]);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
logger.error('[%s] Failed to compose message:', this.fullName, e.message);
|
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',
|
msgtype: 'm.text',
|
||||||
body: this.format.strip(response),
|
body: this.format.strip(response),
|
||||||
format: 'org.matrix.custom.html',
|
format: 'org.matrix.custom.html',
|
||||||
formatted_body: response.replace('\n', '<br />'),
|
formatted_body: response.replace('\n', '<br />'),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1844
package-lock.json
generated
1844
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -11,8 +11,8 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@squeebot/core": "^3.1.1",
|
"@squeebot/core": "^3.3.2",
|
||||||
"matrix-bot-sdk": "^0.5.12",
|
"matrix-bot-sdk": "^0.5.19",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"plugins": [
|
"plugins": [
|
||||||
{
|
{
|
||||||
"name": "matrix",
|
"name": "matrix",
|
||||||
"version": "1.0.0"
|
"version": "1.0.1"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"typescript": true
|
"typescript": true
|
||||||
|
Loading…
Reference in New Issue
Block a user