From: Darren Date: Tue, 14 Jan 2014 22:44:05 +0000 (+0000) Subject: Server module hooks for IRC events X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6c7b20067cfe035817d6eec068acfb6a331d2691;p=KiwiIRC.git Server module hooks for IRC events --- diff --git a/server/client.js b/server/client.js index e26d405..b8e7faf 100755 --- a/server/client.js +++ b/server/client.js @@ -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); + }); } diff --git a/server/irc/channel.js b/server/irc/channel.js index 7c3a56e..926aedd 100644 --- a/server/irc/channel.js +++ b/server/irc/channel.js @@ -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 + }); }); } diff --git a/server/irc/user.js b/server/irc/user.js index ba1c516..213775f 100755 --- a/server/irc/user.js +++ b/server/irc/user.js @@ -224,13 +224,21 @@ function onCtcpResponse(event) { } function onPrivmsg(event) { - this.irc_connection.clientEvent('msg', { - nick: event.nick, - ident: event.ident, - hostname: event.hostname, - channel: event.channel, - msg: event.msg, - time: event.time + var that = this; + + global.modules.emit('irc message', { + connection: this.irc_connection, + irc_event: event + }) + .done(function() { + that.irc_connection.clientEvent('msg', { + nick: event.nick, + ident: event.ident, + hostname: event.hostname, + channel: event.channel, + msg: event.msg, + time: event.time + }); }); } diff --git a/server_modules/example.js b/server_modules/example.js index 30b4495..7bce5e7 100644 --- a/server_modules/example.js +++ b/server_modules/example.js @@ -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); +});