Skip to content
This repository
file 44 lines (41 sloc) 1.529 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
# 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. Case-Insensitive prefix matching is employed when matching usernames, so "foo" also matches "Foo" and "foooo"
#
# Author:
# christianchristensen, lorenzhs, xhochy

module.exports = (robot) ->
   localstorage = {}
   robot.respond /tell ([\w.-]*):? (.*)/i, (msg) ->
     datetime = new Date()
     username = msg.match[1]
     room = msg.message.user.room
     tellmessage = msg.message.user.name + " @ " + datetime.toLocaleString() + " said: " + msg.match[2] + "\r\n"
     if not localstorage[room]?
       localstorage[room] = {}
     if localstorage[room][username]?
       localstorage[room][username] += tellmessage
     else
       localstorage[room][username] = tellmessage
     msg.send "Ok, I'll tell #{username} you said '#{msg.match[2]}'."
     return
 
   # When a user enters, check if someone left them a message
   robot.enter (msg) ->
     username = msg.message.user.name
     room = msg.message.user.room
     if localstorage[room]?
       for recipient, message of localstorage[room]
         # Check if the recipient matches username
         if username.match(new RegExp "^"+recipient, "i")
           tellmessage = username + ": " + localstorage[room][recipient]
           delete localstorage[room][recipient]
           msg.send tellmessage
     return
Something went wrong with that request. Please try again.