From: Darren Date: Wed, 23 Jan 2013 21:24:48 +0000 (+0000) Subject: More IrcChannel events implimented X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ffbbc70fc15ec499675bccb2992fdaa7e0cc63a4;p=KiwiIRC.git More IrcChannel events implimented --- diff --git a/server/irc/channel.js b/server/irc/channel.js index 5fa18b6..9beb8d0 100644 --- a/server/irc/channel.js +++ b/server/irc/channel.js @@ -1,11 +1,15 @@ function IrcChannel(irc_connection, name) { + var that = this; + this.irc_connection = irc_connection; this.name = name; // Helper for binding listeners function bindEvent(event, fn) { - irc_connection.on('channel:' + name + ':' + event, fn); + irc_connection.on('channel:' + name + ':' + event, function () { + fn.apply(that, arguments); + }); } bindEvent('join', this.onJoin); @@ -16,22 +20,24 @@ function IrcChannel(irc_connection, name) { bindEvent('privmsg', this.onMsg); bindEvent('notice', this.onNotice); bindEvent('ctcp', this.onCtcp); + + bindEvent('nicklist', this.onNicklist); + bindEvent('nicklistEnd', this.onNicklistEnd); } -// TODO: Move this into irc_connection -ircChannel.prototype.clientEvent = function (event_name, event) { +IrcChannel.prototype.clientEvent = function (event_name, event) { event.server = this.irc_connection.con_num; - this.client.sendIrcCommand(event_name, event); + this.irc_connection.state.sendIrcCommand(event_name, event); }; IrcChannel.prototype.onJoin = function (event) { this.clientEvent('join', { channel: this.name, - nick: command.nick, - ident: command.ident, - hostname: command.hostname, + nick: event.nick, + ident: event.ident, + hostname: event.hostname, }); // If we've just joined this channel then requesr=t get a nick list @@ -41,13 +47,91 @@ IrcChannel.prototype.onJoin = function (event) { }; -IrcChannel.prototype.removeUser = function (event) { - type = type || 'part'; +IrcChannel.prototype.onPart = function (event) { + this.clientEvent('part', { + nick: event.nick, + ident: event.ident, + hostname: event.hostname, + channel: this.name, + message: event.message + }); +}; - this.emit('') -} + +IrcChannel.prototype.onKick = function (event) { + this.client.sendIrcCommand('kick', { + kicked: event.params[1], // Nick of the kicked + nick: event.nick, // Nick of the kicker + ident: event.ident, + hostname: event.hostname, + channel: this.name, + message: event.message + }); +}; +IrcChannel.prototype.onQuit = function (event) { + this.clientEvent('quit', { + nick: event.nick, + ident: event.ident, + hostname: event.hostname, + message: event.message + }); +}; + + +IrcChannel.prototype.onMsg = function (event) { + this.clientEvent('msg', { + server: this.con_num, + nick: event.nick, + ident: event.ident, + hostname: event.hostname, + channel: this.name, + msg: event.message + }); +}; + + +IrcChannel.prototype.onNotice = function (event) { + this.clientEvent('msg', { + server: this.con_num, + nick: event.nick, + ident: event.ident, + hostname: event.hostname, + channel: this.name, + msg: event.trailing + }); +}; + + +IrcChannel.prototype.onCtcp = function (event) { + this.clientEvent('ctcp_request', { + nick: event.nick, + ident: event.ident, + hostname: event.hostname, + target: event.target, + type: event.type, + msg: event.msg + }); +}; + + +// TODO: Split event.users into batches of 50 +IrcChannel.prototype.onNicklist = function (event) { + this.clientEvent('userlist', { + users: event.users, + channel: this.name + }); +}; + + +IrcChannel.prototype.onNicklistEnd = function (event) { + this.clientEvent('userlist_end', { + users: event.users, + channel: this.name + }); +}; + /* server:event server:* @@ -56,7 +140,6 @@ channel:*:event user:event user:* - Server disconnected: server:disconnect server:* @@ -72,5 +155,4 @@ Channel message: Private message: user:privmsg user:* - */ \ No newline at end of file diff --git a/server/irc/commands.js b/server/irc/commands.js index 77c3923..070dc0c 100644 --- a/server/irc/commands.js +++ b/server/irc/commands.js @@ -237,11 +237,7 @@ var listeners = { channel = command.params[0]; } - this.client.sendIrcCommand('join', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: channel}); - - if (command.nick === this.nick) { - this.irc_connection.write('NAMES ' + channel); - } + this.irc_connection.emit('channel:' + channel + ':join'); }, 'PART': function (command) { this.client.sendIrcCommand('part', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: command.params[0], message: command.trailing}); @@ -345,8 +341,7 @@ var listeners = { } else if (command.trailing.substr(1, 10) === 'CLIENTINFO') { this.irc_connection.write('NOTICE ' + command.nick + ' :' + String.fromCharCode(1) + 'CLIENTINFO SOURCE VERSION TIME' + String.fromCharCode(1)); } else { - this.client.sendIrcCommand('ctcp_request', { - server: this.con_num, + this.irc_connection.emit('channel:' + command.params[0] + ':ctcp', { nick: command.nick, ident: command.ident, hostname: command.hostname, @@ -356,8 +351,13 @@ var listeners = { }); } } else { - //{nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing} - this.client.sendIrcCommand('msg', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: command.params[0], msg: command.trailing}); + this.irc_connection.emit('channel:' + command.params[0] + ':privmsg', { + nick: command.nick, + ident: command.ident, + hostname: command.hostname, + channel: command.params[0], + msg: command.trailing + }); } }, 'CAP': function (command) { diff --git a/server/irc/state.js b/server/irc/state.js index e18de3a..df1ba05 100755 --- a/server/irc/state.js +++ b/server/irc/state.js @@ -1,4 +1,5 @@ -var IrcConnection = require('./connection.js'); +var util = require('util'), + IrcConnection = require('./connection.js'); var State = function (client, save_state) { events.EventEmitter.call(this);