def standup_send(token, channel_id, message): ''' adds a given message to the buffer of messages to be sent when the standup ends. message is saved as 'handle_str: message', to be ready to be printed ''' u_id = check_token(token) check_standup_inputs(channel_id, u_id) if len(message) > 1000: raise InputError( description='Message must be less than 1000 characters') if not is_standup_active(channel_id): raise InputError( description='There is no standup active in this channel') get_standups()[channel_id]['message'].append( f'{find_handle(u_id)}: {message}') return {}
def standup_active(token, channel_id): ''' if there is an active standup in the channel, returns unix timestamp of when standup will finish otherwise, returns None ''' u_id = check_token(token) check_standup_inputs(channel_id, u_id) is_active = is_standup_active(channel_id) try: time_finish = get_standups()[channel_id]['time_created'] except KeyError: time_finish = None return {'is_active': is_active, 'time_finish': time_finish}
def standup_end(channel_id): ''' replaces placeholder message_id with the next available message id, uses str.join() to turn the message list into a string separated by newlines appends this new message to the list of messages in the given channel, and removes that channel id from the list of active standups if there no messages were sent during the standup, the standup is not added to the list of messages, but is still removed from the list of active standups ''' glob_channels = get_channels() glob_standups = get_standups() message_lst = glob_standups[channel_id]['message'] if len(message_lst) > 0: glob_standups[channel_id]['message_id'] = get_message_id() glob_standups[channel_id]['message'] = '\n'.join(message_lst) glob_channels[channel_id]['messages'].insert( 0, glob_standups.pop(channel_id)) else: glob_standups.pop(channel_id)
def standup_start(token, channel_id, length): ''' starts a standup in a given channel for length amount of time creates blank message with time_finish timestamp, placeholder message_id, and stores it in glob_standups ''' u_id = check_token(token) check_standup_inputs(channel_id, u_id) if is_standup_active(channel_id): raise InputError( description='A standup is already active in this channel') glob_standups = get_standups() time_finish = get_current_timestamp(length) message_template = create_message(u_id, -1, time_finish, []) glob_standups[channel_id] = message_template standup = Timer(length, standup_end, args=[channel_id]) standup.start() return {'time_finish': time_finish}
def is_standup_active(channel_id): ''' finds whether a channel has an active standup ''' return channel_id in get_standups()