From b1fa81017da88cbf6069e3fb37f7166772f0737a Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 23 Jan 2013 17:45:51 +0000 Subject: [PATCH] Channel object start --- server/client.js | 1 + server/irc/channel.js | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 server/irc/channel.js diff --git a/server/client.js b/server/client.js index 36edf0c..428878c 100755 --- a/server/client.js +++ b/server/client.js @@ -135,6 +135,7 @@ function kiwiCommand(command, callback) { var con_num = this.next_connection++; this.irc_connections[con_num] = con; + con.con_num = con_num; var irc_commands = new IrcCommands(con, con_num, this); irc_commands.bindEvents(); diff --git a/server/irc/channel.js b/server/irc/channel.js new file mode 100644 index 0000000..5fa18b6 --- /dev/null +++ b/server/irc/channel.js @@ -0,0 +1,76 @@ + +function IrcChannel(irc_connection, name) { + this.irc_connection = irc_connection; + this.name = name; + + // Helper for binding listeners + function bindEvent(event, fn) { + irc_connection.on('channel:' + name + ':' + event, fn); + } + + bindEvent('join', this.onJoin); + bindEvent('part', this.onPart); + bindEvent('kick', this.onKick); + bindEvent('quit', this.onQuit); + + bindEvent('privmsg', this.onMsg); + bindEvent('notice', this.onNotice); + bindEvent('ctcp', this.onCtcp); +} + + +// TODO: Move this into irc_connection +ircChannel.prototype.clientEvent = function (event_name, event) { + event.server = this.irc_connection.con_num; + this.client.sendIrcCommand(event_name, event); +}; + + +IrcChannel.prototype.onJoin = function (event) { + this.clientEvent('join', { + channel: this.name, + nick: command.nick, + ident: command.ident, + hostname: command.hostname, + }); + + // If we've just joined this channel then requesr=t get a nick list + if (event.nick === this.irc_connection.nick) { + this.irc_connection.write('NAMES ' + channel); + } +}; + + +IrcChannel.prototype.removeUser = function (event) { + type = type || 'part'; + + this.emit('') +} + + +/* +server:event +server:* +channel:#channel:event +channel:*:event +user:event +user:* + + +Server disconnected: + server:disconnect + server:* + +Joining channel #kiwiirc: + channel:#kiwiirc:join + channel:*:join + +Channel message: + channel:#kiwiirc:privmsg + channel:*:privmsg + +Private message: + user:privmsg + user:* + +*/ \ No newline at end of file -- 2.25.1