Last active
August 29, 2015 14:08
-
-
Save michikono/bfe0932f42984da4546d to your computer and use it in GitHub Desktop.
Hubot Script for Making Hard Decisions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Decides between two or more options at random. Now Spanish compatible! | |
# | |
# Commands: | |
# decide|choose|pick( between)(:) <option 1> and|or <option 2> (and|or <option #> ...) | |
# escoger|elegir|seleccionar|decidir( entre)(:) <opción 1> y|o <opción 2> (y|o <opción #> ...) | |
# | |
# Author: | |
# Michi Kono | |
module.exports = (robot) -> | |
spanishPhrase = ['escoger','elegir','seleccionar','decidir'] | |
robot.hear new RegExp('((' + spanishPhrase.join('|') + '|decide|choose|pick)\\s*(between|entre)?:?)\\s+(.+\\s+(or|and|o|y)\\s+.*?$)', 'i'), (msg) -> | |
isSpanish = if spanishPhrase.indexOf(msg.match[2]) != -1 then isSpanish = true | |
msg.send (if isSpanish then 'Vamos a ' + msg.match[2] + ' ' else 'Let\'s go with ') + msg.random( | |
msg.match[4].split(' ' + msg.match[5] + ' ').map( | |
# trim and strip special trailing/starting characters | |
(s) -> s.replace(/^\s+|\s+$/g, '').replace(/\b[^\w]+$|^[^\w]+\b/i, '') | |
).filter((x) -> !!x) # filter empty choices | |
) + (if isSpanish then ' che' else '') + '!' # make it friendly! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment