2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-09-13 21:29:45 +00:00
|
|
|
var Msg = require("../../models/msg");
|
|
|
|
|
|
|
|
module.exports = function(irc, network) {
|
|
|
|
var client = this;
|
2016-03-20 18:03:18 +00:00
|
|
|
|
2016-05-06 17:51:38 +00:00
|
|
|
irc.on("irc error", function(data) {
|
2016-03-16 20:54:11 +00:00
|
|
|
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,
|
2016-03-16 20:54:11 +00:00
|
|
|
text: text,
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
2016-09-25 06:41:10 +00:00
|
|
|
lobby.pushMessage(client, msg, true);
|
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
|
|
|
});
|
2016-09-25 06:41:10 +00:00
|
|
|
lobby.pushMessage(client, msg, true);
|
2016-03-08 09:54:17 +00:00
|
|
|
|
2016-04-10 08:55:58 +00:00
|
|
|
if (irc.connection.registered === false) {
|
|
|
|
var random = (data.nick || irc.user.nick) + Math.floor(10 + (Math.random() * 89));
|
|
|
|
irc.changeNick(random);
|
|
|
|
}
|
2016-10-01 16:46:36 +00:00
|
|
|
|
|
|
|
client.emit("nick", {
|
|
|
|
network: network.id,
|
|
|
|
nick: irc.user.nick
|
|
|
|
});
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
2016-04-03 10:26:17 +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."),
|
2016-04-03 10:26:17 +00:00
|
|
|
});
|
2016-09-25 06:41:10 +00:00
|
|
|
lobby.pushMessage(client, msg, true);
|
2016-04-03 10:26:17 +00:00
|
|
|
|
2016-04-10 08:55:58 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-10-01 16:46:36 +00:00
|
|
|
|
|
|
|
client.emit("nick", {
|
|
|
|
network: network.id,
|
|
|
|
nick: irc.user.nick
|
|
|
|
});
|
2016-04-03 10:26:17 +00:00
|
|
|
});
|
2014-09-13 21:29:45 +00:00
|
|
|
};
|