def message_send(token, channel_id, message): """ Sends a message to the designated channel Parameters: token (string) channel_id(int) message(string) Returns: (dictionary): A dictionary containing the message_id of the message that was sent. """ user = token_check(token) if not user: raise InputError channel = channel_check(channel_id) if channel is None: raise InputError #if check_user_in_channel(user['u_id'], channel_id) == False: # raise AccessError if (len(message) > 1000): raise InputError if not member_channel_check(token, channel_id): raise AccessError # message_store = get_messages_store() for member in channel['all_members']: if user['u_id'] == member['u_id']: message_id = make_message(message, channel_id, user['u_id'], 0) if message == "/hangman": channel['Hangman']['is_hangman_active'] = True make_message( "Welcome to Hangman!\n Please input your guess to start the game in the format /guess x where x is your guess\n", channel_id, user['u_id'], 0) if message[0:6] == "/guess" and channel['Hangman'][ 'is_hangman_active'] == True: hangman = play_hangman(message[7]) print('full hang', hangman) print('this is whats being used to print') print('current word:', hangman['current_word']) print('Hangman drwing:', hangman['hang_man_drawing']) if len(hangman['final']) != 0: channel['Hangman']['is_hangman_active'] = False make_message( hangman['hang_man_drawing'] + "\nWord to guess: " + hangman['print_word'] + hangman['final'], channel_id, user['u_id'], 0) return { 'message_id': message_id, }
def message_send_later(token, channel_id, message, time_sent): """ Sends a message to the designated channel at a specified time Parameters: token (string) channel_id(int) message(string) time_sent (datetime) Returns: (dictionary): A dictionary containing the message_id of the message that was sent. """ user = token_check(token) if user == False: raise InputError channel = channel_check(channel_id) if channel == False: raise InputError if member_channel_check(token, channel_id) == False: raise AccessError if (len(message) > 1000): raise InputError if int(time_sent) < int( datetime.datetime.now().replace(tzinfo=timezone.utc).timestamp()): raise InputError message_store = get_messages_store() for member in channel['all_members']: if user['u_id'] == member['u_id']: wait_time = time_sent - datetime.datetime.now().replace( tzinfo=timezone.utc).timestamp() time.sleep(wait_time) #wait_time = time.mktime(datetime.datetime.now().timetuple()) - time.mktime(time_sent.timetuple()) message_id = make_message(message, channel_id, user['u_id'], 0) return { 'message_id': message_id, }
def channel_addowner(token, channel_id, u_id): '''Adds someone as owner to a channel. Parameters: token (str): authorization hash channel_id (int): channel identification u_id (int): user identification ''' if channel_check(channel_id) == False: raise InputError if check_if_user_in_channel_owner_uid(u_id, channel_id) == True: raise InputError permission_error = token_check(token) if check_if_user_in_channel_owner(token, channel_id) == False: if permission_error['permission_id'] != 1: raise AccessError else: pass channel_store = get_channel_store() user = u_id_check(u_id) for channel in channel_store["Channels"]: if channel["channel_id"] == channel_id: if member_channel_check(user['token'], channel_id) == False: channel["all_members"].append({ "u_id": user["u_id"], "name_first": user['name_first'], "name_last": user["name_last"] }) channel["owner_members"].append({ "u_id": user["u_id"], "name_first": user['name_first'], "name_last": user["name_last"] }) user['channel_id_owned'].append(channel_id) user['channel_id_part'].append(channel_id) return {}
def message_unpin(token, message_id): """Unpins a message Parameters: token (string) message_id(int) """ message = message_check(message_id) if message == None: raise InputError if member_channel_check(token, message['channel_id']) == False: raise AccessError if owner_channel_check(token, message['channel_id']) == False: raise InputError if message['is_pinned'] == False: raise InputError message['is_pinned'] = False return {}