<commit_before>var app = require('express')();
var AuthDetails = require('./auth.json');
var Botkit = require('botkit');
var Challonge = require('./challonge_plugin.js');
var challonge_plugin = new Challonge();

app.set('port', (process.env.PORT || 5000));

//For avoidong Heroku $PORT error
app.get('/', function(request, response) {
  response.send('Who\'s Ready for some Tourneys?!?!?!?');
}).listen(app.get('port'), function() {
  console.log('App is running, server is listening on port ', app.get('port'));
});

var controller = Botkit.slackbot({
  json_file_store: 'data/'
});

var bot = controller.spawn(AuthDetails);
bot.startRTM(function(err,bot,payload) {
  if (err) {
    throw new Error('Could not connect to Slack');
  }
  // getAllUsers();
});

// simple hello world schtuff
controller.hears(['hello', 'hi'], 'direct_message,direct_mention,mention', function(bot, message) {

    bot.api.reactions.add({
        timestamp: message.ts,
        channel: message.channel,
        name: 'robot_face',
    }, function(err, res) {
        if (err) {
            bot.botkit.log('Failed to add emoji reaction :(', err);
        }
    });

    controller.storage.users.get(message.user, function(err, user) {
        if (user && user.name) {
            bot.reply(message, 'Hello ' + user.name + '!!');
        } else {
            getUserData(message.user); //lets capture their data for later
            bot.reply(message, 'Hello.');
        }
    });
});

controller.hears(['list'], 'direct_message,direct_mention', function(bot, message) {
    commands.list.process(bot,message);
});

controller.hears(['create'], 'direct_message,direct_mention', function(bot, message) {
    commands.create.process(bot,message);
});

controller.hears(['add'], 'direct_message,direct_mention', function(bot, message) {
    commands.add.process(bot,message);
});

controller.hears(['cookie'], 'ambient', function(bot,message) {
    if(message.text.length === 6){
        bot.reply(message,'Do you jump off bridges when told, too? :stuck_out_tongue_winking_eye: ');
    }
});

// reply to @bot hello
controller.on('mention,direct_mention',function(bot,message) {
    var retort = mentionComments[Math.floor(Math.random() * mentionComments.length)];
    var theUser = getUserData(message.user,function(user){
        retort = retort.replace("{NICK}", user.name);
        bot.reply(message,retort);
    });
});

controller.on('ambient',function(bot,message){
    getUserData(message.user);

    bot.botkit.log('Message:',message);
    // the :penton: annoyance;
    // everytime penton posts a message
    // automatically react with :penton:
    if(message.user === 'U03GALE9V'){
        bot.api.reactions.add({
            timestamp: message.ts,
            channel: message.channel,
            name: 'penton',
        }, function(err, res) {
            if (err) {
                bot.botkit.log('Failed to add penton emoji reaction :(', err);
            }
        });
    }
});



// reply to a direct message
controller.on('direct_message',function(bot,message) {

  // reply to _message_ by using the _bot_ object
  bot.reply(message,'You are talking directly to me? Look, I\'m trying to work here...shouldn\'t you?');
});

var getUserData = function(id,callback){
    console.log('::getUserData::',id);
    controller.storage.users.get(id, function(err, user) {
        if (user && user.name) {
            if(callback){
              callback(user);
            }else{
              return user;
            }
        } else {
          var theUser = new Promise(function(resolve,reject) {
              bot.api.users.info({user: id},function(err,response) {
                  if(response.user){
                      // console.log('::userdata::',response.user);
                      controller.storage.users.save({
                        id: id,
                        name:response.user.name,
                        email: response.user.profile.email
                      }, function(err) {
                        bot.botkit.log('user-stored',response.user.name);
                      });
                      // console.log('::gotUserName::',response.user.name);
                      if(callback){
                        callback(response.user); //TODO change this to return the user object
                      }else{
                          return response.user;
                      }
                  }
              });
          // });
        }
    });
}

var getAllUsers = function(){
  controller.storage.users.all(function(err, all_user_data) {
    if(err){
      bot.botkit.log('::ERROR::',err);
    }
    console.log('::userdata::',all_user_data);
  });
}

var AskGameType = function(convo){<commit_msg>misc; cleanup<commit_after>var app = require('express')();
var AuthDetails = require('./auth.json');
var Botkit = require('botkit');
var Challonge = require('./challonge_plugin.js');
var challonge_plugin = new Challonge();

app.set('port', (process.env.PORT || 5000));

//For avoidong Heroku $PORT error
app.get('/', function(request, response) {
  response.send('Who\'s Ready for some Tourneys?!?!?!?');
}).listen(app.get('port'), function() {
  console.log('App is running, server is listening on port ', app.get('port'));
});

var controller = Botkit.slackbot({
  json_file_store: 'data/'
});

var bot = controller.spawn(AuthDetails);
bot.startRTM(function(err,bot,payload) {
  if (err) {
    throw new Error('Could not connect to Slack');
  }
  // getAllUsers();
});

// simple hello world schtuff
controller.hears(['hello', 'hi'], 'direct_message,direct_mention,mention', function(bot, message) {

    bot.api.reactions.add({
        timestamp: message.ts,
        channel: message.channel,
        name: 'robot_face',
    }, function(err, res) {
        if (err) {
            bot.botkit.log('Failed to add emoji reaction :(', err);
        }
    });

    controller.storage.users.get(message.user, function(err, user) {
        if (user && user.name) {
            bot.reply(message, 'Hello ' + user.name + '!!');
        } else {
            getUserData(message.user); //lets capture their data for later
            bot.reply(message, 'Hello.');
        }
    });
});

controller.hears(['list'], 'direct_message,direct_mention', function(bot, message) {
    commands.list.process(bot,message);
});

controller.hears(['create'], 'direct_message,direct_mention', function(bot, message) {
    commands.create.process(bot,message);
});

controller.hears(['add'], 'direct_message,direct_mention', function(bot, message) {
    commands.add.process(bot,message);
});

controller.hears(['cookie'], 'ambient', function(bot,message) {
    if(message.text.length === 6){
        bot.reply(message,'Do you jump off bridges when told, too? :stuck_out_tongue_winking_eye: ');
    }
});

// reply to @bot hello
controller.on('mention,direct_mention',function(bot,message) {
    var retort = mentionComments[Math.floor(Math.random() * mentionComments.length)];
    var theUser = getUserData(message.user,function(user){
        retort = retort.replace("{NICK}", user.name);
        bot.reply(message,retort);
    });
});

controller.on('ambient',function(bot,message){
    getUserData(message.user);

    bot.botkit.log('Message:',message);
    // the :penton: annoyance;
    // everytime penton posts a message
    // automatically react with :penton:
    if(message.user === 'U03GALE9V'){
        bot.api.reactions.add({
            timestamp: message.ts,
            channel: message.channel,
            name: 'penton',
        }, function(err, res) {
            if (err) {
                bot.botkit.log('Failed to add penton emoji reaction :(', err);
            }
        });
    }
});

// reply to a direct message
controller.on('direct_message',function(bot,message) {

  // reply to _message_ by using the _bot_ object
  bot.reply(message,'You are talking directly to me? Look, I\'m trying to work here...shouldn\'t you?');
  bot.reply(message,'LOL j/k! What can I help you with? (_psst_, type `help` if you need to)');
});

var getUserData = function(id,callback){
    console.log('::getUserData::',id);
    controller.storage.users.get(id, function(err, user) {
        if (user && user.name) {
            if(callback){
              callback(user);
            }else{
              return user;
            }
        } else {
          bot.api.users.info({user: id},function(err,response) {
              if(response.user){
                  // console.log('::userdata::',response.user);
                  controller.storage.users.save({
                    id: id,
                    name:response.user.name,
                    email: response.user.profile.email
                  }, function(err) {
                    bot.botkit.log('user-stored',response.user.name);
                  });
                  // console.log('::gotUserName::',response.user.name);
                  if(callback){
                    callback(response.user); //TODO change this to return the user object
                  }else{
                      return response.user;
                  }
              }
          });
        }
    });
}

var getAllUsers = function(){
  controller.storage.users.all(function(err, all_user_data) {
    if(err){
      bot.botkit.log('::ERROR::',err);
    }
    console.log('::userdata::',all_user_data);
  });
}

var AskGameType = function(convo){
{'fraction_non_alphanumeric': 0.15862728431789205, 'fraction_numerical': 0.0016999575010624734, 'mean_word_length': 2.467034990791897, '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': '28226', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2778, 'n_words': 553}