<commit_before>'use strict';

const logger = require('../logger');
const config = require('../../config/lib/helpers/macro');

/**
 * @return {String}
 */
function getMacroForKey(key) {
  if (!config.macros[key]) {
    return null;
  }
  return config.macros[key].name;
}

/**
 * @param {String} macroName
 * @return {Object}
 */
function getProfileUpdate(macroName) {
  const macro = config.macros[macroName];
  const payload = {};
  if (!macro || !macro.profileUpdate) {
    return payload;
  }
  payload[macro.profileUpdate.field] = macro.profileUpdate.value;
  return payload;
}

/**
 * @param {String} macroName
 * @return {Boolean}
 */
function isCompletedVotingPlan(macroName) {
  return macroName && macroName.includes(config.completedVotingPlanMacro);
}

/**
 * @param {String} macroName
 * @return {Boolean}
 */
function isSaidNo(macroName) {
  return (macroName === module.exports.macros.saidNo());
}

/**
 * @param {String} macroName
 * @return {Boolean}
 */
function isSaidYes(macroName) {
  return (macroName === module.exports.macros.saidYes());
}

function getMacro(macroName) {
  return config.macros[macroName];
}

/**
 * Is given string a Rivescript macro?
 * @param {String} text
 * @return {Boolean}
 */
function isMacro(text) {
  const result = !!getMacroForKey(text);
  logger.debug('macro.isMacro', { text, result });
  return result;
}

module.exports = {
  getMacro,
  getProfileUpdate,
  isCompletedVotingPlan,
  isMacro,
  isSaidNo,
  isSaidYes,
  macros: {
    invalidAskMultipleChoiceResponse: () => getMacroForKey('invalidAskMultipleChoiceResponse'),
    invalidAskVotingPlanStatusResponse: () => getMacroForKey('invalidAskVotingPlanStatusResponse'),
    saidFirstChoice: () => getMacroForKey('saidFirstChoice'),
    saidNo: () => getMacroForKey('saidNo'),
    saidSecondChoice: () => getMacroForKey('saidSecondChoice'),
    saidThirdChoice: () => getMacroForKey('saidThirdChoice'),
    saidFourthChoice: () => getMacroForKey('saidFourthChoice'),
    saidFifthChoice: () => getMacroForKey('saidFifthChoice'),
    saidYes: () => getMacroForKey('saidYes'),
    subscriptionStatusActive: () => getMacroForKey('subscriptionStatusActive'),
    subscriptionStatusLess: () => getMacroForKey('subscriptionStatusLess'),
    subscriptionStatusNeedMoreInfo: () => getMacroForKey('subscriptionStatusNeedMoreInfo'),
    subscriptionStatusStop: () => getMacroForKey('subscriptionStatusStop'),
    votingPlanStatusCantVote: () => getMacroForKey('votingPlanStatusCantVote'),
    votingPlanStatusNotVoting: () => getMacroForKey('votingPlanStatusNotVoting'),
    votingPlanStatusVoted: () => getMacroForKey('votingPlanStatusVoted'),
    votingPlanStatusVoting: () => getMacroForKey('votingPlanStatusVoting'),
  },
};
<commit_msg>chore: updating order or macros per https://github.com/DoSomething/gambit/pull/490#discussion_r269793356<commit_after>'use strict';

const logger = require('../logger');
const config = require('../../config/lib/helpers/macro');

/**
 * @return {String}
 */
function getMacroForKey(key) {
  if (!config.macros[key]) {
    return null;
  }
  return config.macros[key].name;
}

/**
 * @param {String} macroName
 * @return {Object}
 */
function getProfileUpdate(macroName) {
  const macro = config.macros[macroName];
  const payload = {};
  if (!macro || !macro.profileUpdate) {
    return payload;
  }
  payload[macro.profileUpdate.field] = macro.profileUpdate.value;
  return payload;
}

/**
 * @param {String} macroName
 * @return {Boolean}
 */
function isCompletedVotingPlan(macroName) {
  return macroName && macroName.includes(config.completedVotingPlanMacro);
}

/**
 * @param {String} macroName
 * @return {Boolean}
 */
function isSaidNo(macroName) {
  return (macroName === module.exports.macros.saidNo());
}

/**
 * @param {String} macroName
 * @return {Boolean}
 */
function isSaidYes(macroName) {
  return (macroName === module.exports.macros.saidYes());
}

function getMacro(macroName) {
  return config.macros[macroName];
}

/**
 * Is given string a Rivescript macro?
 * @param {String} text
 * @return {Boolean}
 */
function isMacro(text) {
  const result = !!getMacroForKey(text);
  logger.debug('macro.isMacro', { text, result });
  return result;
}

module.exports = {
  getMacro,
  getProfileUpdate,
  isCompletedVotingPlan,
  isMacro,
  isSaidNo,
  isSaidYes,
  macros: {
    invalidAskMultipleChoiceResponse: () => getMacroForKey('invalidAskMultipleChoiceResponse'),
    invalidAskVotingPlanStatusResponse: () => getMacroForKey('invalidAskVotingPlanStatusResponse'),
    saidFirstChoice: () => getMacroForKey('saidFirstChoice'),
    saidSecondChoice: () => getMacroForKey('saidSecondChoice'),
    saidThirdChoice: () => getMacroForKey('saidThirdChoice'),
    saidFourthChoice: () => getMacroForKey('saidFourthChoice'),
    saidFifthChoice: () => getMacroForKey('saidFifthChoice'),
    saidNo: () => getMacroForKey('saidNo'),
    saidYes: () => getMacroForKey('saidYes'),
    subscriptionStatusActive: () => getMacroForKey('subscriptionStatusActive'),
    subscriptionStatusLess: () => getMacroForKey('subscriptionStatusLess'),
    subscriptionStatusNeedMoreInfo: () => getMacroForKey('subscriptionStatusNeedMoreInfo'),
    subscriptionStatusStop: () => getMacroForKey('subscriptionStatusStop'),
    votingPlanStatusCantVote: () => getMacroForKey('votingPlanStatusCantVote'),
    votingPlanStatusNotVoting: () => getMacroForKey('votingPlanStatusNotVoting'),
    votingPlanStatusVoted: () => getMacroForKey('votingPlanStatusVoted'),
    votingPlanStatusVoting: () => getMacroForKey('votingPlanStatusVoting'),
  },
};

{'fraction_non_alphanumeric': 0.14965009869011303, 'fraction_numerical': 0.002153238830073569, 'mean_word_length': 5.436489607390301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 1, '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': '1960412', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1765, 'n_words': 278}