thelounge/src/plugins/irc-events/error.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

"use strict";
const Msg = require("../../models/msg");
2014-09-13 23:29:45 +02:00
module.exports = function(irc, network) {
const client = this;
2016-05-06 19:51:38 +02:00
irc.on("irc error", function(data) {
let text = data.error;
if (data.reason) {
text = data.reason + " (" + text + ")";
}
const lobby = network.channels[0];
const msg = new Msg({
2014-09-13 23:29:45 +02:00
type: Msg.Type.ERROR,
text: text,
2014-09-13 23:29:45 +02:00
});
lobby.pushMessage(client, msg, true);
2016-03-08 10:54:17 +01:00
});
irc.on("nick in use", function(data) {
const lobby = network.channels[0];
const msg = new Msg({
2016-03-08 10:54:17 +01:00
type: Msg.Type.ERROR,
2016-04-04 20:32:21 +02:00
text: data.nick + ": " + (data.reason || "Nickname is already in use."),
2016-03-08 10:54:17 +01:00
});
lobby.pushMessage(client, msg, true);
2016-03-08 10:54:17 +01:00
if (irc.connection.registered === false) {
const random = (data.nick || irc.user.nick) + Math.floor(10 + (Math.random() * 89));
irc.changeNick(random);
}
client.emit("nick", {
network: network.id,
nick: irc.user.nick,
});
2014-09-13 23:29:45 +02:00
});
irc.on("nick invalid", function(data) {
const lobby = network.channels[0];
const msg = new Msg({
type: Msg.Type.ERROR,
2016-04-04 20:32:21 +02:00
text: data.nick + ": " + (data.reason || "Nickname is invalid."),
});
lobby.pushMessage(client, msg, true);
if (irc.connection.registered === false) {
const random = "i" + Math.random().toString(36).substr(2, 10); // 'i' so it never begins with a number
irc.changeNick(random);
}
client.emit("nick", {
network: network.id,
nick: irc.user.nick,
});
});
2014-09-13 23:29:45 +02:00
};