<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);
      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.msg = function(text, from, reply, raw) {
  var re;

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

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

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

    //    reply(user + " now has " + this.scoreboard[user]['points'] + " points (nth place!), including 1 for " + reason); // #todo nth place

  } 
  else if (re = inc.exec(text)) {
    var user = re[0];

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

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

    this.scoreboard[from][user] = this.scoreboard[from][user] || { points: 0, reasons: [] };
    this.scoreboard[from][user]['points']--;
    this.scoreboard[from][user]['decreasons'].push(reason);
  }
  else if (re = dec.exec(text)) {
    var user = re[0];

    this.scoreboard[from][user] = this.scoreboard[from][user] || { points: 0, reasons: [] };
    this.scoreboard[from][user]['points']--;
  }<commit_msg>don't forget to save karma<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);
      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.msg = function(text, from, reply, raw) {
  var re;

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

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

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

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

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

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

    this.scoreboard[from][user] = this.scoreboard[from][user] || { points: 0, reasons: [] };
    this.scoreboard[from][user]['points']--;
    this.scoreboard[from][user]['decreasons'].push(reason);
    saveKarma();
  }
  else if (re = dec.exec(text)) {
    var user = re[0];

    this.scoreboard[from][user] = this.scoreboard[from][user] || { points: 0, reasons: [] };
    this.scoreboard[from][user]['points']--;
    saveKarma();
  }
{'fraction_non_alphanumeric': 0.22294372294372294, 'fraction_numerical': 0.005291005291005291, 'mean_word_length': 3.218052738336714, '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': '7343755', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1487, 'n_words': 304}