--- /dev/null
+var Binder = function () {};
+
+module.exports = Binder;
+
+Binder.prototype.bindEvents = function () {
+ var that = this;
+ this.irc_events.forEach(function (fn, event_name, irc_events) {
+ // Bind the event to `that` context, storing it with the event listing
+ if (!irc_events[event_name].bound_fn) {
+ irc_events[event_name].bound_fn = fn.bind(that);
+ }
+
+ this.irc_connection.on(this.scope + ':' + event_name, irc_events[event_name].bound_fn);
+ });
+};
+
+
+Binder.prototype.unbindEvents = function () {
+ this.irc_events.forEach(function(fn, event_name, irc_events) {
+ if (irc_events[event_name].bound_fn) {
+ this.irc_connection.removeListener(this.scope + ':' + event_name, irc_events[event_name].bound_fn);
+ }
+ });
+};
\ No newline at end of file
+var util = require('util'),
+ Binder = require('./binder.js');
function IrcChannel(irc_connection, name) {
this.irc_connection = irc_connection;
this.name = name;
+ this.scope = 'channel:' + name;
+ Binder.call(this);
+
this.members = [];
this.ban_list_buffer = [];
}
+util.inherits(IrcChannel, Binder);
+
+module.exports = IrcChannel;
+
IrcChannel.prototype.dispose = function (){
this.unbindEvents();
};
-IrcChannel.prototype.bindEvents = function() {
- var that = this;
-
- // If we havent generated an event listing yet, do so now
- if (!this.irc_events) {
- this.irc_events = {
- join: onJoin,
- part: onPart,
- kick: onKick,
- quit: onQuit,
- privmsg: onMsg,
- notice: onNotice,
- ctcp_request: onCtcpRequest,
- ctcp_response: onCtcpResponse,
- topic: onTopic,
- nicklist: onNicklist,
- nicklistEnd: onNicklistEnd,
- banlist: onBanList,
- banlist_end: onBanListEnd,
- topicsetby: onTopicSetby
- };
- }
-
- this.irc_events.forEach(function(fn, event_name, irc_events){
- // Bind the event to `that` context, storing it with the event listing
- if (!irc_events[event_name].bound_fn) {
- irc_events[event_name].bound_fn = fn.bind(that);
- }
-
- this.irc_connection.on(event_name, irc_events[event_name].bound_fn);
- });
+IrcChannel.prototype.irc_events = {
+ join: onJoin,
+ part: onPart,
+ kick: onKick,
+ quit: onQuit,
+ privmsg: onMsg,
+ notice: onNotice,
+ ctcp_request: onCtcpRequest,
+ ctcp_response: onCtcpResponse,
+ topic: onTopic,
+ nicklist: onNicklist,
+ nicklistEnd: onNicklistEnd,
+ banlist: onBanList,
+ banlist_end: onBanListEnd,
+ topicsetby: onTopicSetby
};
-IrcChannel.prototype.unbindEvents = function() {
- this.irc_events.forEach(function(fn, event_name, irc_events){
- if (irc_events[event_name].bound_fn) {
- this.irc_connection.removeListener(event_name, irc_events[event_name].bound_fn);
- }
- });
-};
-
-
-
-
-
function onJoin(event) {
this.irc_connection.sendIrcCommand('join', {
channel: this.name,
+var util = require('util'),
+ Binder = require('./binder.js');
+
var IrcServer = function (irc_connection, host, port) {
this.irc_connection = irc_connection;
this.host = host;
this.port = port;
+ this.scope = 'server:' + host;
+
+ Binder.call(this);
+
this.list_buffer = [];
this.motd_buffer = '';
};
+util.inherits(IrcServer, Binder);
+
module.exports = IrcServer;
-IrcServer.prototype.bindEvents = function () {
- var that = this;
-
- // If we havent generated an event listing yet, do so now
- if (!this.irc_events) {
- this.irc_events = {
- connect: onConnect,
- options: onOptions,
- list_start: onListStart,
- list_channel: onListChannel,
- list_end: onListEnd,
- motd_start: onMotdStart,
- motd: onMotd,
- motd_end: onMotdEnd,
- error: onError,
- channel_redirect: onChannelRedirect,
- no_such_nick: onNoSuchNick,
- cannot_send_to_channel: onChannotSendToChan,
- too_many_channels: onTooManyChannels,
- user_not_in_channel: onUserNotInChannel,
- not_on_channel: onNotOnChannel,
- channel_is_full: onChannelisFull,
- invite_only_channel: onInviteOnlyChannel,
- banned_from_channel: onBannedFromChannel,
- bad_channel_key: onBadChannelKey,
- chanop_privs_needed: onChanopPrivsNeeded,
- nickname_in_use: onNicknameInUse
- };
- }
-
- this.irc_events.forEach(function (fn, event_name, irc_events) {
- // Bind the event to `that` context, storing it with the event listing
- if (!irc_events[event_name].bound_fn) {
- irc_events[event_name].bound_fn = fn.bind(that);
- }
-
- this.irc_connection.on('server:' + this.host + ':' + event_name, irc_events[event_name].bound_fn);
- });
-};
-
-
-IrcServer.prototype.unbindEvents = function () {
- this.irc_events.forEach(function(fn, event_name, irc_events) {
- if (irc_events[event_name].bound_fn) {
- this.irc_connection.removeListener('server:' + this.host + ':' + event_name, irc_events[event_name].bound_fn);
- }
- });
+IrcServer.prototype.irc_events = {
+ connect: onConnect,
+ options: onOptions,
+ list_start: onListStart,
+ list_channel: onListChannel,
+ list_end: onListEnd,
+ motd_start: onMotdStart,
+ motd: onMotd,
+ motd_end: onMotdEnd,
+ error: onError,
+ channel_redirect: onChannelRedirect,
+ no_such_nick: onNoSuchNick,
+ cannot_send_to_channel: onChannotSendToChan,
+ too_many_channels: onTooManyChannels,
+ user_not_in_channel: onUserNotInChannel,
+ not_on_channel: onNotOnChannel,
+ channel_is_full: onChannelisFull,
+ invite_only_channel: onInviteOnlyChannel,
+ banned_from_channel: onBannedFromChannel,
+ bad_channel_key: onBadChannelKey,
+ chanop_privs_needed: onChanopPrivsNeeded,
+ nickname_in_use: onNicknameInUse
};
function onConnect(event) {
+var util = require('util'),\r
+ Binder = require('./binder.js');\r
+\r
var IrcUser = function (irc_connection, nick) {\r
this.irc_connection = irc_connection;\r
this.nick = nick;\r
+ \r
+ this.scope = 'user:' + nick;\r
+ Binder.call(this);\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
+util.inherits(IrcUser, Binder);\r
\r
+module.exports = IrcUser;\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.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
function onNick(event) {\r