mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 20:13:07 +00:00
8ca9ee873b
We should not mess with irc-framework internals. Technically we shouldn't even access the connection object, it's not part of the documented API surface
73 lines
1.3 KiB
TypeScript
73 lines
1.3 KiB
TypeScript
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) {
|
|
chan.pushMessage(
|
|
this,
|
|
new Msg({
|
|
type: MessageType.ERROR,
|
|
text: "Usage: /nick <your new nick>",
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (args.length !== 1) {
|
|
chan.pushMessage(
|
|
this,
|
|
new Msg({
|
|
type: MessageType.ERROR,
|
|
text: "Nicknames may not contain spaces.",
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
const newNick = args[0];
|
|
|
|
if (newNick.length > 100) {
|
|
chan.pushMessage(
|
|
this,
|
|
new Msg({
|
|
type: MessageType.ERROR,
|
|
text: "Nicknames may not be this long.",
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
// 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
|
|
if (network.irc) {
|
|
if (network.irc.connected) {
|
|
network.irc.changeNick(newNick);
|
|
|
|
return;
|
|
}
|
|
|
|
network.irc.options.nick = network.irc.user.nick = newNick;
|
|
}
|
|
|
|
network.setNick(newNick);
|
|
|
|
this.emit("nick", {
|
|
network: network.uuid,
|
|
nick: newNick,
|
|
});
|
|
|
|
this.save();
|
|
};
|
|
|
|
export default {
|
|
commands,
|
|
input,
|
|
allowDisconnected,
|
|
};
|