From f26c2dad0f085d061a9cba0a93fd4a63121d88d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Michel?= Date: Wed, 30 Aug 2017 16:18:38 +0200 Subject: [PATCH] Take an optional argument in /part Fix #1430 --- client/index.html | 7 +++++-- src/plugins/inputs/part.js | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/client/index.html b/client/index.html index 44b8efed..47f26142 100644 --- a/client/index.html +++ b/client/index.html @@ -787,10 +787,13 @@
- /part + /part [channel]
-

Close the current channel or private message window.

+

+ Close the specified channel or private message window, or the + current channel if channel is ommitted. +

Aliases: /close, /leave

diff --git a/src/plugins/inputs/part.js b/src/plugins/inputs/part.js index 88a46563..0763ee77 100644 --- a/src/plugins/inputs/part.js +++ b/src/plugins/inputs/part.js @@ -9,7 +9,17 @@ exports.commands = ["close", "leave", "part"]; exports.allowDisconnected = true; exports.input = function(network, chan, cmd, args) { - if (chan.type === Chan.Type.LOBBY) { + let target = args.length === 0 ? chan : _.find(network.channels, {name: args[0]}); + let partMessage = args.length <= 1 ? Helper.config.leaveMessage : args.slice(1).join(" "); + + if (typeof target === "undefined") { + // In this case, we assume that the word args[0] is part of the leave + // message and we part the current chan. + target = chan; + partMessage = args.join(" "); + } + + if (target.type === Chan.Type.LOBBY) { chan.pushMessage(this, new Msg({ type: Msg.Type.ERROR, text: "You can not part from networks, use /quit instead." @@ -17,18 +27,17 @@ exports.input = function(network, chan, cmd, args) { return; } - network.channels = _.without(network.channels, chan); - chan.destroy(); + network.channels = _.without(network.channels, target); + target.destroy(); this.emit("part", { - chan: chan.id + chan: target.id }); - if (chan.type === Chan.Type.CHANNEL) { + if (target.type === Chan.Type.CHANNEL) { this.save(); if (network.irc) { - const partMessage = args[0] ? args.join(" ") : Helper.config.leaveMessage; - network.irc.part(chan.name, partMessage); + network.irc.part(target.name, partMessage); } }