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",
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,

View File

@ -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 = [];