<commit_before>var bot;

var scoreboard = {};

loadKarma = function(cb) {
  bot.fsGetData('karma', 'karma.json', function(err, res) {
    if(err) {
      console.log("Error loading karma data " + err);
      scoreboard = {};
      return;
    }

    scoreboard = JSON.parse(res);

    cb && cb();
  });
}

saveKarma = function(cb) {
  bot.fsStoreData('karma', 'karma.json', JSON.stringify(scoreboard), function() {
    cb && cb();
  });
}

module.exports.init = function(b) {
  bot = b;
  loadKarma();
};

var inc = /(\w+)\+\+/;
var incfor = /(\w+)\+\+\s+(\sfor)?\s+(.+)/;
var dec = /(\w+)--/;
var decfor = /(\w+)--\s*(\sfor)?\s+(.+)/;

// Watch for messages of the following forms
// dru++
// dru++ for some reason
module.exports.message = function(text, from, to, reply, raw) {
  var re;

  scoreboard[to] = scoreboard[to] || {};

  if (re = incfor.exec(text)) {
    var user = re[1],
      reason = re[2];

    scoreboard[to][user] = scoreboard[to][user] || { points: 0, reasons: [] };
    scoreboard[to][user]['points']++;
    scoreboard[to][user]['increasons'].push(reason);

    //    reply(user + " now has " + scoreboard[user]['points'] + " points (nth place!), including 1 for " + reason); // #todo nth place
    saveKarma();
  } 
  else if (re = inc.exec(text)) {
    var user = re[1];

    scoreboard[to][user] = scoreboard[to][user] || { points: 0, reasons: [] };
    scoreboard[to][user]['points']++;

    //    reply(user + " now has " + scoreboard[user]['points'] + " points (nth place!)"); // #todo nth place
    saveKarma();
  }
  else if (re = decfor.exec(text)) {
    var user = re[1],
      reason = re[2];

    scoreboard[to][user] = scoreboard[to][user] || { points: 0, reasons: [] };
    scoreboard[to][user]['points']--;
    scoreboard[to][user]['decreasons'].push(reason);

    saveKarma();
  }
  else if (re = dec.exec(text)) {
    var user = re[1];

    scoreboard[to][user] = scoreboard[to][user] || { points: 0, reasons: [] };
    scoreboard[to][user]['points']--;

    saveKarma();
  }
};
<commit_msg>fix some regexes and add some more<commit_after>var bot;

var scoreboard = {};

loadKarma = function(cb) {
  bot.fsGetData('karma', 'karma.json', function(err, res) {
    if(err) {
      console.log("Error loading karma data " + err);
      scoreboard = {};
      return;
    }

    scoreboard = JSON.parse(res);

    cb && cb();
  });
}

saveKarma = function(cb) {
  bot.fsStoreData('karma', 'karma.json', JSON.stringify(scoreboard), function() {
    cb && cb();
  });
}

module.exports.init = function(b) {
  bot = b;
  loadKarma();
};

// todo: these are probably wrong somehow
var postinc = /([^\s\+-]+)\+\+/;
var preinc = /\+\+([^\s\+-]+)/;
var incfor = /([^\s\+-]+)\+\+\s+(\sfor)?\s+(.+)/;
var postdec = /([^\s\+-]+)--/;
var predec = /--([^\s\+-]+)/;
var decfor = /([^\s\+-]+)--\s*(\sfor)?\s+(.+)/;

// Watch for messages of the following forms
// dru++
// ++dru
// dru++ for some reason
// dru--
// --dru
// dru-- for some reason
module.exports.message = function(text, from, to, reply, raw) {
  var re;

  scoreboard[to] = scoreboard[to] || {};

  if (re = incfor.exec(text)) {
    var user = re[1],
      reason = re[2];

    scoreboard[to][user] = scoreboard[to][user] || { points: 0, reasons: [] };
    scoreboard[to][user]['points']++;
    scoreboard[to][user]['increasons'].push(reason);

    //    reply(user + " now has " + scoreboard[user]['points'] + " points (nth place!), including 1 for " + reason); // #todo nth place
    saveKarma();
  } 
  else if (re = preinc.exec(text) || postinc.exec(text)) {
    var user = re[1];

    scoreboard[to][user] = scoreboard[to][user] || { points: 0, reasons: [] };
    scoreboard[to][user]['points']++;

    //    reply(user + " now has " + scoreboard[user]['points'] + " points (nth place!)"); // #todo nth place
    saveKarma();
  }
  else if (re = decfor.exec(text)) {
    var user = re[1],
      reason = re[2];

    scoreboard[to][user] = scoreboard[to][user] || { points: 0, reasons: [] };
    scoreboard[to][user]['points']--;
    scoreboard[to][user]['decreasons'].push(reason);

    saveKarma();
  }
  else if (re = predec.exec(text) || postdec.exec(text)) {
    var user = re[1];

    scoreboard[to][user] = scoreboard[to][user] || { points: 0, reasons: [] };
    scoreboard[to][user]['points']--;

    saveKarma();
  }
};

{'fraction_non_alphanumeric': 0.23304790557741265, 'fraction_numerical': 0.0050914140245313586, 'mean_word_length': 3.027958993476235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6152814', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1566, 'n_words': 335}