diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/announce.py | 52 |
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) |