Created
November 30, 2015 08:03
-
-
Save irfanfadilah/2c46208eb4dcb2f03d05 to your computer and use it in GitHub Desktop.
[Sample Code] Hubot Brains Storage (Slack Adapter)
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
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