Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from aiogram import types
- from aiogram.dispatcher.storage import FSMContext
- from aiogram.types import ReplyKeyboardRemove
- from sqlalchemy.dialects.postgresql import insert
- from sqlalchemy.future import select
- from button import actions_encryption
- from db import async_session, Key_table
- from func import create_key
- from loader import dp
- from middleware import get_lang
- from states import CreateKey
- # the main mechanism
- '''@anti_flood(1)
- @dp_c.message_handler(content_types='any')
- async def hi_tag(message):
- copy = message.to_python()
- await sleep(10)
- await message.answer(f'cope = message.to_python()' + f'\n{copy}')
- copy = types.Message.to_object(copy)
- await copy.copy_to(chat_id=message.chat.id)'''
- @dp.message_handler(commands=['key'])
- async def encryption(message: types.Message, state: FSMContext):
- await message.answer('Создаем типо ключ,тест #99493843213 :',
- reply_markup=actions_encryption[await get_lang(message)])
- count = message.text.split()[-1]
- try:
- count = int(count)
- except:
- count = 1
- await message.answer(f'{count}')
- await message.answer(isinstance(count, int))
- if count > 100:
- count = 100
- elif count < 1:
- count = 1
- while True:
- # Генерируем ключ
- key = await create_key()
- # Ищем ключ в базе
- async with async_session as session:
- result = await session.execute(select(Key_table.key).where(Key_table.key == key))
- # .scalar() возвращает None или первую запись с таким ключом
- result = result.scalar()
- # Если ключ найден,запускаем цикл с начала
- if result is not None:
- continue
- # Если ключ не найден,заносим в базу данных
- else:
- await message.answer('Tests')
- new_key = await session.execute(insert(Key_table).values(
- user_id=message.from_user,
- key=key,
- count=count,
- status=True
- ))
- await session.commit()
- break
- async with state.proxy() as data:
- data['key'] = key
- await message.answer(data['key'])
- await CreateKey.media_upload.set()
- # noinspection PyTypeChecker
- @dp.message_handler(state=CreateKey.media_upload, text=['🚫Cancel', '🚫Отмена'])
- async def cancel(message: types.Message, state: FSMContext):
- await state.finish()
- await message.answer('Completed', reply_markup=ReplyKeyboardRemove())
- # state 2
- @dp.message_handler(state=CreateKey.media_upload)
- async def media_upload(message, state: FSMContext):
- await message.answer('Слава великому Андрею,все работает!')
- # async with state.proxy() as data:
- # data['media_1'] = message.text
- # data['key'] = await create_key()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement