From 4d9c01deea6c466cb132d5537497beee75786b67 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 22 Feb 2019 14:04:33 +0200 Subject: [PATCH] Put channel errors and unhandled numerics to relevant channel if it exists --- src/plugins/irc-events/error.js | 17 +++++++++++++++-- src/plugins/irc-events/unhandled.js | 12 +++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/plugins/irc-events/error.js b/src/plugins/irc-events/error.js index ab260621..98dedfaf 100644 --- a/src/plugins/irc-events/error.js +++ b/src/plugins/irc-events/error.js @@ -21,13 +21,26 @@ module.exports = function(irc, network) { text += data.error; } - const lobby = network.channels[0]; const msg = new Msg({ type: Msg.Type.ERROR, text: text, showInActive: true, }); - lobby.pushMessage(client, msg, true); + + let target = network.channels[0]; + + // If this error is channel specific and a channel + // with this name exists, put this error in that channel + if (data.channel) { + const channel = network.getChannel(data.channel); + + if (typeof channel !== "undefined") { + target = channel; + msg.showInActive = false; + } + } + + target.pushMessage(client, msg, true); }); irc.on("nick in use", function(data) { diff --git a/src/plugins/irc-events/unhandled.js b/src/plugins/irc-events/unhandled.js index f9c111ac..1fb66270 100644 --- a/src/plugins/irc-events/unhandled.js +++ b/src/plugins/irc-events/unhandled.js @@ -6,12 +6,22 @@ module.exports = function(irc, network) { const client = this; irc.on("unknown command", function(command) { + let target = network.channels[0]; + // Do not display users own name if (command.params[0] === network.irc.user.nick) { command.params.shift(); + } else { + // If this numeric starts with a channel name that exists + // put this message in that channel + const channel = network.getChannel(command.params[0]); + + if (typeof channel !== "undefined") { + target = channel; + } } - network.channels[0].pushMessage(client, new Msg({ + target.pushMessage(client, new Msg({ type: Msg.Type.UNHANDLED, command: command.command, params: command.params,