summaryrefslogtreecommitdiff
path: root/predicates.py
diff options
context:
space:
mode:
authorMikhail Kirillov <w96k@runbox.com>2024-10-11 01:53:24 +0400
committerMikhail Kirillov <w96k@runbox.com>2024-10-11 01:53:24 +0400
commit69dd60cc024063daf1591168a64a32e771bd7f1b (patch)
tree9af211858513072175e5611a15e47012b34f349c /predicates.py
parent694d823d4d46ec2914f6e210f8903887e4a72d79 (diff)
Task #30. Allow anyone create or edit upcoming event
Diffstat (limited to 'predicates.py')
-rw-r--r--predicates.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/predicates.py b/predicates.py
index c341ccf..07b84d7 100644
--- a/predicates.py
+++ b/predicates.py
@@ -11,28 +11,44 @@
from telegram.ext import ContextTypes
from datetime import datetime
+from typing import Optional
-from utils import normalize_username
+def is_past(dt: Optional[datetime]) -> bool:
+ if dt is None:
+ return False
-def is_past(dt: datetime) -> bool:
return dt < datetime.today()
-def has_finished_event(
- context: ContextTypes.DEFAULT_TYPE,
- username: str
-) -> bool:
+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_event["user"] == normalize_username(username) and \
+ 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
- return False if last_event is None else not is_past(last_event["when"])
+ if last_event is None:
+ return False
+
+ if last_event["movie"] is None:
+ return False
+
+ return not is_past(last_event["when"])
+