def input_delete_message(): print(MENU_OPTION_DEL_MESSAGE) try: number = int(input("Enter number:\t")) return number except Exception as Ex: sync_logger.console(Ex)
def input_select_user(): print(MENU_SELECT_USER) try: option = int(input("Enter number:\t")) return option except Exception as Ex: sync_logger.console(Ex)
def input_reply_message(sender_id, receiver_id): message = input_string_data("Type a message:") if message and len(message) > 0: if sent_message(sender_id, receiver_id, message): print('Sent message successfully') else: sync_logger.console('Could not sent message') else: print('Mesage is empty:')
def input_valid_email(): while True: email = input("\nEnter your email: ") if is_email_validated(email): return email else: sync_logger.console( "\nInvalid email: {}. Please try again!".format( html.escape(email)))
def input_number(min_number, max_number, message='Enter number in'): print("{} [{}:{}]".format(message, min_number, max_number)) try: number = int(input('Enter number:\t')) if min_number <= number <= max_number: return number else: print('Invalid number, please choose number in: [{}:{}]'.format( min_number, max_number)) except Exception as Ex: sync_logger.console(Ex) return -1
def select_util_function_in_friend(user_id, friend_id): # Option util function option = input_util_function() # Delete friend if option == "D": if remove_friend(user_id, friend_id): print('Delete friend successfully') else: sync_logger.console("Could not delete friend") # Reply message elif option == "R": reply_message(user_id, friend_id) elif option == "E": print("Exit") else: print("Invalid option")
def remove_block_user(blocker_id): blocks_user = get_all_blocks_user(blocker_id) if blocks_user and len(blocks_user) > 0: # Display list blocks user display_list_users(blocks_user) # Select user number index = input_number(0, len(blocks_user) - 1) user_id = blocks_user[index].id if user_id >= 0: if unblock(blocker_id, user_id): print('Remove block successfully') else: sync_logger.console('Remove block failed') else: sync_logger.console('Could not remove block') else: print('No block user!')
def add_new_friend(user_id): list_data = search_user_by_name(user_id) if list_data and len(list_data) > 0: # Display list name user display_list_users(list_data) # Select user number index = input_number(0, len(list_data) - 1) friend_id = list_data[index].id if friend_id >= 0: if is_friend_existed(user_id, friend_id): print("Add new friend successfully") elif add_friend(1, friend_id): print("Add new friend successfully") else: sync_logger.console("Add friend failed!") else: sync_logger.console("Could not add a new friend!") else: print("No result")
def add_block_user(blocker_id): # Searching username list_data = search_user_by_name(blocker_id) if list_data and len(list_data) > 0: # Display list name user display_list_users(list_data) # Select user number index = input_number(0, len(list_data) - 1) user_id = list_data[index].id if user_id >= 0: if is_user_blocked(blocker_id, user_id): print('Block successfully') elif block_user(blocker_id, user_id): print('Block successfully') else: sync_logger.console('Block user failed') else: sync_logger.console('Could not block') else: print('No result')
def main(): while True: main_action = show_menu_and_choose_action('main') current_user_id = current_user.get().id if main_action == 1: # Message message_action = show_menu_and_choose_action('message') # View message and other utils if message_action == 1: # Input option incoming message or sent message view_option = input_view_message() if view_option == 1: # Init list incoming message list_senders = get_sender_message(current_user_id) if list_senders and len(list_senders) > 0: # Display incoming message display_list_users(list_senders, title='LIST_SENDER') # Select a message index = input_number( 0, len(list_senders) - 1, message="Select a sender --> Enter number in:") if index >= 0: sender_id = list_senders[index].id list_messages = get_messages( sender_id, current_user_id) if list_messages and len(list_messages) > 0: # Display conversation display_conversation(current_user_id, list_messages) # Display util function choose_util_mss(current_user_id, sender_id) else: print("No message") else: sync_logger.console( "Error", "Could not select sender message") else: print("No sender message") elif view_option == 2: # Init sent message list_receivers = get_receiver_message(current_user_id) if list_receivers and len(list_receivers) > 0: # Display sent message display_list_users(list_receivers, title='\nLIST_RECEIVERS:') # Select a message index = input_number( 0, len(list_receivers) - 1, message='Select a receiver --> Enter number in:') if index >= 0: receiver_id = list_receivers[index].id list_messages = get_messages( receiver_id, current_user_id) # Display detail a message display_conversation(current_user_id, list_messages) # Display util function choose_util_mss(current_user_id, receiver_id) else: sync_logger.console( 'Could not select receiver message') else: print('No receiver message') elif message_action == 2: sent_message(current_user_id) elif message_action == 3: print("Back to message") else: print( 'Invalid message action. Please choose message action: 1, 2 or 3' ) elif main_action == 2: # Friend friend_action = show_menu_and_choose_action('friend') if friend_action == 1: list_data = get_all_friends(current_user_id) if list_data and len(list_data) > 0: # List all friends display_list_users(list_data) # Select a friend friend_id = select_detail_user(current_user_id, list_data) if friend_id >= 0: # Display detail a friend display_detail_user(friend_id) # Option other function select_util_function_in_friend(current_user_id, friend_id) else: print('No friend') elif friend_action == 2: # Add new friend add_new_friend(current_user_id) elif friend_action == 3: # Block add_block_user(current_user_id) elif friend_action == 4: # Remove block remove_block_user(current_user_id) elif friend_action == 5: print('Back to main') else: print( 'Invalid friend action. Please choose friend action: 1, 2, 3, 4 and 5' ) elif main_action == 3: # Logout break else: print('Invalid main action. Please choose main action: 1, 2 or 3')
def remove_message(user_id, friend_id): if delete_all_message(user_id, friend_id): print("Delete all messages Successfully") else: sync_logger.console("Could not delete message")