0.1.7-beta
This commit is contained in:
@ -21,7 +21,12 @@ from typing import Union
|
||||
|
||||
# Local imports
|
||||
from config import token
|
||||
from constants import MAX_QUEUES_OWN, MAX_QUEUES_PARTS_IN, MAX_NAME_LENGTH, MAX_QUEUE_NAME_LENGTH
|
||||
from constants import (
|
||||
MAX_QUEUES_OWN,
|
||||
MAX_QUEUES_PARTS_IN,
|
||||
MAX_NAME_LENGTH,
|
||||
MAX_QUEUE_NAME_LENGTH,
|
||||
)
|
||||
import textbook
|
||||
import keyboards
|
||||
|
||||
@ -65,6 +70,7 @@ async def get_queue_from_state_data(call: types.CallbackQuery) -> Queue:
|
||||
return None
|
||||
return queue
|
||||
|
||||
|
||||
async def get_parting_queue_from_state_data(call: types.CallbackQuery) -> Queue:
|
||||
async with bot.retrieve_data(
|
||||
user_id=call.from_user.id, chat_id=call.message.chat.id
|
||||
@ -80,7 +86,9 @@ async def get_parting_queue_from_state_data(call: types.CallbackQuery) -> Queue:
|
||||
|
||||
|
||||
def get_first_queue_user(queue: Queue) -> Union[QueueUser, None]:
|
||||
arr = sorted(queue.users, key=lambda qu: qu.position) # TODO: Maybe there is a better solution..?
|
||||
arr = sorted(
|
||||
queue.users, key=lambda qu: qu.position
|
||||
) # TODO: Maybe there is a better solution..?
|
||||
return arr[0] if len(arr) else None
|
||||
|
||||
|
||||
@ -113,6 +121,7 @@ async def update_queue_users_message(msg: Message, queue: Queue):
|
||||
parse_mode="html",
|
||||
)
|
||||
|
||||
|
||||
def normalize_queue(queue: Queue) -> Queue:
|
||||
# first_user = get_first_queue_user(queue)
|
||||
# if first_user.position != 0:
|
||||
@ -123,6 +132,7 @@ def normalize_queue(queue: Queue) -> Queue:
|
||||
setattr(qu, "position", i)
|
||||
session.commit()
|
||||
|
||||
|
||||
# Basic
|
||||
|
||||
|
||||
@ -329,13 +339,18 @@ async def queue_parts_handler(call: types.CallbackQuery, queue_id: str = None):
|
||||
@bot.callback_query_handler(func=lambda c: c.data == "leave_queue")
|
||||
async def leave_queue_handler(call: types.CallbackQuery):
|
||||
if queue := await get_parting_queue_from_state_data(call):
|
||||
queueuser = session.query(QueueUser).filter_by(queue_id=queue.id, user_id=call.from_user.id).first()
|
||||
queueuser = (
|
||||
session.query(QueueUser)
|
||||
.filter_by(queue_id=queue.id, user_id=call.from_user.id)
|
||||
.first()
|
||||
)
|
||||
session.delete(queueuser)
|
||||
session.commit()
|
||||
normalize_queue(queue)
|
||||
await bot.answer_callback_query(
|
||||
callback_query_id=call.id,
|
||||
text=textbook.leaved_queue.format(name=queue.name))
|
||||
text=textbook.leaved_queue.format(name=queue.name),
|
||||
)
|
||||
await parts_queues_handler(call)
|
||||
return None
|
||||
await bot.answer_callback_query(callback_query_id=call.id)
|
||||
@ -444,7 +459,7 @@ async def start_queue_handler(call: types.CallbackQuery):
|
||||
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data == "kick_first")
|
||||
async def get_queue_users_handler(call: types.CallbackQuery):
|
||||
async def kick_first_handler(call: types.CallbackQuery):
|
||||
if queue := await get_queue_from_state_data(call):
|
||||
if queue.owner_id == call.from_user.id:
|
||||
if kick_first(queue):
|
||||
@ -478,7 +493,23 @@ async def swap_users_handler(call: types.CallbackQuery):
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data == "refresh_users")
|
||||
async def refresh_users_handler(call: types.CallbackQuery):
|
||||
await get_queue_users_handler(call)
|
||||
if queue := await get_queue_from_state_data(call):
|
||||
try:
|
||||
users_str = "\n".join(
|
||||
[f"{qu.position}. {qu.user.name}" for qu in queue.users]
|
||||
)
|
||||
await bot.edit_message_text(
|
||||
chat_id=call.message.chat.id,
|
||||
message_id=call.message.id,
|
||||
text=textbook.queue_users_list.format(
|
||||
name=queue.name, users_str=users_str
|
||||
),
|
||||
reply_markup=keyboards.queue_users(queue.id),
|
||||
parse_mode="html",
|
||||
)
|
||||
except:
|
||||
await asyncio.sleep(2)
|
||||
await bot.answer_callback_query(callback_query_id=call.id)
|
||||
|
||||
|
||||
# Queue settings
|
||||
@ -529,6 +560,15 @@ async def update_queue_name(msg: Message):
|
||||
)
|
||||
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data == "edit_queue_description")
|
||||
async def edit_queue_description_handler(call: types.CallbackQuery):
|
||||
await bot.answer_callback_query(
|
||||
callback_query_id=call.id,
|
||||
text=textbook.in_development_plug,
|
||||
show_alert=True,
|
||||
)
|
||||
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data == "delete_queue_approve")
|
||||
async def delete_queue_approve_handler(call: types.CallbackQuery):
|
||||
await bot.edit_message_text(
|
||||
@ -597,11 +637,32 @@ async def update_queue_name(msg: Message):
|
||||
|
||||
|
||||
@bot.message_handler(commands=["mystate"])
|
||||
async def mystate(msg):
|
||||
async def mystate(msg: Message):
|
||||
state = await bot.get_state(user_id=msg.from_user.id)
|
||||
await bot.send_message(chat_id=msg.from_user.id, text=state)
|
||||
|
||||
|
||||
@bot.message_handler(commands=["chatid"])
|
||||
async def chatid(msg: Message):
|
||||
await bot.send_message(chat_id=msg.chat.id, text=msg.chat.id)
|
||||
|
||||
|
||||
@bot.message_handler(commands=["stats"])
|
||||
async def stats(msg: Message):
|
||||
users_count = session.query(User).count()
|
||||
queues_count = session.query(Queue).count()
|
||||
await bot.send_message(
|
||||
chat_id=msg.chat.id,
|
||||
text=textbook.stats.format(users_count=users_count, queues_count=queues_count),
|
||||
)
|
||||
|
||||
|
||||
@bot.message_handler(commands=["changelog"])
|
||||
async def changelog(msg: Message):
|
||||
with open("changelog.txt", "r") as file:
|
||||
await bot.send_message(chat_id=msg.chat.id, text=file.read(), parse_mode="html")
|
||||
|
||||
|
||||
# Launch
|
||||
|
||||
|
||||
|
||||
7
bot/app/changelog.txt
Normal file
7
bot/app/changelog.txt
Normal file
@ -0,0 +1,7 @@
|
||||
<b>v0.1.7-beta</b>
|
||||
- Поправлен баг с киком первого вместо обновления списка
|
||||
- Добавлены заглушки куда надо
|
||||
- /stats - статистика по боту
|
||||
|
||||
<b>v0.1.6-beta</b>
|
||||
- MVP бета-версия
|
||||
@ -26,7 +26,9 @@ joined_queue = "Ты присоединился к очереди <b>{name}</b>\
|
||||
error_joining_queue = "Ты не можешь присоединиться к очереди <b>{name}</b>, так как ты уже в ней состоишь или достигнут лимит очередей (8)!"
|
||||
max_participants_reached = "Очередь переполнена, подожди, пока кто-нибудь выйдет!"
|
||||
first_kicked = "Первый пользователь кикнут"
|
||||
kick_first_error = "Действие не выполнено, возможно вы уже вышли из очереди, или очередь пуста?"
|
||||
kick_first_error = (
|
||||
"Действие не выполнено, возможно вы уже вышли из очереди, или очередь пуста?"
|
||||
)
|
||||
|
||||
parts_queues_menu = "Ты принимаешь участие в {count} очереди/ей"
|
||||
part_queue = "Очередь <b>{name}</b>\n\nУчастники:\n{users_str}"
|
||||
@ -36,6 +38,8 @@ your_turn = "Наступил твой черед в одчереди <b>{name}<
|
||||
finished_turn = "Ты вышел из очереди {name}, удачи!"
|
||||
error_turn = "Внимание! Не удалось отправить сообщение следующему пользователю очереди {name}! По своему усмотрению ты можешь зайти и кикнуть его вручную"
|
||||
|
||||
stats = "Количество пользователей: {users_count}\nКоличество очередей: {queues_count}"
|
||||
|
||||
about = "Бот для очередей.\n\nРазработчик - ollyhearn.\nЯ всегда открыт для вопросов и предложений: @OllyHearn\n\nv0.1.6-beta"
|
||||
groups_plug = "Всем привет, я бот для очередей! В настоящее время идет активная разработка, так что я пока не могу полностью функционировать в группах, но вы всегда можете запустить меня в личном диалоге, создать очередь, и отправить ссылку на очередь сюда. Функционал будет доработан, а пока пользуйтесь мной в личке:\n\nhttps://t.me/queue_senko_bot"
|
||||
in_development_plug = "Функция в разработке ¯\_(ツ)_/¯"
|
||||
|
||||
Reference in New Issue
Block a user