- Timestamp:
- Oct 11, 2024, 1:53:24 AM (5 weeks ago)
- Branches:
- master
- Children:
- ac7b16a
- Parents:
- 694d823
- Location:
- commands
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
commands/announce.py
r694d823 r69dd60c 13 13 from telegram.ext import ContextTypes 14 14 15 from strings import ANNOUNCEMENT_TEMPLATE, ANNOUNCEMENT_FINISHED_EVENT 15 from strings import ANNOUNCEMENT_TEMPLATE, ANNOUNCEMENT_FINISHED_EVENT, \ 16 ANNOUNCEMENT_EVENT_NEEDS_EDITING 16 17 from utils import context_init, create_users_string, choose_next_user 17 18 from predicates import has_unfinished_event … … 32 33 last_movie = movies[-1] 33 34 34 genres = " #".join(last_movie["genres"]) 35 if last_event["when"] is None or last_event["where"] is None or last_event["movie"] is None: 36 raise error.TelegramError(ANNOUNCEMENT_EVENT_NEEDS_EDITING) 37 38 genres ="#" + " #".join(last_movie["genres"]) 35 39 36 40 await update.message.reply_markdown( -
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 == "": -
commands/movie.py
r694d823 r69dd60c 14 14 from imdb import Cinemagoer 15 15 16 from utils import context_init, choose_next_user 17 from predicates import has_finished_event 16 from utils import context_init, choose_next_user, normalize_username, \ 17 init_new_event 18 from predicates import has_finished_movie 18 19 from strings import MOVIE_NOT_PROVIDED, EXPECTED_ONE_MOVIE, \ 19 20 MOVIE_ANOTHER_USER, FETCHING_MOVIE, FETCHING_ERROR, \ … … 38 39 username = update.message.from_user.username 39 40 40 if has_finished_event(context, chooser): 41 users = context.chat_data["users"] = choose_next_user(users) 42 raise error.TelegramError(MOVIE_ANOTHER_USER.format(users[0])) 41 if has_finished_movie(context): 42 users = context.chat_data["users"] = choose_next_user(context) 43 43 44 44 if "@"+username != chooser: … … 64 64 id=movie.getID(), 65 65 user=update.effective_user.username, 66 poster=movie.data.get("cover url"),67 66 rating=movie.data.get("rating"), 68 67 genres=movie.data.get("genres"), … … 81 80 context.chat_data["events"][-1] = last_event 82 81 else: 82 init_new_event(context, users[0], movie_dict["title"]) 83 83 context.chat_data["movies"].append(movie_dict) 84 84 … … 101 101 movies_formatted += MOVIES_LIST.format( 102 102 title=movie["title"], 103 id=movie["id"],104 103 user=movie["user"] 105 104 ) -
commands/users.py
r694d823 r69dd60c 17 17 EXPECTED_ONE_USER, USER_SET, USER_REMOVE, ADD_MORE_USERS, \ 18 18 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 20 from utils import context_init, create_users_string, choose_next_user, \ 21 normalize_username 22 from predicates import has_finished_movie, has_event_without_movie 22 23 23 24 … … 61 62 if users == []: 62 63 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 66 65 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)) 68 70 69 71 … … 83 85 raise error.TelegramError(ADD_MORE_USERS) 84 86 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) 87 89 88 90 next_user_string = NEXT_MOVIE_USER.format(user=users[0]) 89 91 90 last_movie = context.chat_data["movies"][ 0] \92 last_movie = context.chat_data["movies"][-1] \ 91 93 if context.chat_data["movies"] != [] else None 92 94 93 if last_movie and last_movie["user"] == users[0]:95 if last_movie and last_movie["user"] == normalize_username(users[0]): 94 96 next_user_string += NEXT_MOVIE.format(movie=last_movie["title"]) 95 97 … … 142 144 context.chat_data["users"] = users 143 145 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] 149 151 150 152 await update.message.reply_text(USER_CHOOSE.format(user=users[0]))
Note:
See TracChangeset
for help on using the changeset viewer.