implement new sendTo method

This commit is contained in:
Evert Prants 2021-10-01 20:36:42 +03:00
parent 7b5ff2d7c4
commit 22a1f2c1fa
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 31 additions and 9 deletions

View File

@ -3,7 +3,7 @@
"name": "irc",
"description": "IRC Service for Squeebot 3",
"tags": ["service", "irc"],
"version": "1.1.1",
"version": "1.1.2",
"dependencies": ["control?"],
"npmDependencies": []
}

View File

@ -195,9 +195,35 @@ class IRCProtocol extends Protocol {
}
public resolve(message: IMessage, ...data: any[]): void {
const response = this.parseMessage(...data);
if (!this.irc.alive || !response) {
return;
}
this.irc.message(message.target!.id, response);
}
public async sendTo(target: string, ...data: any[]): Promise<boolean> {
const response = this.parseMessage(...data);
if (!this.irc.alive || !response) {
return false;
}
const rxSplit = target.split('/');
if (rxSplit.length !== 3 || rxSplit[0] !== 'irc' || rxSplit[1] !== this.name) {
return false;
}
this.irc.message(rxSplit[2], response);
return true;
}
private parseMessage(...data: any[]): string | null {
let response = util.format(data[0], ...data.slice(1));
if (!response) {
return;
return null;
}
if (Array.isArray(data[0])) {
@ -205,15 +231,11 @@ class IRCProtocol extends Protocol {
response = this.format.compose(data[0]);
} catch (e: any) {
logger.error('[%s] Failed to compose message:', this.fullName, e.message);
return;
return null;
}
}
if (!this.irc.alive) {
return;
}
this.irc.message(message.target!.id, response);
return response;
}
}

View File

@ -3,7 +3,7 @@
"plugins": [
{
"name": "irc",
"version": "1.1.1"
"version": "1.1.2"
},
{
"name": "ircprototest",