Last active
December 12, 2015 03:38
-
-
Save xhochy/4708225 to your computer and use it in GitHub Desktop.
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: | |
# Tell Hubot to send a user a message when present in the room | |
# | |
# Dependencies: | |
# None | |
# | |
# Configuration: | |
# None | |
# | |
# Commands: | |
# hubot tell <username> <some message> - tell <username> <some message> next time they are present | |
# | |
# Author: | |
# christianchristensen, lorenzhs | |
module.exports = (robot) -> | |
localstorage = {} | |
robot.respond /tell ([\w.-]*) (.*)/i, (msg) -> | |
datetime = new Date() | |
username = msg.match[1].toLowerCase() | |
room = msg.message.user.room | |
tellmessage = username + ": " + msg.message.user.name + " @ " + datetime.toLocaleString() + " said: " + msg.match[2] + "\r\n" | |
if localstorage[username]? | |
if localstorage[username][room]? | |
localstorage[username][room] += tellmessage | |
else | |
localstorage[username][room] = tellmessage | |
else | |
localstorage[username] = {} | |
localstorage[username][room] = tellmessage | |
return | |
robot.enter (msg) -> | |
# just send the messages if they are available... | |
username = msg.message.user.name.toLowerCase() | |
room = msg.message.user.room | |
if localstorage[username]? and localstorage[username][room]? | |
tellmessage = localstorage[username][room] | |
delete localstorage[username][room] | |
msg.send tellmessage | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment