[5ba045c] | 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 |
|
---|
| 12 | from telegram import Update, error
|
---|
| 13 | from telegram.ext import ContextTypes
|
---|
| 14 |
|
---|
| 15 | from strings import ANNOUNCEMENT_TEMPLATE, ANNOUNCEMENT_FINISHED_EVENT
|
---|
| 16 | from utils import context_init, create_users_string, choose_next_user
|
---|
| 17 | from predicates import has_unfinished_event
|
---|
| 18 |
|
---|
| 19 | async def create_announcement(
|
---|
| 20 | update: Update,
|
---|
| 21 | context: ContextTypes.DEFAULT_TYPE
|
---|
| 22 | ) -> None:
|
---|
| 23 | context_init(context)
|
---|
| 24 |
|
---|
| 25 | intro = " ".join(context.args)
|
---|
| 26 |
|
---|
| 27 | events = context.chat_data["events"]
|
---|
| 28 | movies = context.chat_data["movies"]
|
---|
| 29 |
|
---|
| 30 | if has_unfinished_event(context):
|
---|
| 31 | last_event = events[-1]
|
---|
| 32 | last_movie = movies[-1]
|
---|
| 33 |
|
---|
| 34 | genres = " #".join(last_movie["genres"])
|
---|
| 35 |
|
---|
| 36 | await update.message.reply_markdown(
|
---|
| 37 | ANNOUNCEMENT_TEMPLATE.format(
|
---|
| 38 | intro=intro,
|
---|
| 39 | movie_title=last_movie["title"],
|
---|
| 40 | movie_id=last_movie["id"],
|
---|
| 41 | movie_runtime=last_movie["runtime"][0],
|
---|
| 42 | when=last_event["when"],
|
---|
| 43 | where=last_event["where"],
|
---|
| 44 | user=last_movie["user"],
|
---|
| 45 | rating=last_movie["rating"],
|
---|
| 46 | genres=genres,
|
---|
| 47 | )
|
---|
| 48 | )
|
---|
| 49 |
|
---|
| 50 | return
|
---|
| 51 |
|
---|
| 52 | await update.message.reply_text(ANNOUNCEMENT_FINISHED_EVENT)
|
---|