# This file is part of python-cinema-club-bot # contributed in 2024 by Mikhail Kirillov (~w96k) # To the extent possible under law, the author(s) have dedicated all copyright # and related and neighboring rights to this software to the public domain # worldwide. This software is distributed without any warranty. # You should have received a copy of the CC0 Public Domain Dedication along # with this software. If not, see: # from telegram.ext import ContextTypes from datetime import datetime from typing import Optional def is_past(dt: Optional[datetime]) -> bool: if dt is None: return False return dt < datetime.today() 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_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 if last_event is None: return False if last_event["movie"] is None: return False return not is_past(last_event["when"])