Changeset 6623428 in python-cinema-club-bot for commands


Ignore:
Timestamp:
Oct 9, 2024, 10:46:19 PM (5 weeks ago)
Author:
Mikhail Kirillov <w96k@…>
Branches:
master
Children:
9be02d9
Parents:
0d48ea2
git-author:
Mikhail Kirillov <w96k@…> (10/09/24 04:53:26)
git-committer:
Mikhail Kirillov <w96k@…> (10/09/24 22:46:19)
Message:

Add movies commands

Location:
commands
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • commands/__init__.py

    r0d48ea2 r6623428  
    1111
    1212from .meta import about
    13 from .users import set_users, add_users, list_users, remove_users, chooser_user
     13from .users import set_users, add_users, list_users, remove_users, \
     14    chooser_user, who_is_next
     15from .movie import movie, movies, remove_movies
  • commands/users.py

    r0d48ea2 r6623428  
    1515
    1616from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \
    17     EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE
    18 from utils import context_init
     17    EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE, ADD_MORE_USERS, \
     18    NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE
     19from utils import context_init, create_users_string
    1920
    2021
     
    5455    context_init(context)
    5556
    56     await update.message.reply_text(context.chat_data["users"])
     57    users = context.chat_data["users"]
     58
     59    await update.message.reply_markdown(create_users_string(users))
     60
     61
     62async def who_is_next(
     63        update: Update,
     64        context: ContextTypes.DEFAULT_TYPE
     65) -> None:
     66    context_init(context)
     67
     68    users = context.chat_data["users"]
     69
     70    if len(users) > 0:
     71        await update.message.reply_text(NEXT_MOVIE_USER.format(user=users[0]))
     72    else:
     73        await update.message.reply_text(ADD_MORE_USERS)
    5774
    5875
     
    92109    users = deque(context.chat_data["users"])
    93110
    94     chooser_index = users.index(chooser)
     111    try:
     112        chooser_index = users.index(chooser)
     113    except ValueError:
     114        raise error.TelegramError(USER_NOT_FOUND.format(user=chooser))
     115
    95116    users.rotate(-chooser_index)
     117    users = list(users)
    96118
    97     context.chat_data["users"] = list(users)
     119    context.chat_data["users"] = users
    98120
    99     await update.message.reply_text(context.chat_data["users"])
     121    await update.message.reply_text(USER_CHOOSE.format(user=users[0]))
     122
     123    await update.message.reply_markdown(create_users_string(users))
Note: See TracChangeset for help on using the changeset viewer.