diff --git a/morgenbot.py b/morgenbot.py index 3c9428d..819e6d0 100644 --- a/morgenbot.py +++ b/morgenbot.py @@ -21,13 +21,15 @@ 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 = [] @@ -35,6 +37,8 @@ in_progress = False current_user = '' absent_users = [] +user_ids = {} +user_names = {} def post_message(text, attachments=[]): slack.chat.post_message(channel = channel, @@ -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 @@ -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() @@ -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 @@ -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) @@ -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) @@ -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: @@ -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 @@ -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 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 to learn what they do.') return topic = topic[1:] @@ -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 to save a topic for later discussion. I\'ll list these for you when standup is over.') elif topic == 'left' or topic == '!left': @@ -290,16 +350,19 @@ def main(): text = request.form.get("text", "") # find !command, but ignore =0.5.4