From 1e2a823ef2b1098af9e6b83ca4401a173b9e1c87 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 25 May 2013 19:13:35 +0000 Subject: [PATCH] Initial logging module [#336] --- modules/command/command.js | 1 + modules/log/config.json | 7 +++++++ modules/log/log.js | 24 ++++++++++++++++++++++++ modules/log/strings.json | 5 +++++ 4 files changed, 37 insertions(+) create mode 100644 modules/log/config.json create mode 100644 modules/log/log.js create mode 100644 modules/log/strings.json diff --git a/modules/command/command.js b/modules/command/command.js index 776299c..cab3439 100644 --- a/modules/command/command.js +++ b/modules/command/command.js @@ -51,6 +51,7 @@ var command = function(dbot) { }); } } + dbot.api.event.emit('command', [ event ]); dbot.save(); } else { if(commandName !== '~') { diff --git a/modules/log/config.json b/modules/log/config.json new file mode 100644 index 0000000..d4b8475 --- /dev/null +++ b/modules/log/config.json @@ -0,0 +1,7 @@ +{ + "logChannel": { + "aberwiki": "#dbot" + }, + "ignorable": false, + "dependencies": [ "event", "command" ] +} diff --git a/modules/log/log.js b/modules/log/log.js new file mode 100644 index 0000000..a799672 --- /dev/null +++ b/modules/log/log.js @@ -0,0 +1,24 @@ +/** + * Name: Log + * Description: Log commands to a channel. + */ +var _ = require('underscore')._; + +var log = function(dbot) { + this.onLoad = function() { + dbot.api.event.addHook('command', function(event) { + var logChannel = this.config.logChannel[event.server]; + if(logChannel) { + dbot.say(event.server, logChannel, dbot.t('log_message', { + 'time': new Date().toUTCString(), + 'command': event.message, + 'user': event.user + })); + } + }.bind(this)); + }.bind(this); +}; + +exports.fetch = function(dbot) { + return new log(dbot); +}; diff --git a/modules/log/strings.json b/modules/log/strings.json new file mode 100644 index 0000000..c25d7a8 --- /dev/null +++ b/modules/log/strings.json @@ -0,0 +1,5 @@ +{ + "log_message": { + "en": "[{time}] {user}: {command}" + } +}