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

57 lines
1.3 KiB
JavaScript
Raw Normal View History

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