<commit_before>var Botkit = require('./node_modules/botkit/lib/Botkit.js');

if (!process.env.clientId || !process.env.clientSecret || !process.env.port) {
  console.log('Error: Specify clientId clientSecret and port in environment');
  process.exit(1);
}


var controller = Botkit.slackbot({
  json_file_store: './db_slackbutton_bot/', interactive_replies: true,
}).configureSlackApp(
  {
    clientId: process.env.clientId,
    clientSecret: process.env.clientSecret,
    redirectUri: 'http://localhost:3002',
    scopes: ['bot', 'commands'],
  }
);

controller.setupWebserver(process.env.port,function(err,webserver) {
  controller.createWebhookEndpoints(controller.webserver);
  controller.createHomepageEndpoint(controller.webserver);
  controller.createOauthEndpoints(controller.webserver,function(err,req,res) {
    if (err) {
      res.status(500).send('ERROR: ' + err);
    } else {
      res.send('Success!');
    }
  });
});


// just a simple way to make sure we don't
// connect to the RTM twice for the same team
var _bots = {};
function trackBot(bot) {
  _bots[bot.config.token] = bot;
}

controller.storage.teams.all(function(err,teams) {

  if (err) {
    throw new Error(err);
  }

  // connect all teams with bots up to slack!
  for (var t  in teams) {
    if (teams[t].bot) {
      controller.spawn(teams[t]).startRTM(function(err, bot) {
        if (err) {
          console.log('Error connecting bot to Slack:',err);
        } else {
          trackBot(bot);
        }
      });
    }
  }

});


controller.hears(['movie (.*)'], ['ambient,message_received'], function(bot, message) {
  var movie_search_title = message.match[1];
  var request = require("request");
  var url = "https://api.themoviedb.org/3/search/movie?api_key=87a3acc12bd88c311e7dcc9c41542560&query=" +movie_search_title+ "";

  request({ url: url, json: true }, function (error, response, body) {
    var movies = body.results;

    if (movies.length === 1) {
      var movie_text = generate_movie_text(movies[0]);
      bot.reply(message, movie_text);
    }else {
      bot.reply(message, 'worked');
    }
  });
});

function generate_movie_text(title){
  return title.title<commit_msg>Generate_buttons working<commit_after>var Botkit = require('./node_modules/botkit/lib/Botkit.js');

if (!process.env.clientId || !process.env.clientSecret || !process.env.port) {
  console.log('Error: Specify clientId clientSecret and port in environment');
  process.exit(1);
}


var controller = Botkit.slackbot({
  json_file_store: './db_slackbutton_bot/', interactive_replies: true,
}).configureSlackApp(
  {
    clientId: process.env.clientId,
    clientSecret: process.env.clientSecret,
    redirectUri: 'http://localhost:3002',
    scopes: ['bot', 'commands'],
  }
);

controller.setupWebserver(process.env.port,function(err,webserver) {
  controller.createWebhookEndpoints(controller.webserver);
  controller.createHomepageEndpoint(controller.webserver);
  controller.createOauthEndpoints(controller.webserver,function(err,req,res) {
    if (err) {
      res.status(500).send('ERROR: ' + err);
    } else {
      res.send('Success!');
    }
  });
});


// just a simple way to make sure we don't
// connect to the RTM twice for the same team
var _bots = {};
function trackBot(bot) {
  _bots[bot.config.token] = bot;
}

controller.storage.teams.all(function(err,teams) {

  if (err) {
    throw new Error(err);
  }

  // connect all teams with bots up to slack!
  for (var t  in teams) {
    if (teams[t].bot) {
      controller.spawn(teams[t]).startRTM(function(err, bot) {
        if (err) {
          console.log('Error connecting bot to Slack:',err);
        } else {
          trackBot(bot);
        }
      });
    }
  }

});


controller.hears(['movie (.*)'], ['ambient,message_received'], function(bot, message) {
  var movie_search_title = message.match[1];
  var request = require("request");
  var url = "https://api.themoviedb.org/3/search/movie?api_key=87a3acc12bd88c311e7dcc9c41542560&query=" +movie_search_title+ "";

  request({ url: url, json: true }, function (error, response, body) {
    var movies = body.results;

    if (movies.length === 1) {
      var movie_text = generate_movie_text(movies[0]);
      bot.reply(message, movie_text);
    }else {
      generate_buttons(movies.length, movies);

    }
  });
});

function generate_buttons(length, movies){
  for(var i = 0; i<length;i++){
    var movie_buttons = [];
    movie_buttons.push(
    {
      "name":i,
      "text": movies[i].title,
      "value": i,
      "type": "button"
    });
  }
}

function generate_movie_text(title){
  return title.title
{'fraction_non_alphanumeric': 0.15406283856988082, 'fraction_numerical': 0.014084507042253521, 'mean_word_length': 3.616, 'pattern_counts': {'":': 4, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '784760', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1547, 'n_words': 297}