Changeset 69dd60c in python-cinema-club-bot for predicates.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
-
predicates.py
r694d823 r69dd60c 12 12 from telegram.ext import ContextTypes 13 13 from datetime import datetime 14 15 from utils import normalize_username 14 from typing import Optional 16 15 17 16 18 def is_past(dt: datetime) -> bool: 17 def is_past(dt: Optional[datetime]) -> bool: 18 if dt is None: 19 return False 20 19 21 return dt < datetime.today() 20 22 21 23 22 def has_finished_event( 23 context: ContextTypes.DEFAULT_TYPE, 24 username: str 25 ) -> bool: 24 def has_finished_movie(context: ContextTypes.DEFAULT_TYPE) -> bool: 25 events = context.chat_data["events"] 26 movies = context.chat_data["movies"] 27 28 last_event = events[-1] if events != [] else None 29 last_movie = movies[-1] if movies != [] else None 30 31 return last_event is not None and last_movie is not None and \ 32 last_event["user"] == last_movie["user"] and \ 33 is_past(last_event["when"]) 34 35 36 def has_event_without_movie(context: ContextTypes.DEFAULT_TYPE) -> bool: 26 37 events = context.chat_data["events"] 27 38 last_event = events[-1] if events != [] else None 28 39 29 return last_event is not None and \ 30 last_event["user"] == normalize_username(username) and \ 31 is_past(last_event["when"]) 40 return last_event and last_event["movie"] is None 32 41 33 42 … … 36 45 last_event = events[-1] if events != [] else None 37 46 38 return False if last_event is None else not is_past(last_event["when"]) 47 if last_event is None: 48 return False 49 50 if last_event["movie"] is None: 51 return False 52 53 return not is_past(last_event["when"]) 54
Note:
See TracChangeset
for help on using the changeset viewer.