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

59 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;
// TODO: remove later
2016-03-08 09:54:17 +00:00
irc.on("irc_error", function(data) {
console.log("Got an irc_error");
irc.emit("error", data);
});
irc.on("error", function(data) {
console.log("error", 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
});
client.emit("msg", {
chan: lobby.id,
msg: 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,
text: "Nickname " + data.nick + " is already in use: " + data.reason,
});
client.emit("msg", {
chan: lobby.id,
msg: msg
});
var random = irc.user.nick + Math.floor(10 + (Math.random() * 89));
2016-03-08 13:36:25 +00:00
irc.changeNick(random);
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,
text: "Nickname " + data.nick + " is invalid: " + data.reason,
});
client.emit("msg", {
chan: lobby.id,
msg: msg
});
var random = "i" + Math.random().toString(36).substr(2, 10); // 'i' so it never begins with a number
irc.changeNick(random);
});
2014-09-13 21:29:45 +00:00
};