implement new sendTo method
This commit is contained in:
parent
7b5ff2d7c4
commit
22a1f2c1fa
@ -3,7 +3,7 @@
|
|||||||
"name": "irc",
|
"name": "irc",
|
||||||
"description": "IRC Service for Squeebot 3",
|
"description": "IRC Service for Squeebot 3",
|
||||||
"tags": ["service", "irc"],
|
"tags": ["service", "irc"],
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"dependencies": ["control?"],
|
"dependencies": ["control?"],
|
||||||
"npmDependencies": []
|
"npmDependencies": []
|
||||||
}
|
}
|
||||||
|
@ -195,9 +195,35 @@ class IRCProtocol extends Protocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public resolve(message: IMessage, ...data: any[]): void {
|
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));
|
let response = util.format(data[0], ...data.slice(1));
|
||||||
if (!response) {
|
if (!response) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(data[0])) {
|
if (Array.isArray(data[0])) {
|
||||||
@ -205,15 +231,11 @@ class IRCProtocol extends Protocol {
|
|||||||
response = this.format.compose(data[0]);
|
response = this.format.compose(data[0]);
|
||||||
} catch (e: any) {
|
} 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 null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.irc.alive) {
|
return response;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.irc.message(message.target!.id, response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"plugins": [
|
"plugins": [
|
||||||
{
|
{
|
||||||
"name": "irc",
|
"name": "irc",
|
||||||
"version": "1.1.1"
|
"version": "1.1.2"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ircprototest",
|
"name": "ircprototest",
|
||||||
|
Loading…
Reference in New Issue
Block a user