From 662342863e37e8661f818218df7bb72bc18bf4eb Mon Sep 17 00:00:00 2001 From: Mikhail Kirillov Date: Wed, 9 Oct 2024 04:53:26 +0400 Subject: Add movies commands --- commands/users.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'commands/users.py') diff --git a/commands/users.py b/commands/users.py index 413b681..497d7dd 100644 --- a/commands/users.py +++ b/commands/users.py @@ -14,8 +14,9 @@ from telegram.ext import ContextTypes from collections import deque from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \ - EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE -from utils import context_init + EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE, ADD_MORE_USERS, \ + NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE +from utils import context_init, create_users_string async def set_users( @@ -53,7 +54,23 @@ async def list_users( ) -> None: context_init(context) - await update.message.reply_text(context.chat_data["users"]) + users = context.chat_data["users"] + + await update.message.reply_markdown(create_users_string(users)) + + +async def who_is_next( + update: Update, + context: ContextTypes.DEFAULT_TYPE +) -> None: + context_init(context) + + users = context.chat_data["users"] + + if len(users) > 0: + await update.message.reply_text(NEXT_MOVIE_USER.format(user=users[0])) + else: + await update.message.reply_text(ADD_MORE_USERS) async def remove_users( @@ -91,9 +108,16 @@ async def chooser_user( chooser = context.args[0] users = deque(context.chat_data["users"]) - chooser_index = users.index(chooser) + try: + chooser_index = users.index(chooser) + except ValueError: + raise error.TelegramError(USER_NOT_FOUND.format(user=chooser)) + users.rotate(-chooser_index) + users = list(users) + + context.chat_data["users"] = users - context.chat_data["users"] = list(users) + await update.message.reply_text(USER_CHOOSE.format(user=users[0])) - await update.message.reply_text(context.chat_data["users"]) + await update.message.reply_markdown(create_users_string(users)) -- cgit v1.2.3