2016-10-09 15:14:02 -04:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-10 15:44:14 -05:00
|
|
|
const Msg = require("../../models/msg");
|
2018-04-03 10:49:22 -04:00
|
|
|
const Helper = require("../../helper");
|
2014-09-13 17:29:45 -04:00
|
|
|
|
|
|
|
module.exports = function(irc, network) {
|
2017-11-10 15:44:14 -05:00
|
|
|
const client = this;
|
2016-03-20 14:03:18 -04:00
|
|
|
|
2016-05-06 13:51:38 -04:00
|
|
|
irc.on("irc error", function(data) {
|
2018-01-03 11:46:48 -05:00
|
|
|
let text = "";
|
2017-11-10 15:44:14 -05:00
|
|
|
|
2018-01-03 11:46:48 -05:00
|
|
|
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;
|
2016-03-16 16:54:11 -04:00
|
|
|
}
|
2017-11-10 15:44:14 -05:00
|
|
|
|
|
|
|
const lobby = network.channels[0];
|
|
|
|
const msg = new Msg({
|
2014-09-13 17:29:45 -04:00
|
|
|
type: Msg.Type.ERROR,
|
2016-03-16 16:54:11 -04:00
|
|
|
text: text,
|
2017-07-28 04:53:36 -04:00
|
|
|
showInActive: true,
|
2014-09-13 17:29:45 -04:00
|
|
|
});
|
2016-09-25 02:41:10 -04:00
|
|
|
lobby.pushMessage(client, msg, true);
|
2016-03-08 04:54:17 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("nick in use", function(data) {
|
2017-11-10 15:44:14 -05:00
|
|
|
const lobby = network.channels[0];
|
|
|
|
const msg = new Msg({
|
2016-03-08 04:54:17 -05:00
|
|
|
type: Msg.Type.ERROR,
|
2016-04-04 14:32:21 -04:00
|
|
|
text: data.nick + ": " + (data.reason || "Nickname is already in use."),
|
2017-07-28 04:53:36 -04:00
|
|
|
showInActive: true,
|
2016-03-08 04:54:17 -05:00
|
|
|
});
|
2016-09-25 02:41:10 -04:00
|
|
|
lobby.pushMessage(client, msg, true);
|
2016-03-08 04:54:17 -05:00
|
|
|
|
2016-04-10 04:55:58 -04:00
|
|
|
if (irc.connection.registered === false) {
|
2018-03-26 03:00:46 -04:00
|
|
|
const random = (data.nick || irc.user.nick) + Math.floor(Math.random() * 10);
|
2016-04-10 04:55:58 -04:00
|
|
|
irc.changeNick(random);
|
|
|
|
}
|
2016-10-01 12:46:36 -04:00
|
|
|
|
|
|
|
client.emit("nick", {
|
|
|
|
network: network.id,
|
2017-11-15 01:35:15 -05:00
|
|
|
nick: irc.user.nick,
|
2016-10-01 12:46:36 -04:00
|
|
|
});
|
2014-09-13 17:29:45 -04:00
|
|
|
});
|
2016-04-03 06:26:17 -04:00
|
|
|
|
|
|
|
irc.on("nick invalid", function(data) {
|
2017-11-10 15:44:14 -05:00
|
|
|
const lobby = network.channels[0];
|
|
|
|
const msg = new Msg({
|
2016-04-03 06:26:17 -04:00
|
|
|
type: Msg.Type.ERROR,
|
2016-04-04 14:32:21 -04:00
|
|
|
text: data.nick + ": " + (data.reason || "Nickname is invalid."),
|
2017-07-28 04:53:36 -04:00
|
|
|
showInActive: true,
|
2016-04-03 06:26:17 -04:00
|
|
|
});
|
2016-09-25 02:41:10 -04:00
|
|
|
lobby.pushMessage(client, msg, true);
|
2016-04-03 06:26:17 -04:00
|
|
|
|
2016-04-10 04:55:58 -04:00
|
|
|
if (irc.connection.registered === false) {
|
2018-04-03 10:49:22 -04:00
|
|
|
irc.changeNick(Helper.getDefaultNick());
|
2016-04-10 04:55:58 -04:00
|
|
|
}
|
2016-10-01 12:46:36 -04:00
|
|
|
|
|
|
|
client.emit("nick", {
|
|
|
|
network: network.id,
|
2017-11-15 01:35:15 -05:00
|
|
|
nick: irc.user.nick,
|
2016-10-01 12:46:36 -04:00
|
|
|
});
|
2016-04-03 06:26:17 -04:00
|
|
|
});
|
2014-09-13 17:29:45 -04:00
|
|
|
};
|