From 0a02bc6e515082d1b77102e1c818338c4bd08fa7 Mon Sep 17 00:00:00 2001 From: Jamie Cai Date: Tue, 16 Dec 2014 14:18:00 -0800 Subject: [PATCH 1/2] Changed some msg.reply's to msg.send's to avoid name confusion. Added clearer documentation. Added support for whenever someone @'s a user, grbot will check if they are away, and if they are, say so in the channel --- scripts/ooto.coffee | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/scripts/ooto.coffee b/scripts/ooto.coffee index 1dbb8e1..c510852 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,10 @@ module.exports = (robot) -> printUserMessages = (user, msg) -> if usersAway[user].getUserMessages().length == 0 - msg.reply "You have not received any messages :(" + msg.send "You have not received any messages :(" else for m in usersAway[user].getUserMessages() - msg.reply m["user"] + " says: " + m["message"] + msg.send m["user"] + " says: " + m["message"] robot.respond /ooto (\S+) (.*\S.*)/i, (msg) -> currentUser = msg.message.user.name.toLowerCase() @@ -67,12 +70,12 @@ module.exports = (robot) -> cmd = msg.match[1] switch cmd when "list" - msg.reply "All OOTO users and their away messages:" + msg.send "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:" @@ -83,21 +86,21 @@ module.exports = (robot) -> msg.reply "You are not marked as OOTO! To add a new OOTO message, use 'ooto add '" when "mymsgs" if usersAway[currentUser] - msg.reply "All messages received while you were ooto:" + msg.send "All messages received while you were ooto:" printUserMessages currentUser, msg else msg.reply "You are not marked as OOTO! To add a new OOTO message, use '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 away + 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 +108,12 @@ 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 'ooto list'" + + robot.hear /@(\S+)/, (msg) -> + user = msg.match[1].toLowerCase() + if usersAway[user] + msg.send user + " is currently ooto! You can leave them a message using 'ooto msg " + user + " '" \ No newline at end of file From 37cf45c37344837aefec4fff7773ce405e235cd9 Mon Sep 17 00:00:00 2001 From: Jamie Cai Date: Tue, 16 Dec 2014 16:00:42 -0800 Subject: [PATCH 2/2] Updates to ooto script: removed some extra lines of text, fixed text appearing out of order --- scripts/ooto.coffee | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/ooto.coffee b/scripts/ooto.coffee index c510852..4c3920d 100644 --- a/scripts/ooto.coffee +++ b/scripts/ooto.coffee @@ -40,10 +40,11 @@ module.exports = (robot) -> printUserMessages = (user, msg) -> if usersAway[user].getUserMessages().length == 0 - msg.send "You have not received any messages :(" + msg = msg + "You have not received any messages :(" else for m in usersAway[user].getUserMessages() - msg.send 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() @@ -53,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 @@ -63,40 +64,38 @@ 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.send "All OOTO users and their away messages:" if Object.keys(usersAway).length == 0 - msg.send "Nobody is OOTO!" + msg.send "Nobody is OOTO!" else for user, ooto of usersAway 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.send "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 = """ 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 away + 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 """ @@ -111,9 +110,10 @@ module.exports = (robot) -> msg.send "Your message to " + user + " has been recorded: " + message else msg.send "No user found who is OOTO with that name! To see a list of all OOTO users, " + - "use 'ooto list'" + "use 'grbot ooto list'" robot.hear /@(\S+)/, (msg) -> user = msg.match[1].toLowerCase() if usersAway[user] - msg.send user + " is currently ooto! You can leave them a message using 'ooto msg " + user + " '" \ No newline at end of file + 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