1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# 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, \
ANNOUNCEMENT_EVENT_NEEDS_EDITING
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]
if last_event["when"] is None or last_event["where"] is None or last_event["movie"] is None:
raise error.TelegramError(ANNOUNCEMENT_EVENT_NEEDS_EDITING)
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)
|