49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
"use strict";
|
|
|
|
var _ = require("lodash");
|
|
var Msg = require("../../models/msg");
|
|
|
|
module.exports = function(irc, network) {
|
|
var client = this;
|
|
irc.on("nick", function(data) {
|
|
let msg;
|
|
var self = false;
|
|
if (data.nick === irc.user.nick) {
|
|
network.setNick(data.new_nick);
|
|
|
|
var lobby = network.channels[0];
|
|
msg = new Msg({
|
|
text: "You're now known as " + data.new_nick,
|
|
});
|
|
lobby.pushMessage(client, msg);
|
|
self = true;
|
|
client.save();
|
|
client.emit("nick", {
|
|
network: network.id,
|
|
nick: data.new_nick
|
|
});
|
|
}
|
|
|
|
network.channels.forEach(function(chan) {
|
|
var user = _.find(chan.users, {name: data.nick});
|
|
if (typeof user === "undefined") {
|
|
return;
|
|
}
|
|
user.name = data.new_nick;
|
|
chan.sortUsers(irc);
|
|
client.emit("users", {
|
|
chan: chan.id
|
|
});
|
|
msg = new Msg({
|
|
time: data.time,
|
|
type: Msg.Type.NICK,
|
|
mode: chan.getMode(data.new_nick),
|
|
nick: data.nick,
|
|
new_nick: data.new_nick,
|
|
self: self
|
|
});
|
|
chan.pushMessage(client, msg);
|
|
});
|
|
});
|
|
};
|