thelounge/src/plugins/inputs/part.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

"use strict";
2018-01-11 12:33:36 +01:00
const Msg = require("../../models/msg");
const Chan = require("../../models/chan");
2017-08-18 21:04:16 +02:00
const Helper = require("../../helper");
2014-09-13 23:29:45 +02:00
exports.commands = ["close", "leave", "part"];
exports.allowDisconnected = true;
2016-03-06 10:24:56 +01:00
exports.input = function (network, chan, cmd, args) {
let target = chan;
if (args.length > 0) {
const newTarget = network.getChannel(args[0]);
if (typeof newTarget !== "undefined") {
// If first argument is a channel user is in, part that channel
target = newTarget;
args.shift();
}
}
if (target.type === Chan.Type.LOBBY) {
2019-07-17 11:33:59 +02:00
chan.pushMessage(
this,
new Msg({
type: Msg.Type.ERROR,
text: "You can not part from networks, use /quit instead.",
})
);
2016-03-20 17:34:36 +01:00
return;
}
// If target is not a channel or we are not connected, instantly remove the channel
// Otherwise send part to the server and wait for response
2019-07-17 11:33:59 +02:00
if (
target.type !== Chan.Type.CHANNEL ||
target.state === Chan.State.PARTED ||
!network.irc ||
!network.irc.connection ||
!network.irc.connection.connected
) {
this.part(network, target);
} else {
2020-11-26 00:37:46 +01:00
const partMessage = args.join(" ") || network.leaveMessage || Helper.config.leaveMessage;
network.irc.part(target.name, partMessage);
2016-05-06 10:37:16 +02:00
}
2016-03-06 10:24:56 +01:00
return true;
2014-09-13 23:29:45 +02:00
};