"use strict";

const gutiBot = require('./gutiBot');
const slack = require('./utils/slackUtils');
const strUtils = require('./utils/stringUtils');

function getMatches(str) {
  const pattern = /(\w{2,}er)[^\w]+|(\w{2,}er)$/gi;

  return str.match(pattern) || [];
}

function cleanMatches(matches) {
  const pattern = /[^\w]+$/;

  return matches.map(str => {
    return str.replace(pattern, "");
  });
}

function splitByEr(word) {
  return strUtils.splitWord(word, "er");
}

function formatSplitWordParts(parts) {
  const capFirst = strUtils.capitalizeFirstCharacter;

  return `${capFirst(parts[0])} '${parts[1]}`;
}

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}

function isTwentyFivePercentChance() {
  return getRandomInt(0, 4) === 0;
}

function shouldRespond(username, matches) {
  return username !== 'slackbot'
    && matches.length !== 0
    && isTwentyFivePercentChance();
}

function bot(req, res) {
  const text = req.body.text;
  const username = req.body.user_name;
  const matches = cleanMatches(getMatches(text));
  const linkify = strUtils.linkifySlackUsername;

  if (!shouldRespond(username, matches)) {
    return gutiBot.respondOk(res);
  }

  const blankEr = matches
    .map(splitByEr)
    .map(formatSplitWordParts)
    .join(" ");

  const message = `${linkify(username)}: ${blankEr}?! I barely know 'er!`;

  return gutiBot.respondWith(res, message);
}

module.exports = {
  getMatches,
  bot,
};

@@ -268,16 +268,17 @@
 unction 
+_
 cleanMat
@@ -408,16 +408,17 @@
 unction 
+_
 splitByE
@@ -480,16 +480,17 @@
 unction 
+_
 formatSp
@@ -625,16 +625,17 @@
 unction 
+_
 getRando
@@ -719,16 +719,17 @@
 unction 
+_
 isTwenty
@@ -759,16 +759,17 @@
  return 
+_
 getRando
@@ -798,16 +798,17 @@
 unction 
+_
 shouldRe
@@ -902,16 +902,17 @@
 %0A    && 
+_
 isTwenty
@@ -1047,16 +1047,17 @@
 tches = 
+_
 cleanMat
@@ -1137,16 +1137,17 @@
 %0A  if (!
+_
 shouldRe
@@ -1249,16 +1249,17 @@
    .map(
+_
 splitByE
@@ -1270,16 +1270,17 @@
    .map(
+_
 formatSp

Prepend underscores to non-exported function names