2016-10-09 15:14:02 -04:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-11 06:33:36 -05:00
|
|
|
const Msg = require("../../models/msg");
|
2016-10-01 13:04:03 -04:00
|
|
|
|
|
|
|
exports.commands = ["nick"];
|
|
|
|
exports.allowDisconnected = true;
|
|
|
|
|
|
|
|
exports.input = function(network, chan, cmd, args) {
|
|
|
|
if (args.length === 0) {
|
2019-07-17 05:33:59 -04:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: "Usage: /nick <your new nick>",
|
|
|
|
})
|
|
|
|
);
|
2016-10-01 13:04:03 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length !== 1) {
|
2019-07-17 05:33:59 -04:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: "Nicknames may not contain spaces.",
|
|
|
|
})
|
|
|
|
);
|
2016-10-01 13:04:03 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 06:33:36 -05:00
|
|
|
const newNick = args[0];
|
2016-10-01 13:04:03 -04:00
|
|
|
|
2018-10-20 07:10:26 -04:00
|
|
|
if (newNick.length > 100) {
|
2019-07-17 05:33:59 -04:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: "Nicknames may not be this long.",
|
|
|
|
})
|
|
|
|
);
|
2018-10-20 07:10:26 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-01 13:04:03 -04:00
|
|
|
// If connected to IRC, send to server and wait for ACK
|
|
|
|
// otherwise update the nick and UI straight away
|
|
|
|
if (network.irc && network.irc.connection) {
|
|
|
|
network.irc.raw("NICK", newNick);
|
|
|
|
} else {
|
|
|
|
network.setNick(newNick);
|
|
|
|
|
|
|
|
this.emit("nick", {
|
2018-04-26 05:06:01 -04:00
|
|
|
network: network.uuid,
|
2017-11-15 01:35:15 -05:00
|
|
|
nick: newNick,
|
2016-10-01 13:04:03 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|