Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for skipping idle users #29

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8a5ea7d
Adding !later command
Mar 24, 2016
dc0aba8
Improve command parsing, add prefix_only param
Mar 24, 2016
8840b40
Merge pull request #2 from adamhigerd/alh-prefix-only
Mar 24, 2016
d54a202
Merge pull request #1 from adamhigerd/alh-later-command
Mar 24, 2016
f02daac
Add !later command to commands list
Mar 24, 2016
2fdd2d6
Merge pull request #3 from adamhigerd/alh-later-command
Mar 24, 2016
a985970
Add support for skipping idle users
bedgington May 18, 2016
5cae237
Restore upstream whitespace for pull request, fix Slacker requirement…
bedgington May 18, 2016
3194aab
Choose next user by passing username to "next"
bedgington May 18, 2016
3c3a3e4
Choose next user by passing username to "next"
bedgington May 18, 2016
70dca4f
Choose next user by passing username to "next"
bedgington May 18, 2016
198a19a
Choose next user by passing username to "next"
bedgington May 18, 2016
de363e5
Choose next user by passing username to "next"
bedgington May 18, 2016
241acd2
Choose next user by passing username to "next"
bedgington May 18, 2016
01aafcb
Choose next user by passing username to "next"
bedgington May 18, 2016
6765f5b
Choose next user by passing username to "next"
bedgington May 18, 2016
08da430
Choose next user by passing username to "next"
bedgington May 18, 2016
34e7dde
Choose next user by passing username to "next"
bedgington May 18, 2016
21c9703
Choose next user by passing username to "next"
bedgington May 18, 2016
01019e5
Choose next user by passing username to "next"
bedgington May 18, 2016
f99424a
Choose next user by passing username to "next"
bedgington May 19, 2016
7317afc
Choose next user by passing username to "next"
bedgington May 19, 2016
e08cbec
Choose next user by passing username to "next"
bedgington May 19, 2016
718acca
Choose next user by passing username to "next"
bedgington May 19, 2016
984daee
Choose next user by passing username to "next"
bedgington May 19, 2016
e29027c
Choose next user by passing username to "next"
bedgington May 19, 2016
f324419
Choose next user by passing username to "next"
bedgington May 19, 2016
04566a2
Choose next user by passing username to "next"
bedgington May 19, 2016
209bf6b
Choose next user by passing username to "next"
bedgington May 19, 2016
9c763ca
Revert "Choose next user by passing username to "next""
bedgington May 19, 2016
bfd3d74
Revert "Restore upstream whitespace for pull request, fix Slacker req…
bedgington May 19, 2016
95b5a88
Revert "Add support for skipping idle users"
bedgington May 19, 2016
498d3f4
Testing cleaner skip idle users
bedgington May 19, 2016
69d54a1
Testing cleaner skip idle users
bedgington May 19, 2016
4d82b4b
Add support for skipping idle users
bedgington May 19, 2016
97f2f0d
Merge branch 'master' into develop
bedgington May 19, 2016
288b9b8
Merge branch 'master' of https://github.com/adamhigerd/morgenbot into…
bedgington May 19, 2016
a2d2479
Add !next @user support, add !later support, skip idle users just-in-…
bedgington May 19, 2016
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
93 changes: 79 additions & 14 deletions morgenbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,24 @@
icon_emoji = os.getenv('ICON_EMOJI', ':coffee:')
channel = os.getenv('CHANNEL', '#standup')
ignore_users = os.getenv('IGNORE_USERS', '[]')
skip_idle_users = False if os.getenv('SKIP_IDLE_USERS', 'true').lower() == 'false' else True

init_greeting = os.getenv('INIT_GREETING', 'Good morning!')
start_message = os.getenv('START_MESSAGE', 'What did you work on yesterday? What are you working on today? What, if any, are your blockers?')

giphy = True if os.getenv('GIPHY', 'false').lower() == 'true' else False
prefix_only = True if os.getenv('PREFIX_ONLY', 'false').lower() == 'true' else False

commands = ['standup','start','cancel','next','skip','table','left','ignore','heed','ignoring','help']
commands = ['standup','start','cancel','next','skip','later','table','left','ignore','heed','ignoring','help']

users = []
topics = []
time = []
in_progress = False
current_user = ''
absent_users = []
user_ids = {}
user_names = {}

def post_message(text, attachments=[]):
slack.chat.post_message(channel = channel,
Expand All @@ -58,7 +62,7 @@ def init():
global topics
global time
global in_progress

if len(users) != 0:
post_message('Looks like we have a standup already in process.')
return
Expand All @@ -70,13 +74,14 @@ def init():

def start():
global time
global users

if len(time) != 0:
post_message('But we\'ve already started!')
return
time.append(datetime.datetime.now())
post_message('Let\'s get started! %s\nWhen you\'re done, please type !next' % start_message)
next()
next(None)

def cancel():
tabled()
Expand All @@ -94,12 +99,16 @@ def done():

def reset():
global users
global user_ids
global user_names
global topics
global time
global in_progress
global current_user

del users[:]
del user_ids[:]
del user_names[:]
del topics[:]
del time[:]
in_progress = False
Expand All @@ -108,6 +117,8 @@ def reset():
def standup_users():
global ignore_users
global absent_users
global user_ids
global user_names

ignore_users_array = eval(ignore_users)

Expand All @@ -124,6 +135,8 @@ def standup_users():

for user_id in standup_users:
user_name = slack.users.info(user_id).body['user']['name']
user_ids[user_name] = user_id
user_names[user_id] = user_name
is_deleted = slack.users.info(user_id).body['user']['deleted']
if not is_deleted and user_name not in ignore_users_array and user_name not in absent_users:
active_users.append(user_name)
Expand All @@ -133,21 +146,56 @@ def standup_users():

return active_users

def next():
def next(args):
global users
global current_user
global ignore_users
global absent_users
global user_ids
global user_names
active_users = standup_users()
next_user_index = 0

if len(users) == 0:
done()
else:
current_user = users.pop()
post_message('@%s, you\'re up' % current_user)
if args is not None and args != '':
search_obj = re.search(ur'<@([^>]+)>', args)
if search_obj is not None:
user_id = search_obj.group(1)
if user_id in user_names:
user = user_names[user_id]
else:
user = ''
else:
user = args.strip().replace('@', '')
if user == current_user:
post_message('That makes no sense.');
next_user_index = 0;
elif user not in active_users and user not in ignore_users and user not in absent_users:
post_message('I don\'t recognize that user.')
elif user in ignore_users:
post_message('I\'m already ignoring that user.')
elif user in absent_users:
post_message('That user is absent.')
elif user in active_users:
next_user_index = users.index(user)
current_user = users.pop(next_user_index)

if skip_idle_users and slack.users.get_presence(user_ids[current_user]).body['presence'] != 'active':
post_message('Skipping @%s (idle).' % current_user)
next(None)
else:
post_message('@%s, you\'re up' % current_user)

def standup_time():
if len(time) != 2: return
seconds = (time[1] - time[0]).total_seconds()
minutes = seconds / 60
post_message('That\'s everyone! Standup took us %d minutes.' % minutes)
if minutes < 1:
post_message('That\'s everyone! Standup took us %d seconds.' % seconds)
else:
post_message('That\'s everyone! Standup took us %d minutes.' % minutes)

def left():
if len(users) == 0:
Expand Down Expand Up @@ -208,7 +256,17 @@ def ignoring():

def skip():
post_message('Skipping @%s.' % current_user)
next()
next(None)

def later():
global users
if len(users) > 1:
post_message('We\'ll call on @%s later.' % current_user)
users.append(current_user)
else:
post_message('We can\'t call on @%s later. @%s is the last one left.' % (current_user, current_user))
users.insert(current_user)
next(None)

def table(topic_user, topic):
global topics
Expand Down Expand Up @@ -252,7 +310,7 @@ def giphy(text):

def help(topic=''):
if topic == '':
post_message('My commands are !standup, !start, !cancel, !next, !skip, !table, !left, !ignore, !heed, and !ignoring.\nAsk me "!help <command> to learn what they do.')
post_message('My commands are !standup, !start, !cancel, !next, !skip, !later, !table, !left, !ignore, !heed, and !ignoring.\nAsk me "!help <command> to learn what they do.')
return

topic = topic[1:]
Expand All @@ -266,6 +324,8 @@ def help(topic=''):
post_message('Type !next to call on the next person when you\'re done standing up')
elif topic == 'skip' or topic == '!skip':
post_message('Type !skip to skip someone who isn\'t standing up that day')
elif topic == 'later' or topic == '!later':
post_message('Type !later to move someone who isn\'t ready yet to the end of the list')
elif topic == 'table' or topic == '!table':
post_message('Type !table <topic> to save a topic for later discussion. I\'ll list these for you when standup is over.')
elif topic == 'left' or topic == '!left':
Expand All @@ -290,16 +350,19 @@ def main():
text = request.form.get("text", "")

# find !command, but ignore <!command
match = re.findall(r"(?<!<)!(\S+)", text)
if prefix_only:
match = re.findall(r"^!(\S+)", text)
else:
match = re.findall(r"(?<!<)!(\S+)", text)
if not match: return

command = match[0]
args = text.replace("!%s" % command, '')
args = text[text.find("!%s" % command) + len(command) + 1:]
command = command.lower()

if command not in commands:
if giphy:
giphy(text[1:])
giphy("%s %s" % (command, args))
else:
post_message('Not sure what "%s" is.' % command)
return json.dumps({ })
Expand All @@ -314,9 +377,11 @@ def main():
elif command == 'cancel':
cancel()
elif command == 'next':
next()
next(args)
elif command == 'skip':
skip()
elif command == 'later':
later()
elif command == 'table':
table(msguser, args)
elif command == 'left':
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Flask==0.10.1
requests==2.2.1
wsgiref==0.1.2
gunicorn==18.0
slacker==0.4.0
slacker>=0.5.4