Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions scripts/ooto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
# None
#
# Commands:
# ooto list - lists everyone who's ooto
# ooto add <msg> - sets you as ooto
# ooto edit <msg> - 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 <user> <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 <msg> - sets you as ooto
# hubot ooto edit <msg> - 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 <user> <msg> - sends msg to user if they're away
# hubot ooto help - shows this help
#
# Author:
# flybycai

class UserOOTO
constructor: (@user, @awayMsg) ->
Expand All @@ -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()
Expand All @@ -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 <new msg>'. To see messages left to you, use " +
"'ooto mymsgs'. To mark yourself as back from ooto, use 'ooto back'."
"'grbot ooto edit <new msg>'. 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
Expand All @@ -60,52 +64,56 @@ 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>'"
msg.reply "You are not OOTO! To add a new OOTO message, use 'grbot ooto add <msg>'"

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>'"
msg.reply "You are not marked as OOTO! To add a new OOTO message, use 'grbot ooto add <msg>'"
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>'"
msg.reply "You are not marked as OOTO! To add a new OOTO message, use 'grbot ooto add <msg>'"
when "help"
helpMsg = """
ooto add <msg> - sets you as ooto
ooto edit <msg> - 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 <user> <msg> - sends msg to user if they're away
ooto list - lists everyone who's ooto
ooto help - shows this help
grbot ooto add <msg> - sets you as ooto
grbot ooto edit <msg> - 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 <user> <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()
user = msg.match[1].toLowerCase()
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'"
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 + " <msg>'"