Changeset 23bddf3


Ignore:
Timestamp:
Oct 10, 2024, 6:20:52 AM (5 weeks ago)
Author:
Mikhail Kirillov <w96k@…>
Branches:
master
Children:
1f94544
Parents:
8d2d5ac
Message:

Task #10. /announce command

Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • commands/__init__.py

    r8d2d5ac r23bddf3  
    1515from .movie import movie, movies, remove_movies
    1616from .event import create_event, list_events
     17from .announce import create_announcement
     18
  • commands/event.py

    r8d2d5ac r23bddf3  
    7676    if events == [] or is_past(events[-1]["when"]):
    7777        events.append(event_dict)
    78         await update.message.reply_text(EVENT_CREATED.format(when=event_when))
     78        await update.message.reply_text(
     79            EVENT_CREATED.format(
     80                when=event_when,
     81                movie=event_dict["movie"],
     82            )
     83        )
    7984    else:
     85        old_when = events[-1]["when"]
     86        old_where = events[-1]["where"]
    8087        events[-1] = event_dict
    81         await update.message.reply_text(EVENT_EDITED.format(when=event_when))
     88
     89        await update.message.reply_text(
     90            EVENT_EDITED.format(
     91                old_when=old_when,
     92                old_where=old_where,
     93                when=event_when,
     94                where=event_where,
     95                movie=event_dict["movie"],
     96            )
     97        )
    8298
    8399
  • commands/meta.py

    r8d2d5ac r23bddf3  
    1212from telegram import Update
    1313from telegram.ext import ContextTypes
     14from subprocess import check_output
     15
     16from strings import ABOUT
     17
     18
     19VERSION="0.1"
     20
     21
     22def _get_commit_hash() -> str:
     23    return check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
     24
     25
     26def _get_commit_short_hash() -> str:
     27    return check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()
    1428
    1529
    1630async def about(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    17     await update.message.reply_text('''
    18 Version InDev
    19 
    20 python-cinema-club-bot is a bot for Telegram specialized for managing cinema club activities. This software is released as Public Domain using CC0 license.
    21 
    22 Project information: http://57.129.46.169/trac/wiki/python-cinema-club-bot
    23 Source code: http://57.129.46.169/cgit/python-cinema-club-bot/
    24 
    25 Contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>
    26 
    27 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.
    28 
    29 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see:
    30 <http://creativecommons.org/publicdomain/zero/1.0/>
    31 
    32     ''')
     31    await update.message.reply_text(
     32        ABOUT.format(
     33            version=VERSION,
     34            commit=_get_commit_short_hash(),
     35        )
     36    )
  • commands/users.py

    r8d2d5ac r23bddf3  
    1717    EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE, ADD_MORE_USERS, \
    1818    NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE, NO_USERS, \
    19     EVENT_USER_HAD_EVENT
    20 from utils import context_init, create_users_string, normalize_username, \
    21     choose_next_user
     19    EVENT_USER_HAD_EVENT, NEXT_MOVIE
     20from utils import context_init, create_users_string, choose_next_user
    2221from predicates import has_finished_event
     22
    2323
    2424async def set_users(
     
    8787        users = context.chat_data["users"] = choose_next_user(users)
    8888
    89     await update.message.reply_text(NEXT_MOVIE_USER.format(user=users[0]))
     89    next_user_string = NEXT_MOVIE_USER.format(user=users[0])
     90
     91    last_movie = context.chat_data["movies"][0] \
     92        if context.chat_data["movies"] != [] else None
     93
     94    if last_movie and last_movie["user"] == users[0]:
     95        next_user_string += NEXT_MOVIE.format(movie=last_movie["title"])
     96
     97    await update.message.reply_text(next_user_string)
    9098
    9199
  • main.py

    r8d2d5ac r23bddf3  
    5959    app.add_handler(CommandHandler("event", commands.create_event))
    6060    app.add_handler(CommandHandler("events", commands.list_events))
     61    app.add_handler(CommandHandler("announce", commands.create_announcement))
    6162
    6263    # Movie commands
     
    7071    app.add_handler(CommandHandler("list", commands.list_users))
    7172    app.add_handler(CommandHandler("users", commands.list_users))
     73    app.add_handler(CommandHandler("queue", commands.list_users))
    7274    app.add_handler(CommandHandler("remove", commands.remove_users))
    7375    app.add_handler(CommandHandler("chooser", commands.chooser_user))
  • predicates.py

    r8d2d5ac r23bddf3  
    3030        last_event["user"] == normalize_username(username) and \
    3131        is_past(last_event["when"])
     32
     33
     34def has_unfinished_event(context: ContextTypes.DEFAULT_TYPE) -> bool:
     35    events = context.chat_data["events"]
     36    last_event = events[-1] if events != [] else None
     37
     38    return False if last_event is None else not is_past(last_event["when"])
  • strings.py

    r8d2d5ac r23bddf3  
    2121MOVIE_SET = "Movie \"{title}\" proposed by {user} is succesfully set as next to watch"
    2222MOVIES_LIST = "\"{title}\" IMDB:{id} by {user} \n"
    23 NO_MOVIES = "No movies"
     23NO_MOVIES = "No movies.  You can add movie if you are next to choose (see /next). Too add a movie use /movie <imdb_id>"
    2424
    2525USER_NOT_FOUND = "Provided user ({user}) not found. Check /list"
     
    2828ADD_MORE_USERS = "There is no users added. You can add people who can choose movies using /add nickname"
    2929NEXT_MOVIE_USER = "Next movie choice is up to {user}"
     30NEXT_MOVIE = " and they have choosen to watch \"{movie}\""
    3031
    3132USER_ADD = "User {user} has been added"
     
    4142/event 1.08.2024/18:00 <where>
    4243"""
    43 EVENT_CANT_BE_IN_PAST = "Event can't happen in the past. You set {when}, but today is {today}"
     44EVENT_CANT_BE_IN_PAST = "Event can't happen in the past. You set {when}, but now is {today}"
    4445EVENT_ARGS_NOT_PROVIDED = """
    4546Event commands need arguments provided:
     
    5354"""
    5455
    55 EVENT_CREATED = "Event at {when} was created"
    56 EVENT_EDITED = "Event at {when} was modified"
     56EVENT_CREATED = "Event \"{movie}\" at {when} was created"
     57EVENT_EDITED = "Event \"{movie}\" at {old_when} in {old_where} was modified to {when} in {where}"
    5758EVENTS_LIST = "[{finished}] \"{movie}\" by {user} at {when} in {where}\n"
    5859EVENT_MOVIE_NOT_CHOOSEN = "You should choose a film first using /movie <imdb_id>"
    5960EVENT_MOVIE_NOT_SET = "<None>"
    6061EVENT_USER_HAD_EVENT = "User {user} have already finished event, so he can't choose twice. See /next or /list"
    61 NO_EVENTS = "No events"
     62NO_EVENTS = "No events."
    6263
    6364UNDEFINED_ERROR = "Exception: something unexpected happened. Check the logs."
     65
     66ANNOUNCEMENT_FINISHED_EVENT = "There is no planned events. Create one using /event <when> <where>"
     67ANNOUNCEMENT_TEMPLATE = """
     68{intro}
     69
     70Movie: {movie_title}
     71Choosen by: @{user}
     72Runtime: {movie_runtime} minutes
     73
     74When: {when}
     75Where: {where}
     76
     77Rating: {rating}
     78Genres: {genres}
     79
     80https://imdb.com/title/tt{movie_id}/
     81"""
     82
     83ABOUT = """
     84v{version} #{commit}
     85
     86python-cinema-club-bot is a bot for Telegram specialized for managing cinema club activities. This software is released as Public Domain using CC0 license.
     87
     88Project information: http://57.129.46.169/trac/wiki/python-cinema-club-bot
     89Source code: http://57.129.46.169/cgit/python-cinema-club-bot/
     90
     91Contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>
     92
     93To 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.
     94
     95You 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/>
     96    """
Note: See TracChangeset for help on using the changeset viewer.