another commit
This commit is contained in:
@ -38,7 +38,7 @@ class States(StatesGroup):
|
||||
|
||||
|
||||
def get_queue_stats_text(queue: Queue) -> str:
|
||||
s = f"Название: {queue.name}" f"Количество участников: {len(queue.users)}"
|
||||
s = textbook.queue_stats.format(name=queue.name, count=len(queue.users))
|
||||
return s
|
||||
|
||||
|
||||
@ -127,6 +127,7 @@ async def queue_handler(call: types.CallbackQuery, queue_id: str = None):
|
||||
message_id=call.message.id,
|
||||
text=get_queue_stats_text(queue),
|
||||
reply_markup=keyboards.queue_menu(),
|
||||
parse_mode="html",
|
||||
)
|
||||
await bot.answer_callback_query(callback_query_id=call.id)
|
||||
|
||||
@ -156,6 +157,7 @@ async def edit_queue_name_handler(call: types.CallbackQuery):
|
||||
reply_markup=keyboards.edit_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(
|
||||
@ -165,6 +167,38 @@ async def edit_queue_name_cancel_handler(call: types.CallbackQuery):
|
||||
await queue_handler(call, queue_id)
|
||||
|
||||
|
||||
@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
|
||||
)
|
||||
return None
|
||||
async with bot.retrieve_data(
|
||||
user_id=msg.from_user.id, chat_id=msg.chat.id
|
||||
) as state_data:
|
||||
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
|
||||
)
|
||||
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 asyncio.sleep(1)
|
||||
await bot.set_state(user_id=msg.from_user.id, state=States.default)
|
||||
await bot.send_message(
|
||||
chat_id=msg.chat.id,
|
||||
text=get_queue_stats_text(queue),
|
||||
reply_markup=keyboards.queue_menu(),
|
||||
parse_mode="html",
|
||||
)
|
||||
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data == "settings")
|
||||
async def settings(call: types.CallbackQuery):
|
||||
await bot.set_state(user_id=call.from_user.id, state=States.default)
|
||||
@ -176,9 +210,6 @@ async def settings(call: types.CallbackQuery):
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data == "edit_name")
|
||||
async def edit_name_handler(call: types.CallbackQuery):
|
||||
await bot.set_state(user_id=call.from_user.id, state=States.changing_name)
|
||||
|
||||
@ -43,6 +43,6 @@ def settings() -> keyboard:
|
||||
def edit_name() -> keyboard:
|
||||
return keyboard(
|
||||
keyboard=[
|
||||
[button(text="❌ Отмена", callback_data="settings")],
|
||||
[button(text="❌ Отмена", callback_data="cancel")],
|
||||
]
|
||||
)
|
||||
|
||||
@ -6,10 +6,12 @@ new_queue_created = (
|
||||
)
|
||||
queue_limit = "Ты достиг лимита очередей (4). Удали свои очереди, или воспользуйся другим аккаунтом!"
|
||||
my_queues_list = "У тебя {count} очередь/и/ей"
|
||||
queue_stats = "Название: <b>{name}</b>\nКоличество участников: <b>{count}</b>"
|
||||
error = "Произошла непредвиденная ошибка!"
|
||||
queue_operational_error = "Произошла ошибка! Либо вы не являетесь владельцем очереди, либо данные устарели и вам следует заново выбрать очередь в меню!"
|
||||
edit_queue_name = "Введи новое имя очереди, имя должно быть не длинее 40 символов и не должно содержать переносов строки"
|
||||
settings = "🛠 Меню настроек"
|
||||
edit_name = "Ты можешь поменять свое имя, которое будет отображаться в очередях. По умолчанию используется твое имя в Телеграме. Имя должно быть не длинее 40 символов и не иметь переносов строки. Пришли мне новое имя, или нажми кнопку \"❌ Отмена\""
|
||||
edit_name_success = "Имя изменено!"
|
||||
edit_queue_name_success = "Имя очереди изменено!"
|
||||
edit_name_error = "Новое имя не подходит под условия. Напиши подходящее, или нажми кнопку \"❌ Отмена\""
|
||||
|
||||
Reference in New Issue
Block a user