from aiogram import types
from main import *
from FSM import *
import config as con
import markup as mark
from aiogram.dispatcher import FSMContext
from sql import *
import time
def birthtime(data):
try:
time.strptime(data, '%m/%d/%Y')
return True
except:
return False
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
await bot.send_message(message.from_user.id, 'Добро пожаловать', reply_markup = mark.main)
@dp.callback_query_handler(text = 'btnstart', state = None)
async def request(callback: types.CallbackQuery):
await bot.answer_callback_query(callback.id)
usid = callback.message.chat.id
id = cursor.execute(f"SELECT user_id FROM users WHERE user_id = {usid}")
bid = cursor.fetchone()
if bid is None:
her_id = callback.message.chat.id
cursor.execute(f"INSERT INTO users (user_id) VALUES(?)", (her_id,))
connect.commit()
else:
pass
await callback.message.answer('Введите имя:')
await FSM.name.set()
@dp.message_handler(state = FSM.name)
async def request1(message: types.Message):
myname = message.chat.id
name = cursor.execute(f"SELECT name FROM users WHERE name = {myname}")
bname = cursor.fetchone()
if bname is None:
name_id = message.text
cursor.execute(f"INSERT INTO users (name) VALUES(?)", (name_id,))
connect.commit()
await FSM.surname.set()
await message.answer('Введите фамилию:')
@dp.message_handler(state = FSM.surname)
async def request2(message: types.Message):
mysurname = message.chat.id
surname = cursor.execute(f"SELECT surname FROM users WHERE surname = {mysurname}")
sname = cursor.fetchone()
if sname is None:
sname_id = message.text
cursor.execute(f"INSERT INTO users (surname) VALUES(?)", (sname_id,))
connect.commit()
await FSM.birthday.set()
await message.answer('Введите дату рождения в формате 00/00/0000:')
@dp.message_handler(state = FSM.birthday)
async def request3(message: types.Message):
if birthtime(message.text):
mybirth = message.chat.id
timedata = cursor.execute(f"SELECT birthtime FROM users WHERE birthtime = {mybirth}")
time = cursor.fetchone()
if time is None:
btime = message.text
cursor.execute(f"INSERT INTO users (birthtime) VALUES(?)", (btime,))
connect.commit()
await FSM.descrip.set()
await message.answer('Расскажите немного о себе:')
@dp.message_handler(state = FSM.descrip)
async def request4(message: types.Message, state = FSMContext):
mydesc = message.chat.id
des = cursor.execute(f"SELECT description FROM users WHERE description = {mydesc}")
descrip = cursor.fetchone()
if descrip is None:
des_id = message.text
cursor.execute(f"INSERT INTO users (description) VALUES(?)", (des_id,))
connect.commit()
await state.finish()
await message.answer('Заявка успешно подана')
@dp.message_handler(commands=['viewall'])
async def viewall(message: types.Message):
if message.chat.id == con.admin_id:
await message.answer('Все заявки: \n')
view = cursor.execute(f"SELECT user_id, name, surname, birthtime, description FROM users").fetchall()
if view:
for all in view:
stroka = 'ID: '+ str(all[0]) + '\nИмя: '+ str(all[1]) + '\nФамилия: '+ str(all[2]) + '\nДата рождения: '+ str(all[3]) + '\nКраткое описание: ' + str(all[4])
await message.answer(stroka)