From 5ba045c3ae59c3138d9585ea37f074bf1f06f094 Mon Sep 17 00:00:00 2001 From: Mikhail Kirillov Date: Thu, 10 Oct 2024 07:15:55 +0400 Subject: Add /announcement command Forgot to include this file :( --- commands/announce.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 commands/announce.py (limited to 'commands/announce.py') 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) + +# 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: +# + +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) -- cgit v1.2.3