From 868bbea4241c121aa75277cb95a3795fc01cac01 Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 27 Nov 2017 01:29:09 +0100 Subject: [PATCH] global args --- src/bot.js | 14 ++++++++++++-- src/inc/clients/tg.js | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/bot.js b/src/bot.js index e67c8b8..0dc20e7 100644 --- a/src/bot.js +++ b/src/bot.js @@ -39,7 +39,8 @@ read().then(() => { e.reply(`no permission, min level ${trigger.level} required`); break; } - + + e = Object.assign(e, parseArgs(e.message)); trigger.f(e); } logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`); @@ -56,4 +57,13 @@ function trigger(args) { this.active = args.hasOwnProperty("active") ? args.active : true; this.clients = args.clients || ["irc", "tg"]; this.f = args.f; -} \ No newline at end of file +} + +const parseArgs = (msg) => { + let args = msg.trim().split(" "); + let cmd = args.shift(); + return { + cmd: cmd.replace(/^(\.|\/|\!)/, ""), + args: args + }; +}; \ No newline at end of file diff --git a/src/inc/clients/tg.js b/src/inc/clients/tg.js index bba3891..37200e5 100644 --- a/src/inc/clients/tg.js +++ b/src/inc/clients/tg.js @@ -68,7 +68,7 @@ export class tg { }; } format(msg) { - return ""+msg + return msg.toString() .replace("<", "<") .replace(">", ">") .replace(/\[b\](.*?)\[\/b\]/g, "$1") // bold