<commit_before>var querystring = require('querystring');
var request = require('request');

function now() {
  return parseInt( (new Date()).getTime() / 1000 );
}

function ProjectStatus(zen, redis, config) {
  var self = this;
  self.zen = zen;
  self.redis = redis;
  self.config = config;
}

// Returns a key namespaced to this project for use in Redis
ProjectStatus.prototype.rkey = function(key) {
  return "projects-"+key;
}


ProjectStatus.prototype.ask_done = function(channel, username, nick) {
  var self = this;

  var questions = [
    "What did you finish?",
    "Did you finish anything?",
  ];

  self.zen.send_privmsg(channel, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("done", username);
};

ProjectStatus.prototype.ask_doing = function(channel, username, nick) {
  var self = this;

  var questions = [
    "What have you been working on?",
    "What are you working on?"
  ];

  self.zen.send_privmsg(channel, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("doing", username);
};

ProjectStatus.prototype.ask_future = function(channel, username, nick) {
  var self = this;

  var questions = [
    "What are you going to do tomorrow?",
    "What's your plan for tomorrow?",
  ];

  self.zen.send_privmsg(channel, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("future", username);
};

ProjectStatus.prototype.ask_blocking = function(channel, username, nick) {
  var self = this;

  var questions = [
    "What are you stuck on? Or 'not stuck on anything' is fine too.",
    "What is blocking you? 'Not blocked' is fine too.",
    "Are you blocked on anything?",
  ];

  self.zen.send_privmsg(channel, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("blocking", username);
};

ProjectStatus.prototype.ask_hero = function(channel, username, nick) {
  var self = this;

  var questions = [
    "Who is your hero and what did they do?",
  ];

  self.zen.send_privmsg(nick, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("hero", username);
};

ProjectStatus.prototype.send_confirmation = function(nick, channel, type) {
  var self = this;

  var replies;

  // Set a few default replies. Specific types can override or add to this list.
  replies = [
    nick + ": Got it!",
    nick + ": Nice.",
    nick + ": nice",
    nick + ": Ok! Got it!",
    nick + ": ok!",
    nick + ": awesome!",
    nick + ": Awesome!"
  ];

  switch(type) {
    case 'remove':
      replies = [
        nick + ": ok it's gone",
        nick + ": erased!",
        nick + ": ok I removed it",
        nick + ": ok I got rid of it",
        nick + ": gone!"
      ];
      break;
    case 'blocking':
      replies = [
        nick + ": Sorry to hear that!",
        nick + ": I will remember that",
        nick + ": I hope it is resolved soon!",
        nick + ": :(",
        nick + ": Thanks for letting me know!"
      ];
      break;
    case 'done':
      replies.push(nick + ": Nicely done.");
      replies.push(nick + ": Nicely done!");
      replies.push(nick + ": nicely done!");
      replies.push(nick + ": great!");
      break;
    case 'doing':
      replies.push(nick + ": great, thanks!");
      replies.push(nick + ": Great, thanks!");
      replies.push(nick + ": Thanks!");
      replies.push(nick + ": thanks!");
      replies.push("Thanks, " + nick);
      replies.push("Thanks, " + nick + "!");
      break;
    case 'quote':
      replies.push(nick + ": Good one!");
      replies.push(nick + ": good one!");
      replies.push(nick + ": lol!");
      replies.push(nick + ": haha, awesome");
      replies.push(nick + ": haha, awesome!");
      break;
    case 'hero':
      replies.push(nick + ": sweet!");
      replies.push(nick + ": Sweet!");
      replies.push(nick + ": yeah!!");
      replies.push(nick + ": yeah!");
      replies.push(nick + ": awesome!");
    case 'share':
      replies.push(nick + ": sweet!");
      replies.push(nick + ": Sweet!");
      replies.push(nick + ": yeah!");
      replies.push(nick + ": awesome!");
      break;
  }

  self.zen.send_privmsg(channel, replies[Math.floor(Math.random()*replies.length)]);
}


// Store the last time we asked each person each type of question

ProjectStatus.prototype.get_lastasked = function(type, username, callback) {
  var self = this;

  if(type == "all") {
    self.redis.mget([self.rkey("lastasked-done-"+username),self.rkey("lastasked-doing-"+username),self.rkey("lastasked-future-"+username),self.rkey("lastasked-blocking-"+username),self.rkey("lastasked-hero-"+username),self.rkey("lastasked-share-"+username)], function(err,data){
      if(data){
        callback({
          done: data[0],
          doing: data[1],
          future: data[2],
          blocking: data[3],
          hero: data[4],
          share: data[5]
        });
      }
    });
  } else {
    self.redis.get(self.rkey("lastasked-"+type+"-"+username), callback);
  }
}

ProjectStatus.prototype.set_lastasked = function(type, username) {
  var self = this;

  if(type == "all") {
    for(t in ["done","doing","future","blocking","hero"]) {
      self.redis.set(self.rkey("lastasked-"+t+"-"+username), now(), function(){});
    }
  } else {
    self.redis.set(self.rkey("lastasked-"+type+"-"+username), now(), function(){});
  }
}


// Store the last time we got a reply from each person

ProjectStatus.prototype.get_lastreplied = function(type, username, callback) {
  var self = this;

  self.redis.get(self.rkey("lastreplied-"+type+"-"+username), callback);
}

ProjectStatus.prototype.set_lastreplied = function(type, username) {
  var self = this;

  self.redis.set(self.rkey("lastreplied-"+type+"-"+username), now(), function(){});
  self.redis.set(self.rkey("lastreplied-any-"+username), now(), function(){});
}


// Tracks the current nick of each user based on the last time they spoke
ProjectStatus.prototype.spoke = function(channel, username, nick) {
  var self = this;

  // Store the user's current nick
  self.redis.hset(self.rkey(channel+"-"+username), "nick", nick, function(){});
}


ProjectStatus.prototype.get_nick = function(channel, username, callback) {
  var self = this;

  self.redis.hget(self.rkey(channel+"-"+username), "nick", callback);
}


ProjectStatus.prototype.record_response = function(username, type, message, nick, channel) {
  var self = this;

  console.log("Sending update...");

  self.set_lastreplied(type, username);

  // Send the message to the API
  self.submit_report(channel, username, type, message, function(response){
    console.log("Got a response!");
    // console.log(response);
    if(response.entry) {
      self.send_confirmation(nick, channel, type);
    } else {
      if(response.error == "user_not_found") {
        self.zen.send_privmsg(channel, "Sorry, I couldn't find an account for " + response.error_username);
      } else if(response.error == "user_not_in_group") {
        self.zen.send_privmsg(channel, "Sorry, you're not in this group!");
      } else {
        self.zen.send_privmsg(channel, "Something went wrong trying to store your entry!");
        console.log(response);
      }
    }
  });
}

ProjectStatus.prototype.remove_response = function(username, message, nick, channel) {
  var self = this;

  console.log("Removing...");

  // Send the message to the API
  self.submit_report(channel, username, 'remove', message, function(response){
    console.log("Got a response!");
    console.log(response);
    if(response.result == 'success') {
      self.send_confirmation(nick, channel, 'remove');
    } else {
      if(response.error == "user_not_found") {
        self.zen.send_privmsg(channel, "Sorry, I couldn't find an account for " + response.error_username);
      } else if(response.error == "entry_not_found") {
        self.zen.send_privmsg(channel, "Couldn't find that entry, make sure the text matches exactly");
      } else {
        self.zen.send_privmsg(channel, "Something went wrong trying to remove your entry!");<commit_msg>update to support submitting from other groups<commit_after>var querystring = require('querystring');
var request = require('request');

function now() {
  return parseInt( (new Date()).getTime() / 1000 );
}

function ProjectStatus(zen, redis, config) {
  var self = this;
  self.zen = zen;
  self.redis = redis;
  self.config = config;
}

// Returns a key namespaced to this project for use in Redis
ProjectStatus.prototype.rkey = function(key) {
  return "projects-"+key;
}


ProjectStatus.prototype.ask_done = function(channel, username, nick) {
  var self = this;

  var questions = [
    "What did you finish?",
    "Did you finish anything?",
  ];

  self.zen.send_privmsg(channel, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("done", username);
};

ProjectStatus.prototype.ask_doing = function(channel, username, nick) {
  var self = this;

  var questions = [
    "What have you been working on?",
    "What are you working on?"
  ];

  self.zen.send_privmsg(channel, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("doing", username);
};

ProjectStatus.prototype.ask_future = function(channel, username, nick) {
  var self = this;

  var questions = [
    "What are you going to do tomorrow?",
    "What's your plan for tomorrow?",
  ];

  self.zen.send_privmsg(channel, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("future", username);
};

ProjectStatus.prototype.ask_blocking = function(channel, username, nick) {
  var self = this;

  var questions = [
    "What are you stuck on? Or 'not stuck on anything' is fine too.",
    "What is blocking you? 'Not blocked' is fine too.",
    "Are you blocked on anything?",
  ];

  self.zen.send_privmsg(channel, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("blocking", username);
};

ProjectStatus.prototype.ask_hero = function(channel, username, nick) {
  var self = this;

  var questions = [
    "Who is your hero and what did they do?",
  ];

  self.zen.send_privmsg(nick, nick+": "+questions[Math.floor(Math.random()*questions.length)]);
  self.set_lastasked("hero", username);
};

ProjectStatus.prototype.send_confirmation = function(nick, channel, type) {
  var self = this;

  var replies;

  // Set a few default replies. Specific types can override or add to this list.
  replies = [
    nick + ": Got it!",
    nick + ": Nice.",
    nick + ": nice",
    nick + ": Ok! Got it!",
    nick + ": ok!",
    nick + ": awesome!",
    nick + ": Awesome!"
  ];

  switch(type) {
    case 'remove':
      replies = [
        nick + ": ok it's gone",
        nick + ": erased!",
        nick + ": ok I removed it",
        nick + ": ok I got rid of it",
        nick + ": gone!"
      ];
      break;
    case 'blocking':
      replies = [
        nick + ": Sorry to hear that!",
        nick + ": I will remember that",
        nick + ": I hope it is resolved soon!",
        nick + ": :(",
        nick + ": Thanks for letting me know!"
      ];
      break;
    case 'done':
      replies.push(nick + ": Nicely done.");
      replies.push(nick + ": Nicely done!");
      replies.push(nick + ": nicely done!");
      replies.push(nick + ": great!");
      break;
    case 'doing':
      replies.push(nick + ": great, thanks!");
      replies.push(nick + ": Great, thanks!");
      replies.push(nick + ": Thanks!");
      replies.push(nick + ": thanks!");
      replies.push("Thanks, " + nick);
      replies.push("Thanks, " + nick + "!");
      break;
    case 'quote':
      replies.push(nick + ": Good one!");
      replies.push(nick + ": good one!");
      replies.push(nick + ": lol!");
      replies.push(nick + ": haha, awesome");
      replies.push(nick + ": haha, awesome!");
      break;
    case 'hero':
      replies.push(nick + ": sweet!");
      replies.push(nick + ": Sweet!");
      replies.push(nick + ": yeah!!");
      replies.push(nick + ": yeah!");
      replies.push(nick + ": awesome!");
    case 'share':
      replies.push(nick + ": sweet!");
      replies.push(nick + ": Sweet!");
      replies.push(nick + ": yeah!");
      replies.push(nick + ": awesome!");
      break;
  }

  self.zen.send_privmsg(channel, replies[Math.floor(Math.random()*replies.length)]);
}


// Store the last time we asked each person each type of question

ProjectStatus.prototype.get_lastasked = function(type, username, callback) {
  var self = this;

  if(type == "all") {
    self.redis.mget([self.rkey("lastasked-done-"+username),self.rkey("lastasked-doing-"+username),self.rkey("lastasked-future-"+username),self.rkey("lastasked-blocking-"+username),self.rkey("lastasked-hero-"+username),self.rkey("lastasked-share-"+username)], function(err,data){
      if(data){
        callback({
          done: data[0],
          doing: data[1],
          future: data[2],
          blocking: data[3],
          hero: data[4],
          share: data[5]
        });
      }
    });
  } else {
    self.redis.get(self.rkey("lastasked-"+type+"-"+username), callback);
  }
}

ProjectStatus.prototype.set_lastasked = function(type, username) {
  var self = this;

  if(type == "all") {
    for(t in ["done","doing","future","blocking","hero"]) {
      self.redis.set(self.rkey("lastasked-"+t+"-"+username), now(), function(){});
    }
  } else {
    self.redis.set(self.rkey("lastasked-"+type+"-"+username), now(), function(){});
  }
}


// Store the last time we got a reply from each person

ProjectStatus.prototype.get_lastreplied = function(type, username, callback) {
  var self = this;

  self.redis.get(self.rkey("lastreplied-"+type+"-"+username), callback);
}

ProjectStatus.prototype.set_lastreplied = function(type, username) {
  var self = this;

  self.redis.set(self.rkey("lastreplied-"+type+"-"+username), now(), function(){});
  self.redis.set(self.rkey("lastreplied-any-"+username), now(), function(){});
}


// Tracks the current nick of each user based on the last time they spoke
ProjectStatus.prototype.spoke = function(channel, username, nick) {
  var self = this;

  // Store the user's current nick
  self.redis.hset(self.rkey(channel+"-"+username), "nick", nick, function(){});
}


ProjectStatus.prototype.get_nick = function(channel, username, callback) {
  var self = this;

  self.redis.hget(self.rkey(channel+"-"+username), "nick", callback);
}


ProjectStatus.prototype.record_response = function(username, type, message, nick, channel) {
  var self = this;

  console.log("Sending update...");

  self.set_lastreplied(type, username);

  // Send the message to the API
  self.submit_report(channel, username, type, message, function(response){
    console.log("Got a response!");
    // console.log(response);
    if(response.entry) {
      self.send_confirmation(nick, channel, type);
    } else {
      if(response.error == "user_not_found") {
        self.zen.send_privmsg(channel, "Sorry, I couldn't find an account for " + response.error_username);
      } else if(response.error == "user_not_in_group") {
        self.zen.send_privmsg(channel, "Sorry, you're not in this group!");
      } else if(response.error == "user_not_in_org") {
        self.zen.send_privmsg(channel, "Sorry, you're not in this organization!");
      } else {
        self.zen.send_privmsg(channel, "Something went wrong trying to store your entry!");
        console.log(response);
      }
    }
  });
}

ProjectStatus.prototype.remove_response = function(username, message, nick, channel) {
  var self = this;

  console.log("Removing...");

  // Send the message to the API
  self.submit_report(channel, username, 'remove', message, function(response){
    console.log("Got a response!");
    console.log(response);
    if(response.result == 'success') {
      self.send_confirmation(nick, channel, 'remove');
    } else {
      if(response.error == "user_not_found") {
        self.zen.send_privmsg(channel, "Sorry, I couldn't find an account for " + response.error_username);
      } else if(response.error == "entry_not_found") {
        self.zen.send_privmsg(channel, "Couldn't find that entry, make sure the text matches exactly");
      } else {
        self.zen.send_privmsg(channel, "Something went wrong trying to remove your entry!");
{'fraction_non_alphanumeric': 0.16472169609580253, 'fraction_numerical': 0.001221971039286369, 'mean_word_length': 3.3107716618382934, 'pattern_counts': {'":': 88, '<': 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': '64301', 'n_tokens_mistral': 5262, 'n_tokens_neox': 5169, 'n_words': 1225}