From a8760cd2bc73892ec83ad82e9d95a245649771f2 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 23 Oct 2014 18:05:40 -0400 Subject: [PATCH] only ban once for low rep also only check on downvotes --- src/favourites.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/favourites.js b/src/favourites.js index a678b613b4..341766bdb3 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -1,5 +1,5 @@ var async = require('async'), - + winston = require('winston'), db = require('./database'), posts = require('./posts'), user = require('./user'), @@ -44,11 +44,8 @@ var async = require('async'), db.sortedSetAdd('users:reputation', newreputation, postData.uid); - if (parseInt(meta.config['autoban:downvote'], 10) === 1 && newreputation < parseInt(meta.config['autoban:downvote:threshold'], 10)) { - var adminUser = require('./socket.io/admin/user'); - adminUser.banUser(postData.uid, function() { - require('winston').info('uid ' + uid + ' was banned for reaching ' + newreputation + ' reputation'); - }); + if (type === 'downvote') { + banUserForLowReputation(postData.uid, newreputation); } adjustPostVotes(pid, uid, type, unvote, function(err, votes) { @@ -66,6 +63,23 @@ var async = require('async'), }); } + function banUserForLowReputation(uid, newreputation) { + if (parseInt(meta.config['autoban:downvote'], 10) === 1 && newreputation < parseInt(meta.config['autoban:downvote:threshold'], 10)) { + user.getUserField(uid, 'banned', function(err, banned) { + if (err || parseInt(banned, 10) === 1) { + return; + } + var adminUser = require('./socket.io/admin/user'); + adminUser.banUser(uid, function(err) { + if (err) { + return winston.error(err.message); + } + winston.info('uid ' + uid + ' was banned for reaching ' + newreputation + ' reputation'); + }); + }); + } + } + function adjustPostVotes(pid, uid, type, unvote, callback) { var notType = (type === 'upvote' ? 'downvote' : 'upvote');