From f6fc8d37d0546dbb4df2cde10c0cc47a7c588be7 Mon Sep 17 00:00:00 2001 From: Flummi Date: Wed, 14 Feb 2018 00:33:00 +0100 Subject: [PATCH] allows newlines --- src/clients/irc.mjs | 16 +++++++++++++--- src/inc/trigger/help.mjs | 3 +-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/clients/irc.mjs b/src/clients/irc.mjs index aec2400..15db2ed 100644 --- a/src/clients/irc.mjs +++ b/src/clients/irc.mjs @@ -12,6 +12,11 @@ const colors = { blue: "\x0312$1\x0312", yellow: "\x0308$1\x0308" }; +const msgmodes = { + normal: "PRIVMSG {recipient} :{msg}", + action: "PRIVMSG {recipient} :\u0001ACTION {msg}\u0001", + notice: "NOTICE {recipient} :{msg}" +}; const replaceColor = (match, color, text) => { if (colors.hasOwnProperty(color)) @@ -68,6 +73,11 @@ export class irc extends EventEmitter { this.socket.write(`${data}\n`); logger.debug(`(${this.network}) out: ${data}`); } + sendmsg(mode, recipient, msg) { + msg.split(/\r?\n/).forEach(e => { + this.send( msgmodes[mode].replace("{recipient}", recipient).replace("{msg}", e) ); + }); + } parse(data, [a, ...b] = data.split(/ +:/)) { let tmp = a.split(" ").concat(b); logger.debug(`(${this.network}) in: ${[...tmp]}`); @@ -97,9 +107,9 @@ export class irc extends EventEmitter { message: tmp.params[1], time: ~~(Date.now() / 1000), raw: tmp, - reply: msg => this.send(`PRIVMSG ${tmp.params[0]} :${this.format(""+msg)}`), - replyAction: msg => this.send(`PRIVMSG ${tmp.params[0]} :\u0001ACTION ${this.format(""+msg)}\u0001`), - replyNotice: msg => this.send(`NOTICE ${tmp.params[0]} :${this.format(""+msg)}`), + reply: msg => this.sendmsg("normal", tmp.params[0], this.format(""+msg)), + replyAction: msg => this.sendmsg("action", tmp.params[0], this.format(""+msg)), + replyNotice: msg => this.sendmsg("notice", tmp.params[0], this.format(""+msg)), self: this.server, _chan: this.server.channel[tmp.params[0]], _user: this.server.user, diff --git a/src/inc/trigger/help.mjs b/src/inc/trigger/help.mjs index b02f347..136cb54 100644 --- a/src/inc/trigger/help.mjs +++ b/src/inc/trigger/help.mjs @@ -4,8 +4,7 @@ export default bot => { f: e => { if(e.args[0] && [...bot._trigger.keys()].includes(e.args[0])) { const help = bot._trigger.get(e.args[0]).help; - e.reply(help.text); - e.reply(`usage: ${help.usage}`); + e.reply(`${help.text}\nusage: ${help.usage}`); } else { let triggers = [];