thelounge/server/plugins/inputs/part.ts

55 lines
1.3 KiB
TypeScript
Raw Normal View History

import {PluginInputHandler} from "./index";
import Msg, {MessageType} from "../../models/msg";
import Config from "../../config";
import {ChanType, ChanState} from "../../models/chan";
2014-09-13 23:29:45 +02:00
const commands = ["close", "leave", "part"];
const allowDisconnected = true;
2016-03-06 10:24:56 +01:00
const input: PluginInputHandler = 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 === ChanType.LOBBY) {
2019-07-17 11:33:59 +02:00
chan.pushMessage(
this,
new Msg({
type: MessageType.ERROR,
2019-07-17 11:33:59 +02:00
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 !== ChanType.CHANNEL ||
target.state === ChanState.PARTED ||
!network.irc.connected
2019-07-17 11:33:59 +02:00
) {
this.part(network, target);
} else {
const partMessage = args.join(" ") || network.leaveMessage || Config.values.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
};
export default {
commands,
input,
allowDisconnected,
};