diff --git a/scripts/ooto.coffee b/scripts/ooto.coffee index 1dbb8e1..4c3920d 100644 --- a/scripts/ooto.coffee +++ b/scripts/ooto.coffee @@ -8,13 +8,16 @@ # None # # Commands: -# ooto list - lists everyone who's ooto -# ooto add - sets you as ooto -# ooto edit - changes away msg -# ooto back - sets you as back from ooto -# ooto mymsgs - checks all your away msgs (if you're listed as ooto) -# ooto msg - sends msg to user if they're away -# ooto help - shows this help +# hubot ooto list - lists everyone who's ooto +# hubot ooto add - sets you as ooto +# hubot ooto edit - changes away msg +# hubot ooto back - sets you as back from ooto +# hubot ooto mymsgs - checks all your away msgs (if you're listed as ooto) +# hubot ooto msg - sends msg to user if they're away +# hubot ooto help - shows this help +# +# Author: +# flybycai class UserOOTO constructor: (@user, @awayMsg) -> @@ -37,10 +40,11 @@ module.exports = (robot) -> printUserMessages = (user, msg) -> if usersAway[user].getUserMessages().length == 0 - msg.reply "You have not received any messages :(" + msg = msg + "You have not received any messages :(" else for m in usersAway[user].getUserMessages() - msg.reply m["user"] + " says: " + m["message"] + msg = msg + m["user"] + " says: " + m["message"] + "\n" + return msg robot.respond /ooto (\S+) (.*\S.*)/i, (msg) -> currentUser = msg.message.user.name.toLowerCase() @@ -50,8 +54,8 @@ module.exports = (robot) -> when "add" if usersAway[currentUser] msg.reply "You are already marked as OOTO. To change your ooto msg, use " + - "'ooto edit '. To see messages left to you, use " + - "'ooto mymsgs'. To mark yourself as back from ooto, use 'ooto back'." + "'grbot ooto edit '. To see messages left to you, use " + + "'grbot ooto mymsgs'. To mark yourself as back from ooto, use 'grbot ooto back'." else usersAway[currentUser] = new UserOOTO currentUser, awayMsg msg.reply "You are now marked as OOTO with the message: " + awayMsg @@ -60,44 +64,42 @@ module.exports = (robot) -> usersAway[currentUser].setMessage awayMsg msg.reply "Your OOTO message has been updated: " + awayMsg else - msg.reply "You are not OOTO! To add a new OOTO message, use 'ooto add '" + msg.reply "You are not OOTO! To add a new OOTO message, use 'grbot ooto add '" robot.respond /ooto (\S+)/i, (msg) -> currentUser = msg.message.user.name.toLowerCase() cmd = msg.match[1] switch cmd when "list" - msg.reply "All OOTO users and their away messages:" if Object.keys(usersAway).length == 0 - msg.reply "Nobody is OOTO!" + msg.send "Nobody is OOTO!" else for user, ooto of usersAway - msg.reply user + ": " + ooto.getMessage() + msg.send user + ": " + ooto.getMessage() when "back" if usersAway[currentUser] - msg.reply "Welcome back! Here are all the messages you received while you were ooto:" - printUserMessages currentUser, msg + returnMsg = printUserMessages currentUser, "Welcome back! Here are all the messages you received while you were ooto:\n" + msg.send returnMsg delete usersAway[currentUser] - msg.reply "You have now been removed as OOTO." else - msg.reply "You are not marked as OOTO! To add a new OOTO message, use 'ooto add '" + msg.reply "You are not marked as OOTO! To add a new OOTO message, use 'grbot ooto add '" when "mymsgs" if usersAway[currentUser] - msg.reply "All messages received while you were ooto:" - printUserMessages currentUser, msg + returnMsg = printUserMessages currentUser, "" + msg.send returnMsg else - msg.reply "You are not marked as OOTO! To add a new OOTO message, use 'ooto add '" + msg.reply "You are not marked as OOTO! To add a new OOTO message, use 'grbot ooto add '" when "help" helpMsg = """ - ooto add - sets you as ooto - ooto edit - changes your ooto msg - ooto back - sets you as back from ooto - ooto mymsgs - checks all your away msgs (if you're listed as ooto) - ooto msg - sends msg to user if they're away - ooto list - lists everyone who's ooto - ooto help - shows this help + grbot ooto add - sets you as ooto + grbot ooto edit - changes your ooto msg + grbot ooto back - sets you as back from ooto + grbot ooto mymsgs - checks all your away msgs (if you're listed as ooto) + grbot ooto msg - sends msg to user if they're ooto + grbot ooto list - lists everyone who's ooto + grbot ooto help - shows this help """ - msg.reply helpMsg + msg.send helpMsg robot.respond /ooto msg (\S+) (.*\S.*)/i, (msg) -> currentUser = msg.message.user.name.toLowerCase() @@ -105,7 +107,13 @@ module.exports = (robot) -> message = msg.match[2] if usersAway[user] usersAway[user].addUserMessage currentUser, message - msg.reply "Your message to " + user + " has been recorded: " + message + msg.send "Your message to " + user + " has been recorded: " + message else - msg.reply "No user found who is OOTO with that name! To see a list of all OOTO users, " + - "use 'ooto list'" \ No newline at end of file + msg.send "No user found who is OOTO with that name! To see a list of all OOTO users, " + + "use 'grbot ooto list'" + + robot.hear /@(\S+)/, (msg) -> + user = msg.match[1].toLowerCase() + if usersAway[user] + msg.send user + " is currently ooto (reason: " + usersAway[user].getMessage() + + "). You can leave them a message using 'grbot ooto msg " + user + " '" \ No newline at end of file