예제 #1
0
def send_example(user_id, state):
    print("Running the function: ", send_example.__name__)

    attachments = []
    keyboard = Create_board(state)

    vk_sessionGroup.method(
        'messages.send', {
            'user_id':
            user_id,
            'message':
            config.get('chat').get('errors').get('photo').get('one_person'),
            'random_id':
            0,
            'keyboard':
            keyboard
        })
    message = upload.photo_messages(
        f'{config.get("media_folder").get("name")}\\' +
        f'{config.get("media_folder").get("folders").get("photo_example")}\\' +
        'example.jpg')[0]
    attachments.append('photo{}_{}'.format(message['owner_id'], message['id']))
    vk_sessionGroup.method(
        'messages.send', {
            'user_id': user_id,
            'message': 'Образец:',
            'random_id': 0,
            'attachment': ','.join(attachments)
        })
    print(send_example.__name__, " function is completed", end='\n\n')
    return
예제 #2
0
def print_text(user, sentences):
    text = ""
    for value in sentences.values():
        text += value
    vk_sessionGroup.method('messages.send', {
        'user_id': user['user_id'],
        'message': text,
        'random_id': 0
    })
예제 #3
0
def delete_user_data(user, event):
    user_id = user['user_id']
    mdb.delete_user(user_id)

    text = config.get('chat').get('success').get('photo').get(
        'delete_user_data')
    vk_sessionGroup.method('messages.send', {
        'user_id': user_id,
        'message': text,
        'random_id': 0
    })
예제 #4
0
def ask_admin(user, event):
    command = "/ask_admin"

    state = user['chat']['state']
    if state == command:
        vk_sessionGroup.method('messages.markAsAnsweredConversation', {
            'peer_id': -user['user_id'],
            'answered': 0,
            'group_id': id_group
        })
    else:
        interface.print_menu(user, command)
        mdb.set_user_state(user, command)
    return
예제 #5
0
def insert_user(user_id):
    user = vk_sessionGroup.method("users.get", {"user_ids": user_id})
    separate_date = time_tools.separate(datetime.now())
    output = users_clt.insert_one({
        "user_id": user_id,
        "first_name": user[0]['first_name'],
        "last_name": user[0]['last_name'],
        "admin": 0,
        "chat": {
            "state": None,
            "last_greeting": {
                "year": separate_date['year'],
                "month": separate_date['month'],
                "day": separate_date['day'],
                "hour": separate_date['hour'],
                "minute": separate_date['minute'],
                "second": separate_date['second'],
                "microsecond": separate_date['microsecond'],
                "tzinfo": separate_date['tzinfo']
            }
        },
        # "identify": None,
        # "embedding": None,
        # "photos": []
    })
    return output.inserted_id
예제 #6
0
def send_archive_to_user(person_photos, user_id):
    print("Running the function: ", send_archive_to_user.__name__)

    ii16 = np.iinfo(np.int16)

    path, archive_name = create_images_archive(person_photos)

    attachments = []
    document = upload.document_message(path + archive_name,
                                       title=f"photos{id_group}",
                                       peer_id=user_id)
    attachments.append('doc{}_{}'.format(document['doc']['owner_id'],
                                         document['doc']['id']))
    vk_sessionGroup.method(
        'messages.send', {
            'user_id': user_id,
            'random_id':
            user_id * 10 * ii16.bits + random.randint(0, ii16.max),
            'attachment': ','.join(attachments)
        })

    delete_archive(path, archive_name)
    print(send_archive_to_user.__name__, " function is completed", end='\n\n')
    return
예제 #7
0
def print_menu(user, state):
    keyboard = Create_board(state)
    if user['chat']['state'] is None:
        vk_sessionGroup.method(
            'messages.send', {
                'user_id':
                user['user_id'],
                'message':
                config['chat']['greeting']['first_meeting']['hello'] +
                user['first_name'] + "!\n",
                'random_id':
                0,
                'keyboard':
                keyboard
            })
    else:
        current_date = datetime.now()
        last_greeting_date = time_tools.compound(user['chat']['last_greeting'])
        timer_threshold = time_tools.timer_threshold

        if ((current_date - last_greeting_date) >= timer_threshold) \
                or (current_date.hour >= 6 and last_greeting_date.hour < 6) \
                or (current_date.hour >= 6 and last_greeting_date.day != current_date.day):
            vk_sessionGroup.method(
                'messages.send', {
                    'user_id':
                    user['user_id'],
                    'message':
                    random.choice(config['chat']['greeting']['hello']) +
                    user['first_name'] + "!\n",
                    'random_id':
                    0
                })
            mdb.update_last_greeting(user)

        vk_sessionGroup.method(
            'messages.send', {
                'user_id': user['user_id'],
                'message': config['chat'][state]['intro'],
                'random_id': 0,
                'keyboard': keyboard
            })
예제 #8
0
def message_processing(event):
    chat = 'chat'

    # Получение данных о пользователе
    user = check_user(event)
    state = user[chat]['state']

    if state is None:
        # Вывод главного меню
        allfuncs['/start'](user, event)
    else:
        # Определение запрашиваемой команды
        command = parse(event)

        # Выполнение пункта меню
        try:
            '''
                Решить, как избавиться
            '''
            # if state == "/ask_admin" and command is None:
            #     allfuncs[state](user, event)
            #
            # # Рассмотреть случай удаления вопроса
            # elif state == "/ask_identify" and command is not None:
            #     allfuncs[state](user, event, command)
            #
            # elif state == "/identify" and command is None:
            #     allfuncs[state](user, event)
            #
            # elif state == "/get_all" and command is None:
            #     allfuncs[state](user, event)
            #
            # elif state == "/get_series" and command is None:
            #     allfuncs[state](user, event)
            # elif state == "/get_series""/command is None:
            #     person_photos = allfuncs[command]
            if command is None:
                allfuncs[state](user, event)
            else:
                allfuncs[command](user, event)
        except KeyError:
            vk_sessionGroup.method(
                'messages.send', {
                    'user_id':
                    user['user_id'],
                    'message':
                    random.choice(config.get(chat).get('failure_phrases')),
                    'random_id':
                    0
                })
            allfuncs[state](user, event)

        except UnexpectedRequestError:
            vk_sessionGroup.method(
                'messages.send', {
                    'user_id':
                    user['user_id'],
                    'message':
                    random.choice(config.get(chat).get('failure_phrases')),
                    'random_id':
                    0
                })
            parent = config.get('chat').get(state).get('parent')
            allfuncs[parent](user, event)

        except (InvalidPhotoError, NotFoundError, PhotoCountError,
                FaceDataError) as error:
            vk_sessionGroup.method(
                'messages.send', {
                    'user_id': user['user_id'],
                    'message': error.message,
                    'random_id': 0
                })
            parent = config.get('chat').get(state).get('parent')
            allfuncs[parent](user, event)