diff options
Diffstat (limited to 'predicates.py')
-rw-r--r-- | predicates.py | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/predicates.py b/predicates.py index c341ccf..07b84d7 100644 --- a/predicates.py +++ b/predicates.py @@ -11,28 +11,44 @@ from telegram.ext import ContextTypes from datetime import datetime +from typing import Optional -from utils import normalize_username +def is_past(dt: Optional[datetime]) -> bool: + if dt is None: + return False -def is_past(dt: datetime) -> bool: return dt < datetime.today() -def has_finished_event( - context: ContextTypes.DEFAULT_TYPE, - username: str -) -> bool: +def has_finished_movie(context: ContextTypes.DEFAULT_TYPE) -> bool: events = context.chat_data["events"] + movies = context.chat_data["movies"] + last_event = events[-1] if events != [] else None + last_movie = movies[-1] if movies != [] else None - return last_event is not None and \ - last_event["user"] == normalize_username(username) and \ + return last_event is not None and last_movie is not None and \ + last_event["user"] == last_movie["user"] and \ is_past(last_event["when"]) +def has_event_without_movie(context: ContextTypes.DEFAULT_TYPE) -> bool: + events = context.chat_data["events"] + last_event = events[-1] if events != [] else None + + return last_event and last_event["movie"] is None + + def has_unfinished_event(context: ContextTypes.DEFAULT_TYPE) -> bool: events = context.chat_data["events"] last_event = events[-1] if events != [] else None - return False if last_event is None else not is_past(last_event["when"]) + if last_event is None: + return False + + if last_event["movie"] is None: + return False + + return not is_past(last_event["when"]) + |