blob: 07b84d7a33ea51b56c26dcaa74fe9b0e9d591628 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# This file is part of python-cinema-club-bot
# contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>
# 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:
# <http://creativecommons.org/publicdomain/zero/1.0/>
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"])
|