hardlounge/server/plugins/inputs/part.ts

55 lines
1.3 KiB
TypeScript
Raw Permalink 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 21:29:45 +00:00
const commands = ["close", "leave", "part"];
const allowDisconnected = true;
2016-03-06 09:24:56 +00: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 09:33:59 +00:00
chan.pushMessage(
this,
new Msg({
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;
}
// 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 (
target.type !== ChanType.CHANNEL ||
target.state === ChanState.PARTED ||
!network.irc.connected
2019-07-17 09:33:59 +00:00
) {
this.part(network, target);
} else {
const partMessage = args.join(" ") || network.leaveMessage || Config.values.leaveMessage;
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
};
export default {
commands,
input,
allowDisconnected,
};