2022-06-19 02:25:21 +02:00
|
|
|
import {PluginInputHandler} from "./index";
|
2016-10-09 21:14:02 +02:00
|
|
|
|
2022-06-19 02:25:21 +02:00
|
|
|
import Msg, {MessageType} from "../../models/msg";
|
2016-10-01 19:04:03 +02:00
|
|
|
|
2022-06-19 02:25:21 +02:00
|
|
|
const commands = ["nick"];
|
|
|
|
const allowDisconnected = true;
|
2016-10-01 19:04:03 +02:00
|
|
|
|
2022-06-19 02:25:21 +02:00
|
|
|
const input: PluginInputHandler = function (network, chan, cmd, args) {
|
2016-10-01 19:04:03 +02:00
|
|
|
if (args.length === 0) {
|
2019-07-17 11:33:59 +02:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-19 02:25:21 +02:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 11:33:59 +02:00
|
|
|
text: "Usage: /nick <your new nick>",
|
|
|
|
})
|
|
|
|
);
|
2016-10-01 19:04:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length !== 1) {
|
2019-07-17 11:33:59 +02:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-19 02:25:21 +02:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 11:33:59 +02:00
|
|
|
text: "Nicknames may not contain spaces.",
|
|
|
|
})
|
|
|
|
);
|
2016-10-01 19:04:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 12:33:36 +01:00
|
|
|
const newNick = args[0];
|
2016-10-01 19:04:03 +02:00
|
|
|
|
2018-10-20 13:10:26 +02:00
|
|
|
if (newNick.length > 100) {
|
2019-07-17 11:33:59 +02:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-19 02:25:21 +02:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 11:33:59 +02:00
|
|
|
text: "Nicknames may not be this long.",
|
|
|
|
})
|
|
|
|
);
|
2018-10-20 13:10:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-15 21:35:18 +02:00
|
|
|
// If we were trying to keep a nick and user changes nick, stop trying to keep the old one
|
|
|
|
network.keepNick = null;
|
|
|
|
|
2016-10-01 19:04:03 +02:00
|
|
|
// If connected to IRC, send to server and wait for ACK
|
|
|
|
// otherwise update the nick and UI straight away
|
2019-09-15 21:35:18 +02:00
|
|
|
if (network.irc) {
|
2023-03-04 18:16:28 +01:00
|
|
|
if (network.irc.connected) {
|
2019-09-15 21:35:18 +02:00
|
|
|
network.irc.changeNick(newNick);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
network.irc.options.nick = network.irc.user.nick = newNick;
|
2016-10-01 19:04:03 +02:00
|
|
|
}
|
2019-09-15 21:35:18 +02:00
|
|
|
|
|
|
|
network.setNick(newNick);
|
|
|
|
|
|
|
|
this.emit("nick", {
|
|
|
|
network: network.uuid,
|
|
|
|
nick: newNick,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.save();
|
2016-10-01 19:04:03 +02:00
|
|
|
};
|
2022-06-19 02:25:21 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
commands,
|
|
|
|
input,
|
|
|
|
allowDisconnected,
|
|
|
|
};
|