2022-06-19 00:25:21 +00:00
|
|
|
import {PluginInputHandler} from "./index";
|
2016-10-09 19:14:02 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
import Msg, {MessageType} from "../../models/msg";
|
|
|
|
import Config from "../../config";
|
|
|
|
import {ChanType, ChanState} from "../../models/chan";
|
2014-09-13 21:29:45 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const commands = ["close", "leave", "part"];
|
|
|
|
const allowDisconnected = true;
|
2016-03-06 09:24:56 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const input: PluginInputHandler = function (network, chan, cmd, args) {
|
2020-03-15 18:16:53 +00: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 14:18:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (target.type === ChanType.LOBBY) {
|
2019-07-17 09:33:59 +00:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 09:33:59 +00:00
|
|
|
text: "You can not part from networks, use /quit instead.",
|
|
|
|
})
|
|
|
|
);
|
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
|
2019-07-17 09:33:59 +00:00
|
|
|
if (
|
2022-06-19 00:25:21 +00:00
|
|
|
target.type !== ChanType.CHANNEL ||
|
|
|
|
target.state === ChanState.PARTED ||
|
2019-07-17 09:33:59 +00:00
|
|
|
!network.irc ||
|
|
|
|
!network.irc.connection ||
|
|
|
|
!network.irc.connection.connected
|
|
|
|
) {
|
2021-12-29 14:46:06 +00:00
|
|
|
this.part(network, target);
|
2018-01-30 17:52:52 +00:00
|
|
|
} else {
|
2022-05-01 19:12:39 +00:00
|
|
|
const partMessage = args.join(" ") || network.leaveMessage || Config.values.leaveMessage;
|
2018-01-30 17:52:52 +00:00
|
|
|
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
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
commands,
|
|
|
|
input,
|
|
|
|
allowDisconnected,
|
|
|
|
};
|