Server module hooks for IRC events
authorDarren <darren@darrenwhitlen.com>
Tue, 14 Jan 2014 22:44:05 +0000 (22:44 +0000)
committerDarren <darren@darrenwhitlen.com>
Tue, 14 Jan 2014 22:44:05 +0000 (22:44 +0000)
server/client.js
server/irc/channel.js
server/irc/user.js
server_modules/example.js

index e26d40514f9cde2c39cf5f17e0789bdb30e6b7d9..b8e7faff1c0f91673a1e33685d02b954d1aee0d3 100755 (executable)
@@ -78,7 +78,8 @@ Client.prototype.dispose = function () {
 };
 
 function handleClientMessage(msg, callback) {
-    var server;
+    var that = this,
+        server;
 
     // Make sure we have a server number specified
     if ((msg.server === null) || (typeof msg.server !== 'number')) {
@@ -102,7 +103,13 @@ function handleClientMessage(msg, callback) {
     }
 
     // Run the client command
-    this.client_commands.run(msg.data.method, msg.data.args, server, callback);
+    global.modules.emit('client command', {
+        command: msg.data,
+        server: server
+    })
+    .done(function() {
+        that.client_commands.run(msg.data.method, msg.data.args, server, callback);
+    });
 }
 
 
index 7c3a56eef603eadb7fbe227f38fbb184bca9b1c7..926aedd2119065e793a13e81bc9053899f2fddf5 100644 (file)
@@ -43,73 +43,125 @@ IrcChannel.prototype.dispose = function (){
 
 
 function onJoin(event) {
-    this.irc_connection.clientEvent('join', {
-        channel: this.name,
-        nick: event.nick,
-        ident: event.ident,
-        hostname: event.hostname,
-        time: event.time
+    var that = this;
+
+    global.modules.emit('irc channel join', {
+        channel: this,
+        connection: this.irc_connection,
+        irc_event: event
+    })
+    .done(function() {
+        that.irc_connection.clientEvent('join', {
+            channel: that.name,
+            nick: event.nick,
+            ident: event.ident,
+            hostname: event.hostname,
+            time: event.time
+        });
     });
 }
 
 
 function onPart(event) {
-    this.irc_connection.clientEvent('part', {
-        nick: event.nick,
-        ident: event.ident,
-        hostname: event.hostname,
-        channel: this.name,
-        message: event.message,
-        time: event.time
+    var that = this;
+
+    global.modules.emit('irc channel part', {
+        channel: this,
+        connection: this.irc_connection,
+        irc_event: event
+    })
+    .done(function() {
+        that.irc_connection.clientEvent('part', {
+            nick: event.nick,
+            ident: event.ident,
+            hostname: event.hostname,
+            channel: that.name,
+            message: event.message,
+            time: event.time
+        });
     });
 }
 
 
 function onKick(event) {
-    this.irc_connection.clientEvent('kick', {
-        kicked: event.kicked,  // Nick of the kicked
-        nick: event.nick, // Nick of the kicker
-        ident: event.ident,
-        hostname: event.hostname,
-        channel: this.name,
-        message: event.message,
-        time: event.time
+    global.modules.emit('irc channel kick', {
+        channel: this,
+        connection: this.irc_connection,
+        irc_event: event
+    })
+    .done(function() {
+        this.irc_connection.clientEvent('kick', {
+            kicked: event.kicked,  // Nick of the kicked
+            nick: event.nick, // Nick of the kicker
+            ident: event.ident,
+            hostname: event.hostname,
+            channel: this.name,
+            message: event.message,
+            time: event.time
+        });
     });
 }
 
 
 function onQuit(event) {
-    this.irc_connection.clientEvent('quit', {
-        nick: event.nick,
-        ident: event.ident,
-        hostname: event.hostname,
-        message: event.message,
-        time: event.time
+    var that = this;
+
+    global.modules.emit('irc channel quit', {
+        channel: this,
+        connection: this.irc_connection,
+        irc_event: event
+    })
+    .done(function() {
+        that.irc_connection.clientEvent('quit', {
+            nick: event.nick,
+            ident: event.ident,
+            hostname: event.hostname,
+            message: event.message,
+            time: event.time
+        });
     });
 }
 
 
 function onMsg(event) {
-    this.irc_connection.clientEvent('msg', {
-        nick: event.nick,
-        ident: event.ident,
-        hostname: event.hostname,
-        channel: this.name,
-        msg: event.msg,
-        time: event.time
+    var that = this;
+
+    global.modules.emit('irc message', {
+        channel: this,
+        connection: this.irc_connection,
+        irc_event: event
+    })
+    .done(function() {
+        that.irc_connection.clientEvent('msg', {
+            nick: event.nick,
+            ident: event.ident,
+            hostname: event.hostname,
+            channel: that.name,
+            msg: event.msg,
+            time: event.time
+        });
     });
 }
 
 
 function onNotice(event) {
-    this.irc_connection.clientEvent('notice', {
-        from_server: event.from_server,
-        nick: event.nick,
-        ident: event.ident,
-        hostname: event.hostname,
-        target: event.target,
-        msg: event.msg,
-        time: event.time
+    var that = this;
+
+    global.modules.emit('irc channel notice', {
+        channel: this,
+        connection: this.irc_connection,
+        irc_event: event
+    })
+    .done(function() {
+        that.irc_connection.clientEvent('notice', {
+            from_server: event.from_server,
+            nick: event.nick,
+            ident: event.ident,
+            hostname: event.hostname,
+            target: event.target,
+            msg: event.msg,
+            time: event.time
+        });
     });
 }
 
@@ -173,11 +225,20 @@ function updateUsersList(users) {
 
 
 function onTopic(event) {
-    this.irc_connection.clientEvent('topic', {
-        nick: event.nick,
-        channel: this.name,
-        topic: event.topic,
-        time: event.time
+    var that = this;
+
+    global.modules.emit('irc channel topic', {
+        channel: this,
+        connection: this.irc_connection,
+        irc_event: event
+    })
+    .done(function() {
+        that.irc_connection.clientEvent('topic', {
+            nick: event.nick,
+            channel: that.name,
+            topic: event.topic,
+            time: event.time
+        });
     });
 }
 
@@ -203,13 +264,6 @@ function onBanListEnd(event) {
     this.ban_list_buffer = [];
 }
 
-function onTopic(event) {
-    this.irc_connection.clientEvent('topic', {
-        channel: event.channel,
-        topic: event.topic
-    });
-}
-
 function onTopicSetBy(event) {
     this.irc_connection.clientEvent('topicsetby', {
         nick: event.nick,
@@ -219,10 +273,19 @@ function onTopicSetBy(event) {
 }
 
 function onMode(event) {
-    this.irc_connection.clientEvent('mode', {
-        target: event.target,
-        nick: event.nick,
-        modes: event.modes,
-        time: event.time
+    var that = this;
+
+    global.modules.emit('irc channel mode', {
+        channel: this,
+        connection: this.irc_connection,
+        irc_event: event
+    })
+    .done(function() {
+        that.irc_connection.clientEvent('mode', {
+            target: event.target,
+            nick: event.nick,
+            modes: event.modes,
+            time: event.time
+        });
     });
 }
index ba1c51600ef1822ad5fdeb7d91d30765d23f7974..213775f3bd877edb3c5601490744948657733e1b 100755 (executable)
@@ -224,13 +224,21 @@ function onCtcpResponse(event) {
 }\r
 \r
 function onPrivmsg(event) {\r
-    this.irc_connection.clientEvent('msg', {\r
-        nick: event.nick,\r
-        ident: event.ident,\r
-        hostname: event.hostname,\r
-        channel: event.channel,\r
-        msg: event.msg,\r
-        time: event.time\r
+    var that = this;\r
+\r
+    global.modules.emit('irc message', {\r
+        connection: this.irc_connection,\r
+        irc_event: event\r
+    })\r
+    .done(function() {\r
+        that.irc_connection.clientEvent('msg', {\r
+            nick: event.nick,\r
+            ident: event.ident,\r
+            hostname: event.hostname,\r
+            channel: event.channel,\r
+            msg: event.msg,\r
+            time: event.time\r
+        });\r
     });\r
 }\r
 \r
index 30b44952b5adda37666505bbfd22dbd189be8be7..7bce5e77a717b02bab22a05ad269968b2025e1a6 100644 (file)
@@ -3,12 +3,29 @@ var kiwiModules = require('../server/modules');
 var module = new kiwiModules.Module('Example Module');
 
 
-module.on('client connected', function(event, data) {
-    console.log('Client connection:', data);
+// A web client is connected
+module.on('client created', function(event, data) {
+    console.log('[client connection]', data);
 });
 
 
-module.on('client commands msg', function(event, data) {
-    console.log('Client msg:', data.args.target, ': ', data.args.msg);
-    data.args.msg += ' - modified!';
-});
\ No newline at end of file
+// The Client recieves a IRC PRIVMSG command
+module.on('irc message', function(event, data) {
+       console.log('[MESSAGE]', data.irc_event);
+});
+
+
+// The client recieves an IRC JOIN command
+module.on('irc channel join', function(event, data) {
+       console.log('[JOIN]', data.irc_event);
+});
+
+
+// A command has been sent from the client
+module.on('client command', function(event, data) {
+       var client_method = data.command.method;
+       var client_args = data.command.args;
+
+       console.log('[CLIENT COMMAND]', client_method);
+       console.log('    ', client_args);
+});