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