allows newlines

This commit is contained in:
Flummi 2018-02-14 00:33:00 +01:00
parent 89cda0e25c
commit f6fc8d37d0
2 changed files with 14 additions and 5 deletions

View File

@ -12,6 +12,11 @@ const colors = {
blue: "\x0312$1\x0312", blue: "\x0312$1\x0312",
yellow: "\x0308$1\x0308" 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) => { const replaceColor = (match, color, text) => {
if (colors.hasOwnProperty(color)) if (colors.hasOwnProperty(color))
@ -68,6 +73,11 @@ export class irc extends EventEmitter {
this.socket.write(`${data}\n`); this.socket.write(`${data}\n`);
logger.debug(`(${this.network}) out: ${data}`); 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(/ +:/)) { parse(data, [a, ...b] = data.split(/ +:/)) {
let tmp = a.split(" ").concat(b); let tmp = a.split(" ").concat(b);
logger.debug(`(${this.network}) in: ${[...tmp]}`); logger.debug(`(${this.network}) in: ${[...tmp]}`);
@ -97,9 +107,9 @@ export class irc extends EventEmitter {
message: tmp.params[1], message: tmp.params[1],
time: ~~(Date.now() / 1000), time: ~~(Date.now() / 1000),
raw: tmp, raw: tmp,
reply: msg => this.send(`PRIVMSG ${tmp.params[0]} :${this.format(""+msg)}`), reply: msg => this.sendmsg("normal", tmp.params[0], this.format(""+msg)),
replyAction: msg => this.send(`PRIVMSG ${tmp.params[0]} :\u0001ACTION ${this.format(""+msg)}\u0001`), replyAction: msg => this.sendmsg("action", tmp.params[0], this.format(""+msg)),
replyNotice: msg => this.send(`NOTICE ${tmp.params[0]} :${this.format(""+msg)}`), replyNotice: msg => this.sendmsg("notice", tmp.params[0], this.format(""+msg)),
self: this.server, self: this.server,
_chan: this.server.channel[tmp.params[0]], _chan: this.server.channel[tmp.params[0]],
_user: this.server.user, _user: this.server.user,

View File

@ -4,8 +4,7 @@ export default bot => {
f: e => { f: e => {
if(e.args[0] && [...bot._trigger.keys()].includes(e.args[0])) { if(e.args[0] && [...bot._trigger.keys()].includes(e.args[0])) {
const help = bot._trigger.get(e.args[0]).help; const help = bot._trigger.get(e.args[0]).help;
e.reply(help.text); e.reply(`${help.text}\nusage: ${help.usage}`);
e.reply(`usage: ${help.usage}`);
} }
else { else {
let triggers = []; let triggers = [];