Differentiating between server and non server notices
[KiwiIRC.git] / server / irc / eventbinder.js
index e3d6d1b207b7e8ade18cf791c8dc0fc410d3e00f..e4feb769e40bf926e6358848ef8c50f153ed0383 100644 (file)
@@ -3,7 +3,7 @@ var _ = require('lodash');
 
 module.exports.bindIrcEvents = function (events_scope, event_map, context, irc_connection) {
     var namespace_prefix = events_scope ?
-        events_scope + ':' :
+        events_scope + ' ' :
         '';
 
     // Make sure we have a holder for the bound events
@@ -15,7 +15,7 @@ module.exports.bindIrcEvents = function (events_scope, event_map, context, irc_c
 
         // Bind the event to `context`, storing it with the event listing
         if (!event_map._bound_events[event_name]) {
-            event_map._bound_events[event_name] = fn.bind(context);
+            event_map._bound_events[event_name] = _.bind(fn, context);
         }
 
         // Add the listener to the IRC connection object
@@ -26,7 +26,7 @@ module.exports.bindIrcEvents = function (events_scope, event_map, context, irc_c
 
 module.exports.unbindIrcEvents = function (events_scope, event_map, irc_connection) {
     var namespace_prefix = events_scope ?
-        events_scope + ':' :
+        events_scope + ' ' :
         '';
 
     // No bound events? Then we have nothing to do
@@ -40,7 +40,9 @@ module.exports.unbindIrcEvents = function (events_scope, event_map, irc_connecti
             irc_connection.removeListener(namespace_prefix + event_name, event_map._bound_events[event_name]);
 
             // Remove the bound function as no longer needed
-            event_map._bound_events[event_name] = undefined;
+            delete event_map._bound_events[event_name];
         }
     });
+
+    delete event_map._bound_events;
 };
\ No newline at end of file