Changeset 9be02d9 in python-cinema-club-bot for commands/users.py


Ignore:
Timestamp:
Oct 10, 2024, 4:12:00 AM (5 weeks ago)
Author:
Mikhail Kirillov <w96k@…>
Branches:
master
Children:
8d2d5ac
Parents:
6623428
Message:

Fix #9. Add events commands

File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands/users.py

    r6623428 r9be02d9  
    1616from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \
    1717    EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE, ADD_MORE_USERS, \
    18     NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE
    19 from utils import context_init, create_users_string
    20 
     18    NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE, NO_USERS, \
     19    EVENT_USER_HAD_EVENT
     20from utils import context_init, create_users_string, normalize_username, \
     21    choose_next_user
     22from predicates import has_finished_event
    2123
    2224async def set_users(
     
    3234
    3335    await update.message.reply_text(USER_SET)
     36
    3437
    3538async def add_users(
     
    5760    users = context.chat_data["users"]
    5861
    59     await update.message.reply_markdown(create_users_string(users))
     62    if users == []:
     63        await update.message.reply_text(NO_USERS)
     64    else:
     65        if has_finished_event(context, users[0]):
     66            users = context.chat_data["users"] = choose_next_user(users)
     67
     68        await update.message.reply_markdown(create_users_string(users))
    6069
    6170
     
    6473        context: ContextTypes.DEFAULT_TYPE
    6574) -> None:
     75    """
     76    This commands sets the next chooser if needed and shows current
     77    """
     78
    6679    context_init(context)
    6780
    6881    users = context.chat_data["users"]
    6982
    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)
     83    if users == []:
     84        raise error.TelegramError(ADD_MORE_USERS)
     85
     86    if has_finished_event(context, users[0]):
     87        users = context.chat_data["users"] = choose_next_user(users)
     88
     89    await update.message.reply_text(NEXT_MOVIE_USER.format(user=users[0]))
    7490
    7591
     
    119135    context.chat_data["users"] = users
    120136
     137    if has_finished_event(context, users[0]):
     138        await update.message.reply_text(
     139            EVENT_USER_HAD_EVENT.format(user=users[0])
     140        )
     141        users = context.chat_data["users"] = choose_next_user(users)
     142
    121143    await update.message.reply_text(USER_CHOOSE.format(user=users[0]))
    122144
Note: See TracChangeset for help on using the changeset viewer.