2016-10-09 21:14:02 +02:00
|
|
|
"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
|
|
|
|
2016-03-14 05:21:42 +01:00
|
|
|
exports.commands = ["close", "leave", "part"];
|
2016-04-03 11:58:59 +02:00
|
|
|
exports.allowDisconnected = true;
|
2016-03-06 10:24:56 +01:00
|
|
|
|
2020-03-21 21:55:36 +01:00
|
|
|
exports.input = function (network, chan, cmd, args) {
|
2020-03-15 19:16:53 +01:00
|
|
|
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();
|
|
|
|
}
|
2017-08-30 16:18:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:52:52 +01:00
|
|
|
// 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
|
|
|
|
) {
|
2021-12-29 15:46:06 +01:00
|
|
|
this.part(network, target);
|
2018-01-30 18:52:52 +01:00
|
|
|
} else {
|
2020-11-26 00:37:46 +01:00
|
|
|
const partMessage = args.join(" ") || network.leaveMessage || Helper.config.leaveMessage;
|
2018-01-30 18:52:52 +01:00
|
|
|
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
|
|
|
};
|