Exemplo n.º 1
0
def read_message(user):
    while True:
        messages = list(ChatController.get_incoming_messages(user))

        if len(messages) == 0:
            pm.print_info_message('\nNo new messages!')
            break

        pm.print_enumerated_list(messages, message='Unread message ids:')

        index = int(
            input(f'{Colors.WHITE}\nSelect index to get detailed info ----> '))
        try:
            message = ChatController.convert_to_message_object(messages[index -
                                                                        1])
        except IndexError:
            pm.print_warning_message('\nOut of index. Try again.')
            continue

        ChatController.read_message(message)

        pm.print_info_message('\nSelected object: ')
        pm.print_dict_minimized(message.__dict__)

        break
Exemplo n.º 2
0
def read_message(user):
    messages = list(ChatController.get_incoming_messages(user))

    if len(messages) == 0:
        print_info_message('User {0} has no messages'.format(user.username))
        return

    msg_id = messages[0] if len(messages) == 1 else messages[random.randrange(0, len(messages) - 1, 1)]

    message = ChatController.convert_to_message_object(msg_id)
    print_info_message('{0} read a message from {1}'.format(message.recipients, message.sender))

    ChatController.read_message(message)
Exemplo n.º 3
0
def process_message(message):
    print_method.print_info_message('\nChecking for spam.. ')

    if ChatController.is_spam(message.content):
        print_method.print_warning_message(
            'Spam detected! Blocking this message?')
        ChatController.block_massage(message)
        neo4j.set_spam_message(message)

        return

    print_method.print_info_message(
        'No spam detected! Sending this message...')
    ChatController.send_message(message)
Exemplo n.º 4
0
def select_message_from_queue():
    while True:
        index = int(input(f'{Colors.WHITE}Select index: ----> '))

        try:
            message = ChatController.get_selected_message_from_queue(index - 1)
        except IndexError:
            print_method.print_warning_message('Out of index. Try again.')
            continue

        print_method.print_info_message('Selected object: ')
        print_method.print_dict(message.__dict__)

        process_message(message)
        break
Exemplo n.º 5
0
def load_emulator_scene():
    print_info_message('\nYou are in emulator mode\n')

    for username in usernames:
        user = User(username)
        for i in range(1, 2):
            # time.sleep(random.random() * 2)
            # if not random.getrandbits(1):
            #     read_message(user)
            publish_message(user)

    try:
        for message in listener.listen():
            if message.get('type') == 'message':
                msg = ChatController.convert_to_message_object(message.get('data'))
                process_message(msg)
    except KeyboardInterrupt:
        pass
Exemplo n.º 6
0
def load_worker_scene():
    print_method.print_info_message('You logged in as worker.')

    while True:
        print_method.print_initial(options)

        option = int(input("----> "))

        if option == GET_MESSAGE_QUEUE:
            get_message_queue()

        if option == SELECT_MESSAGE:
            select_message_from_queue()

        if option == BACK:
            break

        continue
Exemplo n.º 7
0
def show_user_menu(user):
    pm.print_info_message('\nYou logged in as {0}.'.format(user.username))

    while True:
        pm.print_initial(user_options)

        option = int(input("----> "))

        if option == SEND_MESSAGE:
            send_message(user)

        if option == READ_MESSAGES:
            read_message(user)

        if option == GET_USER_MESSAGES_INFO:
            get_user_messages_info(user)

        if option == BACK:
            break

        continue
Exemplo n.º 8
0
def show_admin_menu(user):
    pm.print_info_message('\nYou logged in as admin.')

    while True:
        pm.print_initial(admin_options)

        option = int(input("----> "))

        if option == READ_LOGS:
            read_logs()

        if option == GET_ONLINE_USERS:
            get_online_users()

        if option == GET_ACTIVE_SENDERS:
            get_active_senders()

        if option == GET_ACTIVE_SPAMMERS:
            get_active_spammers()

        if option == BACK:
            break

        continue
Exemplo n.º 9
0
def get_user_messages_info(user):
    msg_info = ChatController.get_user_messages(user)
    pm.print_info_message('\nMessage statistic:')
    pm.print_dict(msg_info)