Skip to content

Instantly share code, notes, and snippets.

@irfanfadilah
Created November 30, 2015 08:03
Show Gist options
  • Save irfanfadilah/2c46208eb4dcb2f03d05 to your computer and use it in GitHub Desktop.
Save irfanfadilah/2c46208eb4dcb2f03d05 to your computer and use it in GitHub Desktop.
[Sample Code] Hubot Brains Storage (Slack Adapter)
robot.respond /accumulate this request to my account/i, (msg) ->
user_id = msg.message.user.id; user_name = msg.message.user.name
requests = robot.brain.get(user_id)
if requests == null
robot.brain.set(user_id, 1)
else
robot.brain.set(user_id, requests+1)
requests = robot.brain.get(user_id)
content = if requests > 5
# User exceed limit
"<@#{user_name}>, you exceeded request limit today, please try again tomorrow.
else
# Some action here
"Counter: #{requests}"
msg.send content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment