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

71 lines
1.6 KiB
JavaScript
Raw Normal View History

"use strict";
const Msg = require("../../models/msg");
2014-09-13 21:29:45 +00:00
module.exports = function(irc, network) {
const client = this;
2016-05-06 17:51:38 +00:00
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({
2014-09-13 21:29:45 +00:00
type: Msg.Type.ERROR,
text: text,
2017-07-28 08:53:36 +00:00
showInActive: true,
2014-09-13 21:29:45 +00:00
});
lobby.pushMessage(client, msg, true);
2016-03-08 09:54:17 +00:00
});
irc.on("nick in use", function(data) {
const lobby = network.channels[0];
const msg = new Msg({
2016-03-08 09:54:17 +00:00
type: Msg.Type.ERROR,
2016-04-04 18:32:21 +00:00
text: data.nick + ": " + (data.reason || "Nickname is already in use."),
2017-07-28 08:53:36 +00:00
showInActive: true,
2016-03-08 09:54:17 +00:00
});
lobby.pushMessage(client, msg, true);
2016-03-08 09:54:17 +00:00
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,
});
2014-09-13 21:29:45 +00:00
});
irc.on("nick invalid", function(data) {
const lobby = network.channels[0];
const msg = new Msg({
type: Msg.Type.ERROR,
2016-04-04 18:32:21 +00:00
text: data.nick + ": " + (data.reason || "Nickname is invalid."),
2017-07-28 08:53:36 +00:00
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,
});
});
2014-09-13 21:29:45 +00:00
};