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

Last change on this file since ac7b16a was 69dd60c, checked in by Mikhail Kirillov <w96k@…>, on Oct 11, 2024 at 1:53:24 AM

Task #30. Allow anyone create or edit upcoming event

  • Property mode set to 100644
File size: 1.6 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
[69dd60c]14from typing import Optional
[9be02d9]15
16
[69dd60c]17def is_past(dt: Optional[datetime]) -> bool:
18 if dt is None:
19 return False
[9be02d9]20
21 return dt < datetime.today()
22
23
[69dd60c]24def has_finished_movie(context: ContextTypes.DEFAULT_TYPE) -> bool:
[9be02d9]25 events = context.chat_data["events"]
[69dd60c]26 movies = context.chat_data["movies"]
27
[9be02d9]28 last_event = events[-1] if events != [] else None
[69dd60c]29 last_movie = movies[-1] if movies != [] else None
[9be02d9]30
[69dd60c]31 return last_event is not None and last_movie is not None and \
32 last_event["user"] == last_movie["user"] and \
[9be02d9]33 is_past(last_event["when"])
[23bddf3]34
35
[69dd60c]36def 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
[23bddf3]43def has_unfinished_event(context: ContextTypes.DEFAULT_TYPE) -> bool:
44 events = context.chat_data["events"]
45 last_event = events[-1] if events != [] else None
46
[69dd60c]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
Note: See TracBrowser for help on using the repository browser.