2016-10-09 15:14:02 -04:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-11 06:33:36 -05:00
|
|
|
const _ = require("lodash");
|
|
|
|
const Msg = require("../../models/msg");
|
|
|
|
const Chan = require("../../models/chan");
|
2017-08-18 15:04:16 -04:00
|
|
|
const Helper = require("../../helper");
|
2014-09-13 17:29:45 -04:00
|
|
|
|
2016-03-14 00:21:42 -04:00
|
|
|
exports.commands = ["close", "leave", "part"];
|
2016-04-03 05:58:59 -04:00
|
|
|
exports.allowDisconnected = true;
|
2016-03-06 04:24:56 -05:00
|
|
|
|
2020-03-21 16:55:36 -04:00
|
|
|
exports.input = function (network, chan, cmd, args) {
|
2020-03-15 14:16:53 -04: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 10:18:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target.type === Chan.Type.LOBBY) {
|
2019-07-17 05:33:59 -04:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: "You can not part from networks, use /quit instead.",
|
|
|
|
})
|
|
|
|
);
|
2016-03-20 12:34:36 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-30 12:52:52 -05: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 05:33:59 -04:00
|
|
|
if (
|
|
|
|
target.type !== Chan.Type.CHANNEL ||
|
|
|
|
target.state === Chan.State.PARTED ||
|
|
|
|
!network.irc ||
|
|
|
|
!network.irc.connection ||
|
|
|
|
!network.irc.connection.connected
|
|
|
|
) {
|
2018-01-30 12:52:52 -05:00
|
|
|
network.channels = _.without(network.channels, target);
|
|
|
|
target.destroy();
|
|
|
|
this.emit("part", {
|
|
|
|
chan: target.id,
|
|
|
|
});
|
|
|
|
this.save();
|
|
|
|
} else {
|
2020-03-15 14:16:53 -04:00
|
|
|
const partMessage = args.join(" ") || Helper.config.leaveMessage;
|
2018-01-30 12:52:52 -05:00
|
|
|
network.irc.part(target.name, partMessage);
|
2016-05-06 04:37:16 -04:00
|
|
|
}
|
|
|
|
|
2016-03-06 04:24:56 -05:00
|
|
|
return true;
|
2014-09-13 17:29:45 -04:00
|
|
|
};
|