예제 #1
0
파일: main.py 프로젝트: fckxorg/VkBot
def main():
    for event in longpoll.listen():

        if event.type == VkEventType.MESSAGE_NEW:
            id = event.user_id
            response = event.text.lower()

            if list_of_users.count(id) == 0:
                list_of_users.append(id)
                if id == id_Kristina:
                    group_Kr.append(id)
                else:
                    group_932.append(id)

            if event.from_user and id == id_headman and not event.from_me:
                if 'all' in response:
                    for user in list_of_users:
                        if not user == id_headman:
                            send_message(user, message=event.text, keyboard=keyboard_menu)
                        else:
                            send_message(user, message='Сообщение отправлено', keyboard=keyboard_menu)

            elif event.from_user and not event.from_me:

                if response ==   'начать':
                    send_message(id, message='Возможные действия', keyboard=keyboard_menu)
                if response ==   'расписание':
                    keyboard = create_keyboard(response)
                    send_message(id, message='Выберите день', keyboard=keyboard)
                elif response == 'ближайшая пара':
                    send_message(id, message=the_nearest_lesson_string(), keyboard=keyboard_menu)
                elif response in timetables.keys():
                    attachment = get_pictures.get(vk_session, session, timetables[response])
                    send_message(id, message=response.capitalize(), attachment=attachment, keyboard=keyboard_menu)
                else:
                    send_message(id, message='', keyboard=keyboard_menu)
예제 #2
0
            'keyboard': keyboard
        })


for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        print('Сообщение пришло в: ' +
              str(datetime.strftime(datetime.now(), "%H:%M:%S")))
        print('Текст сообщения: ' + str(event.text))
        print(event.user_id)
        response = event.text.lower()
        keyboard = create_keyboard(response)

        if event.from_user and not event.from_me:
            if response == "котики":
                attachment = get_pictures.get(vk_session, -130670107,
                                              session_api)
                send_message(vk_session,
                             'user_id',
                             event.user_id,
                             message='Держи котиков!',
                             attachment=attachment,
                             keyboard=keyboard)
            elif response == "привет":
                send_message(
                    vk_session,
                    'user_id',
                    event.user_id,
                    message='Нажми на кнопку, чтобы получить список команд',
                    keyboard=keyboard)
            elif response == "тест":
                send_message(vk_session,
예제 #3
0
    return name.get_text(strip=True)


for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        print('Сообщение пришло в: ',
              str(datetime.strftime(datetime.now(), '%H:%M:%S')))
        print('Текст сообщения: ' + str(event.text))
        print('Отправитель — {}, id пользователя — {}'.format(
            get_user_name(event.user_id), event.user_id))
        print('=' * 100)
        response = event.text.lower()
        if event.from_user and not event.from_me:
            if response == "12!":
                vk_session.method(
                    'messages.send', {
                        'user_id': event.user_id,
                        'message': 'И тебе привет от бота!',
                        'random_id': 0
                    })
            elif response == 'мемы':
                attachment = get_pictures.get(vk_session, -142574308,
                                              session_api)
                vk_session.method(
                    'messages.send', {
                        'user_id': event.user_id,
                        'message': 'Лови котиков!',
                        'random_id': 0,
                        'attachment': attachment
                    })
예제 #4
0
파일: ber.py 프로젝트: DimaPlg/ep_prog
 if event.type == VkEventType.MESSAGE_NEW:
     print('Сообщение пришло в: ' +
           str(datetime.strftime(datetime.now(), "%H:%M:%S")))
     print('Текст сообщения: ' + str(event.text))
     print(event.user_id)
     response = event.text.lower()
     if event.from_user and not (event.from_me):
         if response == "привет":
             vk_session.method(
                 'messages.send', {
                     'user_id': event.user_id,
                     'message': 'Привет, друг!',
                     'random_id': 0
                 })
         elif response == "котик":
             attachment = get_pictures.get(vk_session, -23300841,
                                           session_api)
             vk_session.method(
                 "messages.send", {
                     "user_id": event.user_id,
                     'message': " ",
                     "attachment": attachment,
                     "random_id": 0
                 })
         elif response == "анекдот":
             attachment = nekdot.get(vk_session, -29103840, session_api)
             vk_session.method(
                 "messages.send", {
                     "user_id": event.user_id,
                     'message': " ",
                     "attachment": attachment,
                     "random_id": 0
예제 #5
0
    for event in longpoll.listen():
        if event.type == VkEventType.MESSAGE_NEW:
            print('Сообщение пришло в: ' +
                  str(datetime.strftime(datetime.now(), "%H:%M:%S")))
            print("Текст сообщения: " + str(event.text))
            print(event.user_id)
            response = event.text.lower()

            if event.from_user and not (event.from_me):
                if response.find('привет') != -1:
                    send_message(vk_session,
                                 'user_id',
                                 event.user_id,
                                 message='Дарова, хуйло! Как делишки?))')
                elif response.find('мемы') != -1:
                    attachment = get_pictures.get(vk_session, -95958948,
                                                  session_api, 5)
                    send_message(vk_session,
                                 'user_id',
                                 event.user_id,
                                 message='Ну держи мемы:',
                                 attachment=attachment)
                elif response.find("работать") != -1:
                    attachment = get_pictures.get(vk_session, -95958948,
                                                  session_api, 1)
                    attachment += ',' + read_audio.read()
                    create_post.create(
                        -95958948, '#Ботопост_генератор_музыки_рандомный_мем',
                        session_api, attachment)
                elif response.find("паста") != -1:
                    pasta = get_shit_pasta.get(session_api, -92157416)
                    send_message(vk_session,
예제 #6
0
def main():
    try:
        log_engine_main_thread.log("main:")
        log_engine_main_thread.log("Longpoll listen")
        for event in longpoll.listen():
            if event.type == VkEventType.MESSAGE_NEW:
                log_engine_main_thread.log("Got message")
                id = event.user_id
                response = event.text.lower()

                if list_of_users.count(id) == 0:
                    list_of_users.append(id)

                if event.from_user and id == id_headman and not event.from_me:
                    if 'all' in response:
                        log_engine_main_thread.log(
                            "Got announcement from headman")
                        for user in list_of_users:
                            if not user == id_headman:
                                send_message(user,
                                             message=event.text,
                                             keyboard=keyboard_menu)
                            else:
                                send_message(user,
                                             message='Сообщение отправлено',
                                             keyboard=keyboard_menu)

                elif event.from_user and not event.from_me:

                    if response == 'расписание':
                        log_engine_main_thread.log("Sending timetable")
                        keyboard = create_keyboard(response)
                        send_message(id,
                                     message='Выберите день',
                                     keyboard=keyboard)

                    elif response == 'ближайшая пара':
                        log_engine_main_thread.log("Sending nearest lesson")
                        lesson_idx, day = the_nearest_lesson()
                        if lessons[day][
                                lesson_idx].link == None or lesson_idx == -1:
                            keyboard = keyboard_menu
                        else:
                            keyboard = create_lecture()
                        send_message(id,
                                     message=the_nearest_lesson_string(),
                                     keyboard=keyboard)

                    elif response in timetables.keys():
                        log_engine_main_thread.log(
                            "Sending timetable for a day")
                        attachment = get_pictures.get(vk_session, session,
                                                      timetables[response])
                        send_message(id,
                                     message=response.capitalize(),
                                     attachment=attachment,
                                     keyboard=keyboard_menu)
                    else:
                        log_engine_main_thread.log("Sending usage")
                        send_message(id,
                                     message='Возможные действия',
                                     keyboard=keyboard_menu)
    except Exception as e:
        log_engine_main_thread.log(str(e))
예제 #7
0
    if event.type == VkEventType.MESSAGE_NEW:
        print('Время: ' + str(datetime.strftime(datetime.now(), "%H:%M:%S")))
        print('Текст ПИДОРАСА: ' + str(event.text))
        print(event.user_id)
        response = event.text.lower()

        if event.text.lower() == "!камни":
            if event.from_chat:
                send_message(
                    vk_session, 'chat_id', event.chat_id,
                    '🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿🗿'
                )

        if event.text.lower() == "!лоли":
            if event.from_chat:
                attachment = get_pictures.get(vk_session, -127518015,
                                              session_api)
                vk_session.method(
                    'messages.send', {
                        'chat_id': event.chat_id,
                        'message': 'Держи девочку!',
                        'random_id': 0,
                        "attachment": attachment
                    })

        if event.text.lower() == "!юри":
            if event.from_chat:
                attachment = get_pictures2.get(vk_session, -153284406,
                                               session_api)
                vk_session.method(
                    'messages.send', {
                        'chat_id': event.chat_id,
예제 #8
0
def get_user_name(user_id):
    request = requests.get('http://vk.com/id' + str(user_id), headers=HEADERS)
    soup = BeautifulSoup(request.text, 'html.parser')
    items = soup.find_all('div', class_='page_top')
    name = ''
    while name == '':
        for item in items:
            name = item.find('h1', class_='page_name')

    return name.get_text(strip=True)


for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        print('Сообщение пришло в: ', str(datetime.strftime(datetime.now(), '%H:%M:%S')))
        print('Текст сообщения: ' + str(event.text))
        print('В диалоге с ' + get_user_name(event.user_id) + f', id пользователя = {event.user_id}')
        print('=' * 100)
        response = event.text.lower()
        if event.from_user and not event.from_me:
            if response == "12!":
                vk_session.method('messages.send', {'user_id': event.user_id,
                                                    'message': 'И тебе привет от бота!', 'random_id': 0})
            elif response == 'котейки':
                attachment = get_pictures.get(vk_session, -175086907, session_api)
                vk_session.method('messages.send', {'user_id': event.user_id,
                                                    'message': 'Лови котиков!', 'random_id': 0,
                                                    'attachment': attachment})