2012-03-14 22:32:27 +01:00
|
|
|
var logging = function(dbot) {
|
2012-03-14 23:38:20 +01:00
|
|
|
var logMessage = function(message, channel) {
|
2012-03-14 22:32:27 +01:00
|
|
|
if(!(dbot.hasOwnProperty('log'))) {
|
2012-03-14 23:38:20 +01:00
|
|
|
dbot['log'] = {};
|
2012-03-14 22:32:27 +01:00
|
|
|
}
|
2012-03-14 23:38:20 +01:00
|
|
|
|
|
|
|
if(channel) {
|
|
|
|
channel = channel.toLowerCase();
|
|
|
|
} else {
|
|
|
|
channel = '@'; // it's a logger message, shouldn't go in any channel. hence, invalid channel name '@'
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(dbot.log.hasOwnProperty(channel))) {
|
|
|
|
dbot.log[channel] = [];
|
|
|
|
}
|
|
|
|
dbot.log[channel].push([Date.now(), message]);
|
2012-03-14 22:32:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
'onLoad': function() {
|
|
|
|
logMessage({
|
|
|
|
'type': 'LoggerEvent',
|
|
|
|
'details': 'Logger loaded.'
|
|
|
|
});
|
|
|
|
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
|
|
|
|
'onDestroy': function() {
|
|
|
|
logMessage({
|
|
|
|
'type': 'LoggerEvent',
|
|
|
|
'details': 'Logger unloaded.'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
'listener': function(data, eventType) {
|
|
|
|
logMessage({
|
|
|
|
'type': 'IRCEvent',
|
|
|
|
'details': {
|
|
|
|
'eventType': eventType,
|
|
|
|
'data': data
|
|
|
|
}
|
2012-03-14 23:38:20 +01:00
|
|
|
}, data.channel);
|
2012-03-14 22:32:27 +01:00
|
|
|
},
|
|
|
|
'on': ['JOIN', 'PART', 'KICK', 'PRIVMSG', 'MODE']
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return logging(dbot);
|
|
|
|
};
|