From ad984fa37732b52e605c0582946a7bb5e0e453f4 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 1 Aug 2019 00:16:00 +0300 Subject: [PATCH] Parse target group for sent messages when echo-message is not enabled --- src/plugins/inputs/msg.js | 13 +++++++++++-- src/plugins/inputs/notice.js | 26 ++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/plugins/inputs/msg.js b/src/plugins/inputs/msg.js index db86b208..9f2c74db 100644 --- a/src/plugins/inputs/msg.js +++ b/src/plugins/inputs/msg.js @@ -16,7 +16,7 @@ function getTarget(cmd, args, chan) { } exports.input = function(network, chan, cmd, args) { - const targetName = getTarget(cmd, args, chan); + let targetName = getTarget(cmd, args, chan); if (cmd === "query") { if (!targetName) { @@ -92,6 +92,14 @@ exports.input = function(network, chan, cmd, args) { network.irc.say(targetName, msg); if (!network.irc.network.cap.isEnabled("echo-message")) { + const parsedTarget = network.irc.network.extractTargetGroup(targetName); + let targetGroup; + + if (parsedTarget) { + targetName = parsedTarget.target; + targetGroup = parsedTarget.target_group; + } + const channel = network.getChannel(targetName); if (typeof channel !== "undefined") { @@ -99,7 +107,8 @@ exports.input = function(network, chan, cmd, args) { nick: network.irc.user.nick, ident: network.irc.user.username, hostname: network.irc.user.host, - target: channel.name, + target: targetName, + group: targetGroup, message: msg, }); } diff --git a/src/plugins/inputs/notice.js b/src/plugins/inputs/notice.js index 652f5e63..40823eeb 100644 --- a/src/plugins/inputs/notice.js +++ b/src/plugins/inputs/notice.js @@ -7,20 +7,30 @@ exports.input = function(network, chan, cmd, args) { return; } - let targetChan = network.getChannel(args[0]); + let targetName = args[0]; let message = args.slice(1).join(" "); - network.irc.notice(args[0], message); - - if (typeof targetChan === "undefined") { - message = "{to " + args[0] + "} " + message; - targetChan = chan; - } + network.irc.notice(targetName, message); if (!network.irc.network.cap.isEnabled("echo-message")) { + let targetGroup; + const parsedTarget = network.irc.network.extractTargetGroup(targetName); + + if (parsedTarget) { + targetName = parsedTarget.target; + targetGroup = parsedTarget.target_group; + } + + const targetChan = network.getChannel(targetName); + + if (typeof targetChan === "undefined") { + message = "{to " + args[0] + "} " + message; + } + network.irc.emit("notice", { nick: network.irc.user.nick, - target: targetChan.name, + target: targetName, + group: targetGroup, message: message, }); }