2013-05-25 21:13:35 +02:00
|
|
|
/**
|
|
|
|
* Name: Log
|
|
|
|
* Description: Log commands to a channel.
|
|
|
|
*/
|
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
|
|
|
var log = function(dbot) {
|
2013-08-18 19:42:23 +02:00
|
|
|
this.ignoredCommands = [];
|
|
|
|
|
2013-08-18 18:37:30 +02:00
|
|
|
this.api = {
|
|
|
|
'log': function(server, user, message) {
|
2013-08-18 18:39:35 +02:00
|
|
|
var logChannel = this.config.logChannel[server];
|
2013-08-18 18:37:30 +02:00
|
|
|
dbot.say(server, logChannel, dbot.t('log_message', {
|
|
|
|
'time': new Date().toUTCString(),
|
|
|
|
'command': message,
|
2013-08-31 15:31:45 +02:00
|
|
|
"channel": 'nochan',
|
2013-08-18 18:37:30 +02:00
|
|
|
'user': user
|
|
|
|
}));
|
2013-08-18 19:42:23 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'ignoreCommand': function(commandName) {
|
|
|
|
this.ignoredCommands.push(commandName);
|
2013-08-18 18:37:30 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-25 21:13:35 +02:00
|
|
|
this.onLoad = function() {
|
|
|
|
dbot.api.event.addHook('command', function(event) {
|
|
|
|
var logChannel = this.config.logChannel[event.server];
|
2013-08-31 15:33:10 +02:00
|
|
|
channel = event.channel.name || 'PM';
|
2013-08-18 19:46:57 +02:00
|
|
|
if(logChannel && !_.include(this.ignoredCommands, event.message.split(' ')[0])) {
|
2013-05-25 21:13:35 +02:00
|
|
|
dbot.say(event.server, logChannel, dbot.t('log_message', {
|
|
|
|
'time': new Date().toUTCString(),
|
2013-08-31 15:33:10 +02:00
|
|
|
'channel': channel,
|
2013-05-25 21:13:35 +02:00
|
|
|
'command': event.message,
|
|
|
|
'user': event.user
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new log(dbot);
|
|
|
|
};
|