thelounge/src/plugins/irc-events/error.js
Jérémie Astori 5738642d44
Fix/Improve some nick fallbacks
- Rename a forgotten `lounge-user`
- Generate nick fallbacks when already in use by appending 0-9 instead of 10-98 (?!).
- Generate nick fallbacks when invalid similarly to our config default instead of random string. This is to make it less confusing when fallback gets used.
2018-03-26 03:00:46 -04:00

71 lines
1.6 KiB
JavaScript

"use strict";
const Msg = require("../../models/msg");
module.exports = function(irc, network) {
const client = this;
irc.on("irc error", function(data) {
let text = "";
if (data.channel) {
text = `${data.channel}: `;
}
if (data.error === "user_on_channel") {
text += `User (${data.nick}) is already on channel`;
} else if (data.reason) {
text += `${data.reason} (${data.error})`;
} else {
text += data.error;
}
const lobby = network.channels[0];
const msg = new Msg({
type: Msg.Type.ERROR,
text: text,
showInActive: true,
});
lobby.pushMessage(client, msg, true);
});
irc.on("nick in use", function(data) {
const lobby = network.channels[0];
const msg = new Msg({
type: Msg.Type.ERROR,
text: data.nick + ": " + (data.reason || "Nickname is already in use."),
showInActive: true,
});
lobby.pushMessage(client, msg, true);
if (irc.connection.registered === false) {
const random = (data.nick || irc.user.nick) + Math.floor(Math.random() * 10);
irc.changeNick(random);
}
client.emit("nick", {
network: network.id,
nick: irc.user.nick,
});
});
irc.on("nick invalid", function(data) {
const lobby = network.channels[0];
const msg = new Msg({
type: Msg.Type.ERROR,
text: data.nick + ": " + (data.reason || "Nickname is invalid."),
showInActive: true,
});
lobby.pushMessage(client, msg, true);
if (irc.connection.registered === false) {
irc.changeNick("thelounge" + Math.floor(Math.random() * 100));
}
client.emit("nick", {
network: network.id,
nick: irc.user.nick,
});
});
};