Changeset 23bddf3 in python-cinema-club-bot for commands


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

Location:
commands
Files:
4 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
Note: See TracChangeset for help on using the changeset viewer.