source: python-cinema-club-bot/predicates.py@ 5ba045c

Last change on this file since 5ba045c was 23bddf3, checked in by Mikhail Kirillov <w96k@…>, on Oct 10, 2024 at 6:20:52 AM

Task #10. /announce command

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[9be02d9]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
12from telegram.ext import ContextTypes
13from datetime import datetime
14
15from utils import normalize_username
16
17
18def is_past(dt: datetime) -> bool:
19 return dt < datetime.today()
20
21
22def 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"])
[23bddf3]32
33
34def 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"])
Note: See TracBrowser for help on using the repository browser.