thelounge/server/plugins/inputs/nick.ts

74 lines
1.3 KiB
TypeScript
Raw Normal View History

import {PluginInputHandler} from "./index";
import Msg, {MessageType} from "../../models/msg";
const commands = ["nick"];
const allowDisconnected = true;
const input: PluginInputHandler = function (network, chan, cmd, args) {
if (args.length === 0) {
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: "Usage: /nick <your new nick>",
})
);
return;
}
if (args.length !== 1) {
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: "Nicknames may not contain spaces.",
})
);
return;
}
2018-01-11 11:33:36 +00:00
const newNick = args[0];
if (newNick.length > 100) {
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: "Nicknames may not be this long.",
})
);
return;
}
2019-09-15 19:35:18 +00:00
// If we were trying to keep a nick and user changes nick, stop trying to keep the old one
network.keepNick = null;
// If connected to IRC, send to server and wait for ACK
// otherwise update the nick and UI straight away
2019-09-15 19:35:18 +00:00
if (network.irc) {
if (network.irc.connected) {
2019-09-15 19:35:18 +00:00
network.irc.changeNick(newNick);
return;
}
network.irc.options.nick = network.irc.user.nick = newNick;
}
2019-09-15 19:35:18 +00:00
network.setNick(newNick);
this.emit("nick", {
network: network.uuid,
nick: newNick,
});
this.save();
};
export default {
commands,
input,
allowDisconnected,
};