- 01
 - 02
 - 03
 - 04
 - 05
 - 06
 - 07
 - 08
 - 09
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 - 20
 - 21
 - 22
 - 23
 - 24
 - 25
 - 26
 - 27
 - 28
 - 29
 - 30
 - 31
 - 32
 - 33
 - 34
 - 35
 - 36
 - 37
 - 38
 - 39
 - 40
 - 41
 - 42
 - 43
 - 44
 - 45
 - 46
 - 47
 - 48
 - 49
 - 50
 - 51
 - 52
 - 53
 - 54
 - 55
 - 56
 - 57
 - 58
 - 59
 - 60
 - 61
 - 62
 - 63
 - 64
 - 65
 - 66
 - 67
 - 68
 - 69
 - 70
 - 71
 - 72
 - 73
 - 74
 - 75
 - 76
 - 77
 - 78
 - 79
 - 80
 - 81
 - 82
 - 83
 - 84
 - 85
 - 86
 - 87
 - 88
 - 89
 - 90
 - 91
 - 92
 - 93
 - 94
 
                        import datetime, random, time, os, vk_api
import sqlite3 as sl
from vk_api.exceptions import Captcha
from vk_api.longpoll import VkEventType, VkLongPoll
from functions import *
from settings import *
vk_session = vk_api.VkApi(token=token, api_version=5.126)
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
now = datetime.datetime.now()
for event in longpoll.listen():
    try:
        def send_msg(msg='', chat=False, prefix=True, attach=''):
            if chat:
                vk.messages.send(chat_id=event.chat_id,message=msg,attachment=attach)
            else:
                vk.messages.send(user_id=event.user_id,message=msg,attachment=attach)
    except Captcha:
        time.sleep(1)
        send_msg('Ошибка. Слишком частые запросы.')
    except Exception as e:
        time.sleep(1)
        send_msg(f'Неизвестная ошибка при отправке сообщения.\n{e}')
    try:
        if event.type == VkEventType.MESSAGE_NEW and event.to_me:
            user_get = vk.users.get(user_ids=event.user_id)
            first_name = user_get[0]['first_name']
            last_name = user_get[0]['last_name']
            if event.from_chat and event.chat_id and (event.message == '!meme' or event.message == '!мем'):
                meme_create()
                upload = vk_api.VkUpload(vk_session)
                try:
                    a = upload.photo_messages(photos=os.path.dirname(__file__) + '/random_meme.jpg', peer_id=event.user_id)
                    send_msg(attach=f'photo{a[0]["owner_id"]}_{a[0]["id"]}',chat=True, prefix=False)
                except:
                    send_msg("Ошибка. Попробуйте снова.")
            elif event.from_chat and event.chat_id and (event.message == '!info' or event.message == '!инфо'):
                response = requests.get(f'https://vk.com/foaf.php?id={event.user_id}')
                soup = BeautifulSoup(response.text, 'lxml')
                created = soup.find('ya:created').get('dc:date')
                created1 = datetime.datetime.strptime(created, '%Y-%m-%dT%H:%M:%S%z').replace(tzinfo=None)
                diff = datetime.datetime.now()-created1
                modified = soup.find('ya:modified').get('dc:date')
                modified1 = datetime.datetime.strptime(modified, '%Y-%m-%dT%H:%M:%S%z').replace(tzinfo=None)
                send_msg(f'''https://vk.com/id{event.user_id}\nИмя пользователя: {first_name} {last_name}\nАккаунт существует {diff.days} дней.\nДата регистрации: {created1.month} {months[created1.month-1]} {created1.year} в {created1.time()}\nПоследнее обновление информации: {modified1.month} {months[modified1.month-1]} {modified1.year} в {modified1.time()}''', chat=True)
            elif event.from_user and event.user_id and (event.message == '!info' or event.message == '!инфо'):
                response = requests.get(f'https://vk.com/foaf.php?id={event.user_id}')
                soup = BeautifulSoup(response.text, 'lxml')
                created = soup.find('ya:created').get('dc:date')
                created1 = datetime.datetime.strptime(created, '%Y-%m-%dT%H:%M:%S%z').replace(tzinfo=None)
                diff = datetime.datetime.now()-created1
                modified = soup.find('ya:modified').get('dc:date')
                modified1 = datetime.datetime.strptime(modified, '%Y-%m-%dT%H:%M:%S%z').replace(tzinfo=None)
                send_msg(f'''https://vk.com/id{event.user_id}\nИмя пользователя: {first_name} {last_name}\nАккаунт существует {diff.days} дней.\nДата регистрации: {created1.month} {months[created1.month-1]} {created1.year} в {created1.time()}\nПоследнее обновление информации: {modified1.month} {months[modified1.month-1]} {modified1.year} в {modified1.time()}''')
            elif event.from_user and event.user_id and event.message == '!coin':
                coin = 'Орёл' if random.randint(0, 1) == 1 else 'Решка'
                send_msg(f'{coin}')
            elif event.from_user and event.user_id and (event.message == '!anek' or event.message == '!анек'):
                send_msg(f'{get_anek()}', prefix=False)
            elif event.from_user and event.user_id:
                con = sl.connect(os.path.dirname(__file__) + '/users.db')
                count = 0
                with con:
                            con.execute("""
                                CREATE TABLE IF NOT EXISTS USER (
                                    user_id INTEGER NOT NULL PRIMARY KEY,
                                    name TEXT,
                                    permission_lvl INTEGER
                                );
                            """)
                with con:
                    data = con.execute("SELECT * FROM USER")
                    for row in data:
                        if event.user_id in row:
                            count += 1
                    if count == 0:
                        send_msg(f'''Привет, это сообщение отправлено автоматически.\nПока я добавляю информацию о тебе в базу данных, ты можешь ознакомиться с командами написав !help\nКоманд не так много, но в будущем их станет больше ;)''')
                        sql = 'INSERT INTO USER (user_id, name, permission_lvl) values(?, ?, ?)'
                        data = [(event.user_id, f'{first_name} {last_name}', 1)]
                        with con:
                            con.executemany(sql, data)
            if event.attachments:
                print(
                    f"{now}\nuser_id: {event.user_id} | {first_name} {last_name}\nmessage: {event.message}\nattach: {event.attachments}\n")
            else:
                print(
                    f"{now}\nuser_id: {event.user_id} | {first_name} {last_name}\nmessage: {event.text}\n")
    except Captcha:
        time.sleep(1)
        send_msg('Ошибка. Слишком частые запросы.')
    except Exception as e:
        time.sleep(1)
        send_msg(f'Упс. Произошла неизвестная ошибка.\n{e}')