source: python-cinema-club-bot/commands/announce.py@ 0239940

Last change on this file since 0239940 was 5ba045c, checked in by Mikhail Kirillov <w96k@…>, on Oct 10, 2024 at 7:15:55 AM

Add /announcement command

Forgot to include this file :(

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[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
12from telegram import Update, error
13from telegram.ext import ContextTypes
14
15from strings import ANNOUNCEMENT_TEMPLATE, ANNOUNCEMENT_FINISHED_EVENT
16from utils import context_init, create_users_string, choose_next_user
17from predicates import has_unfinished_event
18
19async 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)
Note: See TracBrowser for help on using the repository browser.