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 |
|
---|
15 | from utils import normalize_username
|
---|
16 |
|
---|
17 |
|
---|
18 | def is_past(dt: datetime) -> bool:
|
---|
19 | return dt < datetime.today()
|
---|
20 |
|
---|
21 |
|
---|
22 | def has_finished_event(
|
---|
23 | context: ContextTypes.DEFAULT_TYPE,
|
---|
24 | username: str
|
---|
25 | ) -> bool:
|
---|
26 | events = context.chat_data["events"]
|
---|
27 | last_event = events[-1] if events != [] else None
|
---|
28 |
|
---|
29 | return last_event is not None and \
|
---|
30 | last_event["user"] == normalize_username(username) and \
|
---|
31 | is_past(last_event["when"])
|
---|
32 |
|
---|
33 |
|
---|
34 | def has_unfinished_event(context: ContextTypes.DEFAULT_TYPE) -> bool:
|
---|
35 | events = context.chat_data["events"]
|
---|
36 | last_event = events[-1] if events != [] else None
|
---|
37 |
|
---|
38 | return False if last_event is None else not is_past(last_event["when"])
|
---|