Skip to content

Instantly share code, notes, and snippets.

@xhochy
Last active December 12, 2015 03:38
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 xhochy/4708225 to your computer and use it in GitHub Desktop.
Save xhochy/4708225 to your computer and use it in GitHub Desktop.
# 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