<commit_before>/*
  Many thanks to https://github.com/howdyai/botkit/blob/master/slack_bot.js
  Where most of this was stolen from
*/

const excuse = require('huh');
const os = require('os');

const hi = (bot, message) => {
  bot.api.reactions.add({
    timestamp: message.ts,
    channel: message.channel,
    name: 'robot_face',
  }, function(err) {
    if (err) {
      bot.botkit.log('Failed to add emoji reaction :(', err);
    }
  });
  bot.storage.users.get(message.user, function(err, user) {
    if (user && user.name) {
      bot.reply(message, 'Hello ' + user.name + '!!');
    } else {
      bot.reply(message, 'Hello.');
    }
  });
};

const shutdown = (bot, message) => {
  bot.startConversation(message, function(err, convo) {
    convo.ask('Are you sure you want me to shutdown?', [
      {
        pattern: bot.utterances.yes,
        callback: function(response, convo) {
          convo.say("Alright Sir, if you'll not be needing me, I'll close down for awhile");
          convo.next();
          setTimeout(function() {
            process.exit();
          }, 3000);
        }
      },
      {
        pattern: bot.utterances.no,
        default: true,
        callback: function(response, convo) {
          convo.say('*ZORGBORT LIVES!*');
          convo.next();
        }
      }
    ]);
  });
};

const uptime = (bot, message) => {
  let formatUptime = function(uptime) {
    var unit = 'second';
    if (uptime > 60) {
      uptime = uptime / 60;
      unit = 'minute';
    }
    if (uptime > 60) {
      uptime = uptime / 60;
      unit = 'hour';
    }
    if (uptime != 1) {
      unit = unit + 's';
    }

    uptime = uptime + ' ' + unit;
    return uptime;
  };
  const hostname = os.hostname();
  const uptime = formatUptime(process.uptime());
  const reponse = ':robot_face: I am a bot named <@' + bot.identity.name +
          '>. I have been running for ' + uptime + ' on ' + hostname + '.';
  bot.reply(message, reponse);
};

const defaultExcuse = (bot, message) => {
  let msg = message.text;
  let reason = excuse.get('en');
  bot.reply(message, `Sorry, I don't know how to _${msg}_. It must be *${reason}!*`);
};

module.exports = bot => {
  bot.hears(['hello', 'hi', 'howdy', 'sup', 'howzit'], hi);
  bot.hears(['shutdown', 'powerdown'], shutdown);
  bot.hears(['uptime', 'identify yourself', 'who are you', 'what is your name'], uptime);
  bot.hears('','direct_message,direct_mention,mention', defaultExcuse);
};<commit_msg>Listen to the right type of messages<commit_after>/*
  Many thanks to https://github.com/howdyai/botkit/blob/master/slack_bot.js
  Where most of this was stolen from
*/

const excuse = require('huh');
const os = require('os');

const hi = (bot, message) => {
  bot.api.reactions.add({
    timestamp: message.ts,
    channel: message.channel,
    name: 'robot_face',
  }, function(err) {
    if (err) {
      bot.botkit.log('Failed to add emoji reaction :(', err);
    }
  });
  bot.storage.users.get(message.user, function(err, user) {
    if (user && user.name) {
      bot.reply(message, 'Hello ' + user.name + '!!');
    } else {
      bot.reply(message, 'Hello.');
    }
  });
};

const shutdown = (bot, message) => {
  bot.startConversation(message, function(err, convo) {
    convo.ask('Are you sure you want me to shutdown?', [
      {
        pattern: bot.utterances.yes,
        callback: function(response, convo) {
          convo.say("Al<NAME>ir, if you'll not be needing me, I'll close down for awhile");
          convo.next();
          setTimeout(function() {
            process.exit();
          }, 3000);
        }
      },
      {
        pattern: bot.utterances.no,
        default: true,
        callback: function(response, convo) {
          convo.say('*ZORGBORT LIVES!*');
          convo.next();
        }
      }
    ]);
  });
};

const uptime = (bot, message) => {
  let formatUptime = function(uptime) {
    var unit = 'second';
    if (uptime > 60) {
      uptime = uptime / 60;
      unit = 'minute';
    }
    if (uptime > 60) {
      uptime = uptime / 60;
      unit = 'hour';
    }
    if (uptime != 1) {
      unit = unit + 's';
    }

    uptime = uptime + ' ' + unit;
    return uptime;
  };
  const hostname = os.hostname();
  const uptime = formatUptime(process.uptime());
  const reponse = ':robot_face: I am a bot named <@' + bot.identity.name +
          '>. I have been running for ' + uptime + ' on ' + hostname + '.';
  bot.reply(message, reponse);
};

const defaultExcuse = (bot, message) => {
  let msg = message.text;
  let reason = excuse.get('en');
  bot.reply(message, `Sorry, I don't know how to _${msg}_. It must be *${reason}!*`);
};

const mention = ['direct_message','direct_mention','mention'];
module.exports = bot => {
  bot.hears(['hello', 'hi', 'howdy', 'sup', 'howzit'], mention, hi);
  bot.hears(['shutdown', 'powerdown'], mention, shutdown);
  bot.hears(['uptime', 'identify yourself', 'who are you', 'what is your name'], mention, uptime);
  bot.hears('','', mention, defaultExcuse);
};
{'fraction_non_alphanumeric': 0.1725787166201674, 'fraction_numerical': 0.0051813471502590676, 'mean_word_length': 2.579885877318117, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 20, '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': '1958614', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1697, 'n_words': 422}