import vk_api
import sqlite3
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.utils import get_random_id
token = 'TOKEN'
authorize = vk_api.VkApi(token = token)
longpoll = VkLongPoll(authorize)
db = sqlite3.connect('action.db')
sql = db.cursor()
sql.execute("""CREATE TABLE IF NOT EXISTS users (
userId BIGINT,
flag TEXT,
name TEXT,
age TEXT,
city TEXT,
text TEXT
)""")
db.commit()
def write_message (id, message):
authorize.method('messages.send', {'user_id': id, 'message': message, 'random_id': get_random_id()})
def zapros(flag):
sql.execute(f"UPDATE users SET flag = '{flag}' WHERE userId = {id}")
db.commit()
def reg_user():
userFlag = sql.execute(f"SELECT flag FROM users WHERE userId = '{id}'").fetchone()[0]
if userFlag == "newUser" and reseived_message == "Создать заявку":
zapros('getName')
write_message(id, "Напиши свое имя")
elif userFlag == "getName" and reseived_message == "Назад":
zapros('newUser')
write_message(id, "Вы вышли с регистрации")
elif userFlag == "getName" and reseived_message == "Отменить":
zapros('newUser')
write_message(id, "Вы вышли с регистрации")
elif userFlag == "getName":
zapros('getAge')
write_message(id, "Укажи возраст")
elif userFlag == "getAge" and reseived_message == "Назад":
zapros('getName')
write_message(id, "Напиши свое имя")
elif userFlag == "getAge" and reseived_message == "Отменить":
zapros('newUser')
write_message(id, "Вы вышли с регистрации")
elif userFlag == "getAge":
zapros('getCity')
write_message(id, "С какого ты города?")
elif userFlag == "getCity" and reseived_message == "Назад":
zapros('getAge')
write_message(id, "Укажи возраст")
elif userFlag == "getCity" and reseived_message == "Отменить":
zapros('newUser')
write_message(id, "Вы вышли с регистрации")
elif userFlag == "getCity":
zapros('getText')
write_message(id, "Укажи текст заявки")
elif userFlag == "getText" and reseived_message == "Назад":
zapros('getAge')
write_message(id, "Укажи возраст")
elif userFlag == "getText" and reseived_message == "Отменить":
zapros('newUser')
write_message(id, "Вы вышли с регистрации")
elif userFlag == "getText":
write_message(id, "Ваша заявка отправлена модератору")
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
reseived_message = event.text
id = event.user_id
sql.execute(f"SELECT userId FROM users WHERE userId = '{id}'")
if sql.fetchone() is None:
sql.execute("INSERT INTO users VALUES (?, ?, ?, ?, ?, ?)", (id, "newUser", "0", "0", "0", "0"))
write_message(id, "Привет, напиши Создать заявку")
else:
reg_user()
import vk_api
import sqlite3
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.utils import get_random_id
token = 'TOKEN'
authorize = vk_api.VkApi(token = token)
longpoll = VkLongPoll(authorize)
db = sqlite3.connect('action.db')
sql = db.cursor()
sql.execute("""CREATE TABLE IF NOT EXISTS users (
userId BIGINT,
flag TEXT,
name TEXT,
age TEXT,
city TEXT,
text TEXT
)""")
db.commit()
userFlag = '0'
def write_message (id, message):
authorize.method('messages.send', {'user_id': id, 'message': message, 'random_id': get_random_id()})
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
reseived_message = event.text
id = event.user_id
sql.execute(f"SELECT userId FROM users WHERE userId = '{id}'")
if sql.fetchone() is None:
sql.execute("INSERT INTO users VALUES (?, ?, ?, ?, ?, ?)", (id, "newUser", "0", "0", "0", "0"))
write_message(id, "Привет, напиши Создать заявку")
else:
userFlag = sql.execute(f"SELECT flag FROM users WHERE userId = '{id}'").fetchone()[0]
if userFlag == "newUser" and reseived_message == "Создать заявку":
sql.execute(f"UPDATE users SET flag = 'getName' WHERE userId = {id}")
db.commit()
write_message(id, "Напиши свое имя")
elif userFlag == "getName":
sql.execute(f"UPDATE users SET flag = 'getAge' WHERE userId = {id}")
db.commit()
write_message(id, "Укажи возраст")
elif userFlag == "getAge":
sql.execute(f"UPDATE users SET flag = 'getCity' WHERE userId = {id}")
db.commit()
write_message(id, "С какого ты города?")
elif userFlag == "getCity":
sql.execute(f"UPDATE users SET flag = 'getText' WHERE userId = {id}")
db.commit()
write_message(id, "Укажи текст заявки")
elif userFlag == "getText":
write_message(id, "Ваша заявка отправлена модератору")