about+black

This commit is contained in:
2023-06-08 21:56:48 +03:00
parent 460bb84b76
commit a9ec3a29a9
3 changed files with 36 additions and 23 deletions

View File

@ -61,7 +61,9 @@ async def start(msg: Message):
pass
else:
await bot.send_message(
chat_id=msg.chat.id, text=textbook.menu.format(name=user.name), reply_markup=keyboards.menu()
chat_id=msg.chat.id,
text=textbook.menu.format(name=user.name),
reply_markup=keyboards.menu(),
)
@ -76,6 +78,7 @@ async def to_menu_handler(call: types.CallbackQuery):
reply_markup=keyboards.menu(),
)
@bot.callback_query_handler(func=lambda c: c.data == "new_queue")
async def new_queue_handler(call: types.CallbackQuery):
user = session.query(User).filter_by(id=call.from_user.id).first()
@ -114,9 +117,7 @@ async def queue_handler(call: types.CallbackQuery, queue_id: str = None):
queue_id = call.data[2:] if not queue_id else queue_id
queue = session.query(Queue).filter_by(id=queue_id).first()
if not queue:
await bot.answer_callback_query(
callback_query_id=call.id, text=textbook.error
)
await bot.answer_callback_query(callback_query_id=call.id, text=textbook.error)
return None
async with bot.retrieve_data(
user_id=call.from_user.id, chat_id=call.message.chat.id
@ -158,7 +159,9 @@ async def edit_queue_name_handler(call: types.CallbackQuery):
)
@bot.callback_query_handler(func=lambda c: c.data == "cancel", state=States.changing_queue_name)
@bot.callback_query_handler(
func=lambda c: c.data == "cancel", state=States.changing_queue_name
)
async def edit_queue_name_cancel_handler(call: types.CallbackQuery):
async with bot.retrieve_data(
user_id=call.from_user.id, chat_id=call.message.chat.id
@ -170,9 +173,7 @@ async def edit_queue_name_cancel_handler(call: types.CallbackQuery):
@bot.message_handler(content_types=["text"], state=States.changing_queue_name)
async def update_queue_name(msg: Message):
if len(msg.text) > 40 or "\n" in msg.text:
await bot.send_message(
chat_id=msg.chat.id, text=textbook.edit_name_error
)
await bot.send_message(chat_id=msg.chat.id, text=textbook.edit_name_error)
return None
async with bot.retrieve_data(
user_id=msg.from_user.id, chat_id=msg.chat.id
@ -180,15 +181,11 @@ async def update_queue_name(msg: Message):
queue_id = state_data.get("queue_id", None)
queue = session.query(Queue).filter_by(id=queue_id).first()
if not queue:
await bot.send_message(
chat_id=msg.chat.id, text=textbook.edit_name_error
)
await bot.send_message(chat_id=msg.chat.id, text=textbook.edit_name_error)
return None
setattr(queue, "name", msg.text)
session.commit()
await bot.send_message(
chat_id=msg.chat.id, text=textbook.edit_queue_name_success
)
await bot.send_message(chat_id=msg.chat.id, text=textbook.edit_queue_name_success)
await asyncio.sleep(1)
await bot.set_state(user_id=msg.from_user.id, state=States.default)
await bot.send_message(
@ -221,7 +218,9 @@ async def edit_name_handler(call: types.CallbackQuery):
)
@bot.callback_query_handler(func=lambda c: c.data == "cancel", state=States.changing_name)
@bot.callback_query_handler(
func=lambda c: c.data == "cancel", state=States.changing_name
)
async def edit_name_cancel_handler(call: types.CallbackQuery):
await settings(call)
@ -229,19 +228,16 @@ async def edit_name_cancel_handler(call: types.CallbackQuery):
@bot.message_handler(content_types=["text"], state=States.changing_name)
async def update_name(msg: Message):
if len(msg.text) > 40 or "\n" in msg.text:
await bot.send_message(
chat_id=msg.chat.id, text=textbook.edit_name_error
)
await bot.send_message(chat_id=msg.chat.id, text=textbook.edit_name_error)
return None
user = session.query(User).filter_by(id=msg.from_user.id).first()
setattr(user, "name", msg.text)
session.commit()
await bot.send_message(
chat_id=msg.chat.id, text=textbook.edit_name_success
)
await bot.send_message(chat_id=msg.chat.id, text=textbook.edit_name_success)
await asyncio.sleep(1)
await start(msg)
@bot.message_handler(commands=["take_part"])
async def tp(msg: Message):
try:
@ -271,12 +267,22 @@ async def q(msg: Message):
else:
await bot.send_message(chat_id=msg.chat.id, text="Очередь не найдена!")
@bot.message_handler(commands=["mystate"])
async def mystate(msg):
state = await bot.get_state(user_id=msg.from_user.id)
await bot.send_message(chat_id=msg.from_user.id, text=state)
@bot.callback_query_handler(func=lambda c: c.data == "about")
async def about_handler(call: types.CallbackQuery):
await bot.answer_callback_query(
callback_query_id=call.id,
text=textbook.about,
show_alert=True,
)
async def main():
a = asyncio.create_task(bot.polling(non_stop=True))
await a