More IrcChannel events implimented
authorDarren <darren@darrenwhitlen.com>
Wed, 23 Jan 2013 21:24:48 +0000 (21:24 +0000)
committerDarren <darren@darrenwhitlen.com>
Thu, 31 Jan 2013 14:58:42 +0000 (14:58 +0000)
server/irc/channel.js
server/irc/commands.js
server/irc/state.js

index 5fa18b6d1ef363829eee5a1560915f52d081bfc0..9beb8d02182fe7bc73e8181514cf4eea47429c7f 100644 (file)
@@ -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
index 77c3923dc1a204cc8f8b08976f4f4349170348a0..070dc0c5fd03955290ece709809cedcc80ddf454 100644 (file)
@@ -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) {
index e18de3a9f68f5370a7012b2681b58a0c9760375f..df1ba056e754fbb2db8982296d61237a1fac1c12 100755 (executable)
@@ -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);