Changeset 69dd60c in python-cinema-club-bot for commands/users.py


Ignore:
Timestamp:
Oct 11, 2024, 1:53:24 AM (5 weeks ago)
Author:
Mikhail Kirillov <w96k@…>
Branches:
master
Children:
ac7b16a
Parents:
694d823
Message:

Task #30. Allow anyone create or edit upcoming event

File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands/users.py

    r694d823 r69dd60c  
    1717    EXPECTED_ONE_USER, USER_SET, USER_REMOVE, ADD_MORE_USERS, \
    1818    NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE, NO_USERS, \
    19     EVENT_USER_HAD_EVENT, NEXT_MOVIE
    20 from utils import context_init, create_users_string, choose_next_user
    21 from predicates import has_finished_event
     19    NEXT_MOVIE
     20from utils import context_init, create_users_string, choose_next_user, \
     21    normalize_username
     22from predicates import has_finished_movie, has_event_without_movie
    2223
    2324
     
    6162    if users == []:
    6263        await update.message.reply_text(NO_USERS)
    63     else:
    64         if has_finished_event(context, users[0]):
    65             users = context.chat_data["users"] = choose_next_user(users)
     64        return
    6665
    67         await update.message.reply_markdown(create_users_string(users))
     66    if has_finished_movie(context):
     67        users = context.chat_data["users"] = choose_next_user(context)
     68
     69    await update.message.reply_markdown(create_users_string(users))
    6870
    6971
     
    8385        raise error.TelegramError(ADD_MORE_USERS)
    8486
    85     if has_finished_event(context, users[0]):
    86         users = context.chat_data["users"] = choose_next_user(users)
     87    if has_finished_movie(context):
     88        users = context.chat_data["users"] = choose_next_user(context)
    8789
    8890    next_user_string = NEXT_MOVIE_USER.format(user=users[0])
    8991
    90     last_movie = context.chat_data["movies"][0] \
     92    last_movie = context.chat_data["movies"][-1] \
    9193        if context.chat_data["movies"] != [] else None
    9294
    93     if last_movie and last_movie["user"] == users[0]:
     95    if last_movie and last_movie["user"] == normalize_username(users[0]):
    9496        next_user_string += NEXT_MOVIE.format(movie=last_movie["title"])
    9597
     
    142144    context.chat_data["users"] = users
    143145
    144     if has_finished_event(context, users[0]):
    145         await update.message.reply_text(
    146             EVENT_USER_HAD_EVENT.format(user=users[0])
    147         )
    148         users = context.chat_data["users"] = choose_next_user(users)
     146    if has_finished_movie(context):
     147        users = context.chat_data["users"] = choose_next_user(context)
     148
     149    if has_event_without_movie(context):
     150        context.chat_data["events"][-1]["user"] = users[0]
    149151
    150152    await update.message.reply_text(USER_CHOOSE.format(user=users[0]))
Note: See TracChangeset for help on using the changeset viewer.