Changeset 69dd60c in python-cinema-club-bot for commands/event.py
- Timestamp:
- Oct 11, 2024, 1:53:24 AM (5 weeks ago)
- Branches:
- master
- Children:
- ac7b16a
- Parents:
- 694d823
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
commands/event.py
r694d823 r69dd60c 14 14 from datetime import datetime 15 15 16 from utils import context_init 17 from predicates import is_past, has_finished_ event16 from utils import context_init, normalize_username 17 from predicates import is_past, has_finished_movie, has_event_without_movie 18 18 from strings import EVENT_ARGS_NOT_PROVIDED, EVENT_INVALID_DATETIME, \ 19 19 EVENT_CREATED, EVENT_EDITED, EVENT_CANT_BE_IN_PAST, \ 20 20 EVENT_WHERE_NOT_PROVIDED, EVENT_MOVIE_NOT_CHOOSEN, EVENTS_LIST, \ 21 EVENT_ USER_HAD_EVENT, NO_EVENTS21 EVENT_FINISHED, NO_EVENTS, EVENTS_LIST_PLANNING, EVENTS_LIST_MOVIE_SET 22 22 23 23 … … 27 27 ) -> None: 28 28 context_init(context) 29 users = context.chat_data["users"] 29 30 events = context.chat_data["events"] 30 31 movies = context.chat_data["movies"] 31 32 32 username = update.message.from_user.username33 33 last_movie = movies[-1] if movies != [] else None 34 34 35 if has_finished_event(context, username):36 raise error.TelegramError(EVENT_ USER_HAD_EVENT)35 if last_movie is None: 36 raise error.TelegramError(EVENT_MOVIE_NOT_CHOOSEN) 37 37 38 if last_movie is None or last_movie["user"] != username:39 raise error.TelegramError(EVENT_ MOVIE_NOT_CHOOSEN)38 if has_finished_movie(context): 39 raise error.TelegramError(EVENT_FINISHED) 40 40 41 41 if context.args == []: … … 62 62 raise error.TelegramError(EVENT_WHERE_NOT_PROVIDED) 63 63 64 event_where = " ".join(arguments_where) 64 old_when = events[-2]["when"] if len(events) >= 2 else None 65 old_where = events[-2]["where"] if len(events) >= 2 else None 65 66 66 if event_where == "": 67 event_where = events[-1]["where"] 67 event_where = " ".join(arguments_where) if arguments_where != [] else old_where 68 68 69 69 event_dict = dict( … … 74 74 ) 75 75 76 if events == [] or is_past(events[-1]["when"]): 77 events.append(event_dict) 78 await update.message.reply_text( 79 EVENT_CREATED.format( 80 when=event_when, 81 movie=event_dict["movie"], 82 ) 76 events[-1] = event_dict 77 78 await update.message.reply_text( 79 EVENT_EDITED.format( 80 old_when=old_when, 81 old_where=old_where, 82 when=event_when, 83 where=event_where, 84 movie=event_dict["movie"], 83 85 ) 84 else: 85 old_when = events[-1]["when"] 86 old_where = events[-1]["where"] 87 events[-1] = event_dict 88 89 await update.message.reply_text( 90 EVENT_EDITED.format( 91 old_when=old_when, 92 old_where=old_where, 93 when=event_when, 94 where=event_where, 95 movie=event_dict["movie"], 96 ) 97 ) 86 ) 98 87 99 88 … … 104 93 context_init(context) 105 94 95 users = context.chat_data["users"] 106 96 events = context.chat_data["events"] 97 last_event = events[-1] if events != [] else None 98 99 if last_event and last_event["movie"] is None: 100 last_event["user"] = normalize_username(users[0]) 107 101 108 102 events_formatted: str = "" 109 103 110 104 for event in events: 111 event_ finished= "FINISHED" \105 event_status = "FINISHED" \ 112 106 if is_past(event["when"]) else "PLANNED" 113 107 114 events_formatted += EVENTS_LIST.format( 115 movie=event["movie"], 116 user=event["user"], 117 when=event["when"], 118 where=event["where"], 119 finished=event_finished 120 ) 108 if event["movie"] is None: 109 breakpoint() 110 event_status = "PLANNING" 111 events_formatted += EVENTS_LIST_PLANNING.format( 112 user=event["user"], 113 status=event_status 114 ) 115 elif event["when"] is None or event["where"] is None: 116 event_status = "PLANNING" 117 events_formatted += EVENTS_LIST_MOVIE_SET.format( 118 user=event["user"], 119 movie=event["movie"], 120 status=event_status 121 ) 122 else: 123 events_formatted += EVENTS_LIST.format( 124 movie=event["movie"], 125 user=event["user"], 126 when=event["when"], 127 where=event["where"], 128 status=event_status 129 ) 121 130 122 131 if events_formatted == "":
Note:
See TracChangeset
for help on using the changeset viewer.