summaryrefslogtreecommitdiff
path: root/commands/announce.py
diff options
context:
space:
mode:
authorMikhail Kirillov <w96k@runbox.com>2024-10-10 07:15:55 +0400
committerMikhail Kirillov <w96k@runbox.com>2024-10-10 07:15:55 +0400
commit5ba045c3ae59c3138d9585ea37f074bf1f06f094 (patch)
tree2585e9c5a27e355f828fb582bf39fa775780ce81 /commands/announce.py
parent1f94544ff6c9357b2911dfa5ca50f3e007963332 (diff)
Add /announcement command
Forgot to include this file :(
Diffstat (limited to 'commands/announce.py')
-rw-r--r--commands/announce.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/commands/announce.py b/commands/announce.py
new file mode 100644
index 0000000..733e8d8
--- /dev/null
+++ b/commands/announce.py
@@ -0,0 +1,52 @@
+# This file is part of python-cinema-club-bot
+# contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>
+
+# To the extent possible under law, the author(s) have dedicated all copyright
+# and related and neighboring rights to this software to the public domain
+# worldwide. This software is distributed without any warranty.
+
+# You should have received a copy of the CC0 Public Domain Dedication along
+# with this software. If not, see:
+# <http://creativecommons.org/publicdomain/zero/1.0/>
+
+from telegram import Update, error
+from telegram.ext import ContextTypes
+
+from strings import ANNOUNCEMENT_TEMPLATE, ANNOUNCEMENT_FINISHED_EVENT
+from utils import context_init, create_users_string, choose_next_user
+from predicates import has_unfinished_event
+
+async def create_announcement(
+ update: Update,
+ context: ContextTypes.DEFAULT_TYPE
+) -> None:
+ context_init(context)
+
+ intro = " ".join(context.args)
+
+ events = context.chat_data["events"]
+ movies = context.chat_data["movies"]
+
+ if has_unfinished_event(context):
+ last_event = events[-1]
+ last_movie = movies[-1]
+
+ genres = " #".join(last_movie["genres"])
+
+ await update.message.reply_markdown(
+ ANNOUNCEMENT_TEMPLATE.format(
+ intro=intro,
+ movie_title=last_movie["title"],
+ movie_id=last_movie["id"],
+ movie_runtime=last_movie["runtime"][0],
+ when=last_event["when"],
+ where=last_event["where"],
+ user=last_movie["user"],
+ rating=last_movie["rating"],
+ genres=genres,
+ )
+ )
+
+ return
+
+ await update.message.reply_text(ANNOUNCEMENT_FINISHED_EVENT)