Improve nick highlights
This commit is contained in:
parent
bbf7b8086f
commit
aa8c3f6419
@ -144,6 +144,7 @@ Client.prototype.connect = function(args) {
|
|||||||
ip: args.ip,
|
ip: args.ip,
|
||||||
hostname: args.hostname,
|
hostname: args.hostname,
|
||||||
});
|
});
|
||||||
|
network.setNick(nick);
|
||||||
|
|
||||||
client.networks.push(network);
|
client.networks.push(network);
|
||||||
client.emit("network", {
|
client.emit("network", {
|
||||||
|
@ -33,13 +33,34 @@ function Network(attr) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Network.prototype.setNick = function(nick) {
|
||||||
|
this.nick = nick;
|
||||||
|
this.highlightRegex = new RegExp(
|
||||||
|
// Do not match characters and numbers (unless IRC color)
|
||||||
|
"(?:^|[^a-z0-9]|\x03[0-9]{1,2})" +
|
||||||
|
|
||||||
|
// Escape nickname, as it may contain regex stuff
|
||||||
|
nick.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") +
|
||||||
|
|
||||||
|
// Do not match characters and numbers
|
||||||
|
"(?:[^a-z0-9]|$)",
|
||||||
|
|
||||||
|
// Case insensitive search
|
||||||
|
"i"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
Network.prototype.toJSON = function() {
|
Network.prototype.toJSON = function() {
|
||||||
var json = _.extend(this, {nick: (this.irc && this.irc.user.nick) || ""});
|
return _.omit(this, [
|
||||||
return _.omit(json, "irc", "password");
|
"irc",
|
||||||
|
"password",
|
||||||
|
"highlightRegex"
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype.export = function() {
|
Network.prototype.export = function() {
|
||||||
var network = _.pick(this, [
|
var network = _.pick(this, [
|
||||||
|
"nick",
|
||||||
"name",
|
"name",
|
||||||
"host",
|
"host",
|
||||||
"port",
|
"port",
|
||||||
@ -51,11 +72,12 @@ Network.prototype.export = function() {
|
|||||||
"ip",
|
"ip",
|
||||||
"hostname"
|
"hostname"
|
||||||
]);
|
]);
|
||||||
network.nick = (this.irc && this.irc.user.nick) || "";
|
|
||||||
network.join = _.map(
|
network.join = _.map(
|
||||||
_.filter(this.channels, {type: "channel"}),
|
_.filter(this.channels, {type: "channel"}),
|
||||||
"name"
|
"name"
|
||||||
).join(",");
|
).join(",");
|
||||||
|
|
||||||
return network;
|
return network;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,9 +64,7 @@ module.exports = function(irc, network) {
|
|||||||
// Self messages are never highlighted
|
// Self messages are never highlighted
|
||||||
// Non-self messages are highlighted as soon as the nick is detected
|
// Non-self messages are highlighted as soon as the nick is detected
|
||||||
if (!highlight && !self) {
|
if (!highlight && !self) {
|
||||||
highlight = data.message.split(" ").some(function(w) {
|
highlight = network.highlightRegex.test(data.message);
|
||||||
return (w.replace(/^@/, "").toLowerCase().indexOf(irc.user.nick.toLowerCase()) === 0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self && chan.id !== client.activeChannel) {
|
if (!self && chan.id !== client.activeChannel) {
|
||||||
|
@ -6,6 +6,8 @@ module.exports = function(irc, network) {
|
|||||||
irc.on("nick", function(data) {
|
irc.on("nick", function(data) {
|
||||||
var self = false;
|
var self = false;
|
||||||
if (data.nick === irc.user.nick) {
|
if (data.nick === irc.user.nick) {
|
||||||
|
network.setNick(data.new_nick);
|
||||||
|
|
||||||
var lobby = network.channels[0];
|
var lobby = network.channels[0];
|
||||||
var msg = new Msg({
|
var msg = new Msg({
|
||||||
text: "You're now known as " + data.new_nick,
|
text: "You're now known as " + data.new_nick,
|
||||||
|
@ -3,7 +3,8 @@ var Msg = require("../../models/msg");
|
|||||||
module.exports = function(irc, network) {
|
module.exports = function(irc, network) {
|
||||||
var client = this;
|
var client = this;
|
||||||
irc.on("registered", function(data) {
|
irc.on("registered", function(data) {
|
||||||
network.nick = data.nick;
|
network.setNick(data.nick);
|
||||||
|
|
||||||
var lobby = network.channels[0];
|
var lobby = network.channels[0];
|
||||||
var msg = new Msg({
|
var msg = new Msg({
|
||||||
text: "You're now known as " + data.nick
|
text: "You're now known as " + data.nick
|
||||||
|
Loading…
Reference in New Issue
Block a user