From a57b123fed5876772fbe3165aa9ca7a8093155c5 Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 14 Dec 2016 21:58:42 +0000 Subject: [PATCH] two space indent for log and karma, karma logging --- modules/karma/karma.js | 265 +++++++++++++++++++++-------------------- modules/log/log.js | 108 ++++++++--------- 2 files changed, 188 insertions(+), 185 deletions(-) diff --git a/modules/karma/karma.js b/modules/karma/karma.js index 09bdbd2..354fc69 100644 --- a/modules/karma/karma.js +++ b/modules/karma/karma.js @@ -5,147 +5,150 @@ var _ = require('underscore')._; var karma = function(dbot) { - this.lastKarma = {}; + this.lastKarma = {}; - this.internalAPI = { - 'getKarma': function(item, callback) { - this.db.read('karma', item.toLowerCase(), callback); - }.bind(this), + this.internalAPI = { + 'getKarma': function(item, callback) { + this.db.read('karma', item.toLowerCase(), callback); + }.bind(this), - 'setKarma': function(item, value, callback) { - this.db.save('karma', item.toLowerCase(), { - 'item': item.toLowerCase(), - 'karma': value - }, callback); - }.bind(this) - }; + 'setKarma': function(item, value, callback) { + this.db.save('karma', item.toLowerCase(), { + 'item': item.toLowerCase(), + 'karma': value + }, callback); + }.bind(this) + }; - this.commands = { - 'karma': function(event) { - var item = event.params[1] || event.user; - this.internalAPI.getKarma(item, function(err, karma) { - if(!err && karma) { - karma = karma.karma; - } else { - karma = 0; - } - - event.reply(dbot.t('karma', { - 'item': item, - 'karma': karma - })); - }); - }, - - 'setkarma': function(event) { - var item = event.params[1], - value = parseInt(event.params[2]); - - this.internalAPI.setKarma(item, value, function(err, karma) { - event.reply(dbot.t('newkarma', { - 'item': item, - 'value': value - })); - }); - }, - - 'unkarmaiest': function(event) { - var karmas = {}; - this.db.scan('karma', function(karma) { - if(karma && !_.isUndefined(karma.item)) { - karmas[karma.item] = karma.karma; - } - }.bind(this), function(err) { - var qSizes = _.chain(karmas) - .pairs() - .sortBy(function(category) { return category[1]; }) - .first(10) - .value(); - - var qString = 'Unkarmaiest: '; - for(var i=0;i Date.now()) { - return event.reply('Try again in a few seconds : - )'); - } else if(event.rUser.currentNick.toLowerCase() === match[1].toLowerCase() || event.rUser.primaryNick.toLowerCase() === match[1].toLowerCase()) { - return event.reply('Stop playing with yourself : - )'); - } else if(event.channel == event.user) { - return event.reply('Don\'t be a Secretive Sally : - )'); - } + 'setkarma': function(event) { + var item = event.params[1], + value = parseInt(event.params[2]); - this.internalAPI.getKarma(match[1], function(err, karma) { - if(!karma) { - karma = 0; - } else { - karma = karma.karma; - } + this.internalAPI.setKarma(item, value, function(err, karma) { + event.reply(dbot.t('newkarma', { + 'item': item, + 'value': value + })); + }); + }, - if(match[2] === '--') { - karma -= 1; - } else { - karma += 1; - } - - this.internalAPI.setKarma(match[1], karma, function(err, karma) { - this.lastKarma[event.rUser.id] = Date.now(); - var pre; - if(karma.karma > 0) { - pre = '[\u00039karma\u000f]'; - karma.karma = '\u00039 '+karma.karma+'\u000f'; - } else if(karma.karma < 0) { - pre = '[\u00034karma\u000f]'; - karma.karma = '\u00034 '+karma.karma+'\u000f'; - } else { - pre = '[\u00036karma\u000f]'; - karma.karma = '\u00036 '+karma.karma+'\u000f'; - } - event.reply(pre + ' ' + dbot.t('newkarma', { - 'item': match[1], - 'value': karma.karma - })); - }.bind(this)); - }.bind(this)); + 'unkarmaiest': function(event) { + var karmas = {}; + this.db.scan('karma', function(karma) { + if(karma && !_.isUndefined(karma.item)) { + karmas[karma.item] = karma.karma; } - }.bind(this); - this.on = 'PRIVMSG'; + }.bind(this), function(err) { + var qSizes = _.chain(karmas) + .pairs() + .sortBy(function(category) { return category[1]; }) + .first(10) + .value(); + + var qString = 'Unkarmaiest: '; + for(var i=0;i Date.now()) { + return event.reply('Try again in a few seconds : - )'); + } else if(event.rUser.currentNick.toLowerCase() === match[1].toLowerCase() || event.rUser.primaryNick.toLowerCase() === match[1].toLowerCase()) { + return event.reply('Stop playing with yourself : - )'); + } else if(event.channel == event.user) { + return event.reply('Don\'t be a Secretive Sally : - )'); + } + + this.internalAPI.getKarma(match[1], function(err, karma) { + if(!karma) { + karma = 0; + } else { + karma = karma.karma; + } + + if(match[2] === '--') { + karma -= 1; + } else { + karma += 1; + } + + this.internalAPI.setKarma(match[1], karma, function(err, karma) { + this.lastKarma[event.rUser.id] = Date.now(); + var pre; + if(karma.karma > 0) { + pre = '[\u00039karma\u000f]'; + karma.karma = '\u00039 '+karma.karma+'\u000f'; + } else if(karma.karma < 0) { + pre = '[\u00034karma\u000f]'; + karma.karma = '\u00034 '+karma.karma+'\u000f'; + } else { + pre = '[\u00036karma\u000f]'; + karma.karma = '\u00036 '+karma.karma+'\u000f'; + } + event.reply(pre + ' ' + dbot.t('newkarma', { + 'item': match[1], + 'value': karma.karma + })); + if(_.has(dbot.modules, 'log')) { + dbot.api.log.log(event.server, event.rUser.primaryNick, event.message); + } + }.bind(this)); + }.bind(this)); + } + }.bind(this); + this.on = 'PRIVMSG'; }; exports.fetch = function(dbot) { - return new karma(dbot); + return new karma(dbot); }; diff --git a/modules/log/log.js b/modules/log/log.js index 2ae1df5..a8f1a1e 100644 --- a/modules/log/log.js +++ b/modules/log/log.js @@ -3,70 +3,70 @@ * Description: Log commands to a channel. */ var _ = require('underscore')._, - process = require('process'); + process = require('process'); var log = function(dbot) { - this.ignoredCommands = []; + this.ignoredCommands = []; - this.api = { - 'log': function(server, user, message) { - var logChannel = this.config.logChannel[server]; - dbot.say(server, logChannel, dbot.t('log_message', { - 'time': new Date().toUTCString(), - 'command': message, - "channel": 'nochan', - 'user': user - })); - }, + this.api = { + 'log': function(server, user, message) { + var logChannel = this.config.logChannel[server]; + dbot.say(server, logChannel, dbot.t('log_message', { + 'time': new Date().toUTCString(), + 'command': message, + "channel": 'nochan', + 'user': user + })); + }, - 'logError': function(server, err) { - var stack = err.stack.split('\n').slice(1, dbot.config.debugLevel + 1), - logChannel = this.config.logChannel[server], - time = new Date().toUTCString(); + 'logError': function(server, err) { + var stack = err.stack.split('\n').slice(1, dbot.config.debugLevel + 1), + logChannel = this.config.logChannel[server], + time = new Date().toUTCString(); - dbot.say(server, logChannel, dbot.t('error_message', { - 'time': time, - 'error': 'Message: ' + err - })); + dbot.say(server, logChannel, dbot.t('error_message', { + 'time': time, + 'error': 'Message: ' + err + })); - _.each(stack, function(stackLine, index) { - dbot.say(server, logChannel, dbot.t('error_message', { - 'time': time, - 'error': 'Stack[' + index + ']: ' + - stackLine.trim() - })); - }); - }, + _.each(stack, function(stackLine, index) { + dbot.say(server, logChannel, dbot.t('error_message', { + 'time': time, + 'error': 'Stack[' + index + ']: ' + + stackLine.trim() + })); + }); + }, - 'ignoreCommand': function(commandName) { - this.ignoredCommands.push(commandName); - } - }; + 'ignoreCommand': function(commandName) { + this.ignoredCommands.push(commandName); + } + }; - this.onLoad = function() { - dbot.api.event.addHook('command', function(event) { - var logChannel = this.config.logChannel[event.server]; - channel = event.channel.name || 'PM'; - if(logChannel && !_.include(this.ignoredCommands, event.message.split(' ')[0])) { - dbot.say(event.server, logChannel, dbot.t('log_message', { - 'time': new Date().toUTCString(), - 'channel': channel, - 'command': event.message, - 'user': event.user - })); - } - }.bind(this)); + this.onLoad = function() { + dbot.api.event.addHook('command', function(event) { + var logChannel = this.config.logChannel[event.server]; + channel = event.channel.name || 'PM'; + if(logChannel && !_.include(this.ignoredCommands, event.message.split(' ')[0])) { + dbot.say(event.server, logChannel, dbot.t('log_message', { + 'time': new Date().toUTCString(), + 'channel': channel, + 'command': event.message, + 'user': event.user + })); + } + }.bind(this)); - process.on('uncaughtException', function(err) { - console.log(err); - _.each(this.config.logChannel, function(chan, server) { - this.api.logError(server, err); - }, this); - process.exit(1); - }.bind(this)); - }.bind(this); + process.on('uncaughtException', function(err) { + console.log(err); + _.each(this.config.logChannel, function(chan, server) { + this.api.logError(server, err); + }, this); + process.exit(1); + }.bind(this)); + }.bind(this); }; exports.fetch = function(dbot) { - return new log(dbot); + return new log(dbot); };