0

Karma Script (word++/word--)

Free lines JavaScript 2 revisions 53 22 days ago 22 days ago
discord-sporks
var arr = message.content.split(' ');
if (arr[0] == '!karma') {
  var k = load("karma_" + arr[1]);
  if (k == undefined || parseInt(k) == 0) {
    create_message(CHANNEL_ID, arr[1] + " has neutral karma.");
  } else {
  	create_message(CHANNEL_ID, "karma for " + arr[1] + " is " + k);
  }
} else {
  for (i = 0; i < arr.length; ++i) {
    var modifier = 0;
    if (arr[i].slice(-2) == "--") {
      modifier = -1;
    } else if (arr[i].slice(-2) == "++") {
      modifier = +1;
    }
    if (modifier != 0) {
      var word = arr[i].substring(0, arr[i].length - 2);
      var k = load("karma_" + word);
      if (k == undefined) {
        k = modifier;
      } else {
        k = parseInt(k);
        k += modifier;
      }
      save("karma_" + word, k.toString());
    }
  }
}

A script for Sporks which logs if someone rates a word up (by putting '++' on the end of it) or down (by putting '--' on the end of it). e.g. putting netflix++ in a line will add 1 to the karma of netflix, and netflix-- will take karma away. The command karma <word> will show the current karma of a word.