Skip to content

Instantly share code, notes, and snippets.

@michikono
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michikono/bfe0932f42984da4546d to your computer and use it in GitHub Desktop.
Save michikono/bfe0932f42984da4546d to your computer and use it in GitHub Desktop.
Hubot Script for Making Hard Decisions
# 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