Commit | Line | Data |
---|---|---|
635e02c3 D |
1 | var _ = require('lodash'); |
2 | ||
635e02c3 | 3 | |
ba21099b | 4 | module.exports.bindIrcEvents = function (events_scope, event_map, context, irc_connection) { |
635e02c3 D |
5 | _.each(event_map, function (fn, event_name) { |
6 | // Bind the event to `context`, storing it with the event listing | |
7 | if (!event_map[event_name].bound_fn) { | |
8 | event_map[event_name].bound_fn = fn.bind(context); | |
9 | } | |
10 | ||
11 | // Add the listener to the IRC connection object | |
12 | irc_connection.on(events_scope + ':' + event_name, event_map[event_name].bound_fn); | |
13 | }); | |
14 | }; | |
15 | ||
16 | ||
ba21099b | 17 | module.exports.unbindIrcEvents = function (events_scope, event_map, irc_connection) { |
635e02c3 D |
18 | _.each(event_map, function(fn, event_name) { |
19 | if (event_map[event_name].bound_fn) { | |
20 | // Remove the listener from the IRC connection object | |
21 | irc_connection.removeListener(events_scope + ':' + event_name, event_map[event_name].bound_fn); | |
22 | ||
23 | // Remove the bound function as no longer needed | |
24 | event_map[event_name].bound_fn = undefined; | |
25 | } | |
26 | }); | |
27 | }; |