1 | # This file is part of python-cinema-club-bot
|
---|
2 | # contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>
|
---|
3 |
|
---|
4 | # To the extent possible under law, the author(s) have dedicated all copyright
|
---|
5 | # and related and neighboring rights to this software to the public domain
|
---|
6 | # worldwide. This software is distributed without any warranty.
|
---|
7 |
|
---|
8 | # You should have received a copy of the CC0 Public Domain Dedication along
|
---|
9 | # with this software. If not, see:
|
---|
10 | # <http://creativecommons.org/publicdomain/zero/1.0/>
|
---|
11 |
|
---|
12 | from telegram.ext import ContextTypes
|
---|
13 | from datetime import datetime
|
---|
14 | from typing import Optional
|
---|
15 |
|
---|
16 |
|
---|
17 | def is_past(dt: Optional[datetime]) -> bool:
|
---|
18 | if dt is None:
|
---|
19 | return False
|
---|
20 |
|
---|
21 | return dt < datetime.today()
|
---|
22 |
|
---|
23 |
|
---|
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:
|
---|
37 | events = context.chat_data["events"]
|
---|
38 | last_event = events[-1] if events != [] else None
|
---|
39 |
|
---|
40 | return last_event and last_event["movie"] is None
|
---|
41 |
|
---|
42 |
|
---|
43 | def has_unfinished_event(context: ContextTypes.DEFAULT_TYPE) -> bool:
|
---|
44 | events = context.chat_data["events"]
|
---|
45 | last_event = events[-1] if events != [] else None
|
---|
46 |
|
---|
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 |
|
---|