+var util = require('util'),\r
+ EventBinder = require('./eventbinder.js');\r
+\r
var IrcUser = function (irc_connection, nick) {\r
this.irc_connection = irc_connection;\r
this.nick = nick;\r
+\r
+ this.irc_events = {\r
+ nick: onNick,\r
+ away: onAway,\r
+ quit: onQuit,\r
+ whoisuser: onWhoisUser,\r
+ whoisaway: onWhoisAway,\r
+ whoisoperator: onWhoisOperator,\r
+ whoischannels: onWhoisChannels,\r
+ whoismodes: onWhoisModes,\r
+ whoisidle: onWhoisIdle,\r
+ whoisregnick: onWhoisRegNick,\r
+ whoisserver: onWhoisServer,\r
+ endofwhois: onWhoisEnd,\r
+ whowas: onWhoWas,\r
+ endofwhowas: onWhoWasEnd,\r
+ wasnosuchnick: onWasNoSuchNick,\r
+ notice: onNotice,\r
+ ctcp_response: onCtcpResponse,\r
+ privmsg: onPrivmsg,\r
+ ctcp_request: onCtcpRequest,\r
+ mode: onMode\r
+ };\r
+ EventBinder.bindIrcEvents('user ' + this.nick, this.irc_events, this, irc_connection);\r
};\r
\r
-module.exports = IrcUser;\r
\r
-IrcUser.prototype.bindEvents = function () {\r
- var that = this;\r
-\r
- // If we havent generated an event listing yet, do so now\r
- if (!this.irc_events) {\r
- this.irc_events = {\r
- nick: onNick,\r
- away: onAway,\r
- quit: onKick,\r
- whoisuser: onWhoisUser,\r
- whoisoperator: onWhoisOperator,\r
- whoischannels: onWhoisChannels,\r
- whoismodes: onWhoisModes,\r
- whoisidle: onWhoisIdle,\r
- whoisregnick: onRegNick,\r
- endofwhois: onEhoisEnd,\r
- notice: onNotice,\r
- ctcp_response: onCtcpResponse,\r
- privmsg: onPrivmsg,\r
- ctcp_request: onCtcpRequest\r
- };\r
- }\r
-\r
- this.irc_events.forEach(function (fn, event_name, irc_events) {\r
- // Bind the event to `that` context, storing it with the event listing\r
- if (!irc_events[event_name].bound_fn) {\r
- irc_events[event_name].bound_fn = fn.bind(that);\r
- }\r
-\r
- this.irc_connection.on('user:' + this.nick + ':' + event_name, irc_events[event_name].bound_fn);\r
- });\r
-};\r
+module.exports = IrcUser;\r
\r
\r
-IrcUser.prototype.unbindEvents = function () {\r
- this.irc_events.forEach(function(fn, event_name, irc_events) {\r
- if (irc_events[event_name].bound_fn) {\r
- this.irc_connection.removeListener('user:' + this.nick + ':' + event_name, irc_events[event_name].bound_fn);\r
- }\r
- });\r
+IrcUser.prototype.dispose = function () {\r
+ EventBinder.unbindIrcEvents('user ' + this.nick, this.irc_events, this.irc_connection);\r
+ this.irc_connection = undefined;\r
};\r
\r
+\r
function onNick(event) {\r
this.irc_connection.clientEvent('nick', {\r
nick: event.nick,\r
hostname: event.hostname,\r
newnick: event.newnick\r
});\r
-};\r
+\r
+ // TODO: uncomment when using an IrcUser per nick\r
+ //EventBinder.unbindIrcEvents('user ' + this.nick, this.irc_events, irc_connection);\r
+ //this.nick = event.newnick;\r
+ //EventBinder.bindIrcEvents('user ' + this.nick, this.irc_events, this, irc_connection);\r
+}\r
\r
function onAway(event) {\r
this.irc_connection.clientEvent('away', {\r
nick: event.nick,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onQuit(event) {\r
this.irc_connection.clientEvent('quit', {\r
hostname: event.hostname,\r
message: event.trailing\r
});\r
-};\r
+}\r
\r
function onWhoisUser(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: false\r
});\r
-};\r
+}\r
+\r
+function onWhoisAway(event) {\r
+ this.irc_connection.clientEvent('whois', {\r
+ nick: event.nick,\r
+ away_reason: event.reason,\r
+ end: false\r
+ });\r
+}\r
\r
function onWhoisServer(event) {\r
this.irc_connection.clientEvent('whois', {\r
nick: event.nick,\r
irc_server: event.irc_server,\r
+ server_info: event.server_info,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisOperator(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisChannels(event) {\r
this.irc_connection.clientEvent('whois', {\r
chans: event.chans,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisModes(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: false\r
});\r
-};\r
+}\r
\r
-function onWhoisUser(event) {\r
+function onWhoisIdle(event) {\r
this.irc_connection.clientEvent('whois', {\r
nick: event.nick,\r
idle: event.idle,\r
logon: event.logon || undefined,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisRegNick(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisEnd(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: true\r
});\r
-};\r
+}\r
+\r
+function onWhoWas(event) {\r
+ this.irc_connection.clientEvent('whowas', {\r
+ nick: event.nick,\r
+ ident: event.user,\r
+ host: event.host,\r
+ real_name: event.real_name,\r
+ end: false\r
+ });\r
+}\r
+\r
+function onWasNoSuchNick(event) {\r
+ this.irc_connection.clientEvent('whowas', {\r
+ nick: event.nick,\r
+ end: false\r
+ });\r
+}\r
+\r
+function onWhoWasEnd(event) {\r
+ this.irc_connection.clientEvent('whowas', {\r
+ nick: event.nick,\r
+ end: true\r
+ });\r
+}\r
\r
function onNotice(event) {\r
this.irc_connection.clientEvent('notice', {\r
+ from_server: event.from_server,\r
nick: event.nick,\r
ident: event.ident,\r
hostname: event.hostname,\r
target: event.target,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onCtcpResponse(event) {\r
this.irc_connection.clientEvent('ctcp_response', {\r
channel: event.channel,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onPrivmsg(event) {\r
- this.irc_connection.clientEvent('privmsg', {\r
+ this.irc_connection.clientEvent('msg', {\r
nick: event.nick,\r
ident: event.ident,\r
hostname: event.hostname,\r
channel: event.channel,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onCtcpRequest(event) {\r
this.irc_connection.clientEvent('ctcp_request', {\r
type: event.type,\r
msg: event.msg\r
});\r
-};\r
+}\r
+\r
+function onMode(event) {\r
+ this.irc_connection.clientEvent('mode', {\r
+ target: event.target,\r
+ nick: event.nick,\r
+ modes: event.modes\r
+ });\r
+}\r