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

Last change on this file was 69dd60c, checked in by Mikhail Kirillov <w96k@…>, on Oct 11, 2024 at 1:53:24 AM

Task #30. Allow anyone create or edit upcoming event

  • Property mode set to 100644
File size: 1.9 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
[69dd60c]15from strings import ANNOUNCEMENT_TEMPLATE, ANNOUNCEMENT_FINISHED_EVENT, \
16 ANNOUNCEMENT_EVENT_NEEDS_EDITING
[5ba045c]17from utils import context_init, create_users_string, choose_next_user
18from predicates import has_unfinished_event
19
20async def create_announcement(
21 update: Update,
22 context: ContextTypes.DEFAULT_TYPE
23) -> None:
24 context_init(context)
25
26 intro = " ".join(context.args)
27
28 events = context.chat_data["events"]
29 movies = context.chat_data["movies"]
30
31 if has_unfinished_event(context):
32 last_event = events[-1]
33 last_movie = movies[-1]
34
[69dd60c]35 if last_event["when"] is None or last_event["where"] is None or last_event["movie"] is None:
36 raise error.TelegramError(ANNOUNCEMENT_EVENT_NEEDS_EDITING)
37
38 genres ="#" + " #".join(last_movie["genres"])
[5ba045c]39
40 await update.message.reply_markdown(
41 ANNOUNCEMENT_TEMPLATE.format(
42 intro=intro,
43 movie_title=last_movie["title"],
44 movie_id=last_movie["id"],
45 movie_runtime=last_movie["runtime"][0],
46 when=last_event["when"],
47 where=last_event["where"],
48 user=last_movie["user"],
49 rating=last_movie["rating"],
50 genres=genres,
51 )
52 )
53
54 return
55
56 await update.message.reply_text(ANNOUNCEMENT_FINISHED_EVENT)
Note: See TracBrowser for help on using the repository browser.