implement new sendTo method
This commit is contained in:
parent
7b5ff2d7c4
commit
22a1f2c1fa
@ -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": []
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
"plugins": [
|
||||
{
|
||||
"name": "irc",
|
||||
"version": "1.1.1"
|
||||
"version": "1.1.2"
|
||||
},
|
||||
{
|
||||
"name": "ircprototest",
|
||||
|
Loading…
Reference in New Issue
Block a user