lib/flint.js
function runActions(matched, bot, trigger, id) {
          // process preference logic
          if(matched.length > 1) {
            matched = _.sortBy(matched, match => match.preference);
            var prefLow = matched[0].preference;
            var prefHigh = matched[matched.length - 1].preference;

            if(prefLow !== prefHigh) {
              matched = _.filter(matched, match => (match.preference === prefLow));
            }
          }

          _.forEach(matched, lex => {
            // for regex
            if(lex.phrase instanceof RegExp && typeof lex.action === 'function') {
              // define trigger.args, trigger.phrase
              trigger.args = trigger.text.split(' ');
              trigger.phrase = lex.phrase;

              // run action
              lex.action(bot, trigger, id);
              return true;
            }

            // for string
            else if (typeof lex.phrase === 'string' && typeof lex.action === 'function') {
              // find index of match
              var args = _.toLower(trigger.text).split(' ');
              var indexOfMatch = args.indexOf(lex.phrase) !== -1 ? args.indexOf(lex.phrase) : 0;

              // define trigger.args, trigger.phrase
              trigger.args = trigger.text.split(' ');
              trigger.args = trigger.args.slice(indexOfMatch, trigger.args.length);
              trigger.phrase = lex.phrase;

              // run action
              lex.action(bot, trigger, id);
              return true;
            }

            // for nothing...
            else {
              return false;
            }
          });
        }
function runActions(matched, bot, trigger, id) {
          // process preference logic
          if(matched.length > 1) {
            matched = _.sortBy(matched, match => match.preference);
            var prefLow = matched[0].preference;
            var prefHigh = matched[matched.length - 1].preference;

            if(prefLow !== prefHigh) {
              matched = _.filter(matched, match => (match.preference === prefLow));
            }
          }

          _.forEach(matched, lex => {
            // for regex
            if(lex.phrase instanceof RegExp && typeof lex.action === 'function') {
              // define trigger.args, trigger.phrase
              trigger.args = trigger.text.split(' ');
              trigger.phrase = lex.phrase;

              // run action
              lex.action(bot, trigger, id);
              return true;
            }

            // for string
            else if (typeof lex.phrase === 'string' && typeof lex.action === 'function') {
              // find index of match
              var args = _.toLower(trigger.text).split(' ');
              var indexOfMatch = args.indexOf(lex.phrase) !== -1 ? args.indexOf(lex.phrase) : 0;

              // define trigger.args, trigger.phrase
              trigger.args = trigger.text.split(' ');
              trigger.args = trigger.args.slice(indexOfMatch, trigger.args.length);
              trigger.phrase = lex.phrase;

              // run action
              lex.action(bot, trigger, id);
              return true;
            }

            // for nothing...
            else {
              return false;
            }
          });
        }
function runActions ( matched , bot , trigger , id ) { // process preference logic if ( matched . length > 1 ) { matched = _ . sortBy ( matched , match => match . preference ) ; var prefLow = matched [ 0 ] . preference ; var prefHigh = matched [ matched . length - 1 ] . preference ; if ( prefLow !== prefHigh ) { matched = _ . filter ( matched , match => ( match . preference === prefLow ) ) ; } } _ . forEach ( matched , lex => { // for regex if ( lex . phrase instanceof RegExp && typeof lex . action === 'function' ) { // define trigger.args, trigger.phrase trigger . args = trigger . text . split ( ' ' ) ; trigger . phrase = lex . phrase ; // run action lex . action ( bot , trigger , id ) ; return true ; } // for string else if ( typeof lex . phrase === 'string' && typeof lex . action === 'function' ) { // find index of match var args = _ . toLower ( trigger . text ) . split ( ' ' ) ; var indexOfMatch = args . indexOf ( lex . phrase ) !== - 1 ? args . indexOf ( lex . phrase ) : 0 ; // define trigger.args, trigger.phrase trigger . args = trigger . text . split ( ' ' ) ; trigger . args = trigger . args . slice ( indexOfMatch , trigger . args . length ) ; trigger . phrase = lex . phrase ; // run action lex . action ( bot , trigger , id ) ; return true ; } // for nothing... else { return false ; } } ) ; }
function to run the action
function to run the action