diff options
author | Mikhail Kirillov <w96k@runbox.com> | 2024-10-09 04:53:26 +0400 |
---|---|---|
committer | Mikhail Kirillov <w96k@runbox.com> | 2024-10-09 22:46:19 +0400 |
commit | 662342863e37e8661f818218df7bb72bc18bf4eb (patch) | |
tree | 79ff9b3884a36e7afec820a8b7c3f235f2e6f1f1 /commands/users.py | |
parent | 0d48ea28aeb8a6290d2aeab202efa9c8d6e30fe3 (diff) |
Add movies commands
Diffstat (limited to 'commands/users.py')
-rw-r--r-- | commands/users.py | 36 |
1 files changed, 30 insertions, 6 deletions
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)) |