Removing junk from .po files
[KiwiIRC.git] / server / irc / user.js
index c4fa2b78f46ef99536503515d5f0ba00253d0b00..387b7f1534901bdb1e73f9e6be7e793a2a29499d 100755 (executable)
@@ -1,52 +1,45 @@
+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
@@ -54,14 +47,19 @@ function onNick(event) {
         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
@@ -70,7 +68,7 @@ function onQuit(event) {
         hostname: event.hostname,\r
         message: event.trailing\r
     });\r
-};\r
+}\r
 \r
 function onWhoisUser(event) {\r
     this.irc_connection.clientEvent('whois', {\r
@@ -80,15 +78,24 @@ function onWhoisUser(event) {
         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
@@ -96,7 +103,7 @@ function onWhoisOperator(event) {
         msg: event.msg,\r
         end: false\r
     });\r
-};\r
+}\r
 \r
 function onWhoisChannels(event) {\r
     this.irc_connection.clientEvent('whois', {\r
@@ -104,7 +111,7 @@ function onWhoisChannels(event) {
         chans: event.chans,\r
         end: false\r
     });\r
-};\r
+}\r
 \r
 function onWhoisModes(event) {\r
     this.irc_connection.clientEvent('whois', {\r
@@ -112,16 +119,16 @@ function onWhoisModes(event) {
         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
@@ -129,7 +136,7 @@ function onWhoisRegNick(event) {
         msg: event.msg,\r
         end: false\r
     });\r
-};\r
+}\r
 \r
 function onWhoisEnd(event) {\r
     this.irc_connection.clientEvent('whois', {\r
@@ -137,17 +144,42 @@ function onWhoisEnd(event) {
         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
@@ -157,17 +189,17 @@ function onCtcpResponse(event) {
         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
@@ -178,4 +210,12 @@ function onCtcpRequest(event) {
         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