diff options
-rw-r--r-- | commands/__init__.py | 2 | ||||
-rw-r--r-- | commands/event.py | 20 | ||||
-rw-r--r-- | commands/meta.py | 26 | ||||
-rw-r--r-- | commands/users.py | 16 | ||||
-rw-r--r-- | db | bin | 121 -> 0 bytes | |||
-rw-r--r-- | main.py | 2 | ||||
-rw-r--r-- | predicates.py | 7 | ||||
-rw-r--r-- | strings.py | 43 |
8 files changed, 94 insertions, 22 deletions
diff --git a/commands/__init__.py b/commands/__init__.py index 2e0e009..7081c89 100644 --- a/commands/__init__.py +++ b/commands/__init__.py @@ -14,3 +14,5 @@ from .users import set_users, add_users, list_users, remove_users, \ chooser_user, who_is_next from .movie import movie, movies, remove_movies from .event import create_event, list_events +from .announce import create_announcement + diff --git a/commands/event.py b/commands/event.py index 5a7bf69..e06ea83 100644 --- a/commands/event.py +++ b/commands/event.py @@ -75,10 +75,26 @@ async def create_event( if events == [] or is_past(events[-1]["when"]): events.append(event_dict) - await update.message.reply_text(EVENT_CREATED.format(when=event_when)) + await update.message.reply_text( + EVENT_CREATED.format( + when=event_when, + movie=event_dict["movie"], + ) + ) else: + old_when = events[-1]["when"] + old_where = events[-1]["where"] events[-1] = event_dict - await update.message.reply_text(EVENT_EDITED.format(when=event_when)) + + await update.message.reply_text( + EVENT_EDITED.format( + old_when=old_when, + old_where=old_where, + when=event_when, + where=event_where, + movie=event_dict["movie"], + ) + ) async def list_events( diff --git a/commands/meta.py b/commands/meta.py index c98e770..5a61a84 100644 --- a/commands/meta.py +++ b/commands/meta.py @@ -11,22 +11,26 @@ from telegram import Update from telegram.ext import ContextTypes +from subprocess import check_output +from strings import ABOUT -async def about(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: - await update.message.reply_text(''' -Version InDev -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. +VERSION="0.1" + -Project information: http://57.129.46.169/trac/wiki/python-cinema-club-bot -Source code: http://57.129.46.169/cgit/python-cinema-club-bot/ +def _get_commit_hash() -> str: + return check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip() -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. +def _get_commit_short_hash() -> str: + return check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() -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/> - ''') +async def about(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + await update.message.reply_text( + ABOUT.format( + version=VERSION, + commit=_get_commit_short_hash(), + ) + ) diff --git a/commands/users.py b/commands/users.py index 9dcc125..8808bf6 100644 --- a/commands/users.py +++ b/commands/users.py @@ -16,11 +16,11 @@ from collections import deque from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \ EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE, ADD_MORE_USERS, \ NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE, NO_USERS, \ - EVENT_USER_HAD_EVENT -from utils import context_init, create_users_string, normalize_username, \ - choose_next_user + EVENT_USER_HAD_EVENT, NEXT_MOVIE +from utils import context_init, create_users_string, choose_next_user from predicates import has_finished_event + async def set_users( update: Update, context: ContextTypes.DEFAULT_TYPE @@ -86,7 +86,15 @@ async def who_is_next( if has_finished_event(context, users[0]): users = context.chat_data["users"] = choose_next_user(users) - await update.message.reply_text(NEXT_MOVIE_USER.format(user=users[0])) + next_user_string = NEXT_MOVIE_USER.format(user=users[0]) + + last_movie = context.chat_data["movies"][0] \ + if context.chat_data["movies"] != [] else None + + if last_movie and last_movie["user"] == users[0]: + next_user_string += NEXT_MOVIE.format(movie=last_movie["title"]) + + await update.message.reply_text(next_user_string) async def remove_users( Binary files differ@@ -58,6 +58,7 @@ if __name__ == "__main__": # Event commands app.add_handler(CommandHandler("event", commands.create_event)) app.add_handler(CommandHandler("events", commands.list_events)) + app.add_handler(CommandHandler("announce", commands.create_announcement)) # Movie commands app.add_handler(CommandHandler("movie", commands.movie)) @@ -69,6 +70,7 @@ if __name__ == "__main__": app.add_handler(CommandHandler("add", commands.add_users)) app.add_handler(CommandHandler("list", commands.list_users)) app.add_handler(CommandHandler("users", commands.list_users)) + app.add_handler(CommandHandler("queue", commands.list_users)) app.add_handler(CommandHandler("remove", commands.remove_users)) app.add_handler(CommandHandler("chooser", commands.chooser_user)) app.add_handler(CommandHandler("next", commands.who_is_next)) diff --git a/predicates.py b/predicates.py index 992972d..c341ccf 100644 --- a/predicates.py +++ b/predicates.py @@ -29,3 +29,10 @@ def has_finished_event( return last_event is not None and \ last_event["user"] == normalize_username(username) and \ is_past(last_event["when"]) + + +def has_unfinished_event(context: ContextTypes.DEFAULT_TYPE) -> bool: + events = context.chat_data["events"] + last_event = events[-1] if events != [] else None + + return False if last_event is None else not is_past(last_event["when"]) @@ -20,13 +20,14 @@ FETCHING_ERROR = "Couldn't fetch movie or it is not found. Provide IMDB id, for MOVIE_REMOVE = "Movie \"{title}\" with id {id} has been removed" MOVIE_SET = "Movie \"{title}\" proposed by {user} is succesfully set as next to watch" MOVIES_LIST = "\"{title}\" IMDB:{id} by {user} \n" -NO_MOVIES = "No movies" +NO_MOVIES = "No movies. You can add movie if you are next to choose (see /next). Too add a movie use /movie <imdb_id>" USER_NOT_FOUND = "Provided user ({user}) not found. Check /list" USER_NOT_PROVIDED = "User(s) is not provided" EXPECTED_ONE_USER = "Expected only one user" ADD_MORE_USERS = "There is no users added. You can add people who can choose movies using /add nickname" NEXT_MOVIE_USER = "Next movie choice is up to {user}" +NEXT_MOVIE = " and they have choosen to watch \"{movie}\"" USER_ADD = "User {user} has been added" USERS_ADDED = "Users have been added successfully. Use /list to view." @@ -40,7 +41,7 @@ EVENT_INVALID_DATETIME = """ Can't parse provided datetime. It should comply template like this: /event 1.08.2024/18:00 <where> """ -EVENT_CANT_BE_IN_PAST = "Event can't happen in the past. You set {when}, but today is {today}" +EVENT_CANT_BE_IN_PAST = "Event can't happen in the past. You set {when}, but now is {today}" EVENT_ARGS_NOT_PROVIDED = """ Event commands need arguments provided: /event <when> <where> @@ -52,12 +53,44 @@ Second <where> argument is not provided and previous event doesn't has it. /event 1.08.2024/18:00 84 Erevan Str 1st entrance 7 floor 451 apartment """ -EVENT_CREATED = "Event at {when} was created" -EVENT_EDITED = "Event at {when} was modified" +EVENT_CREATED = "Event \"{movie}\" at {when} was created" +EVENT_EDITED = "Event \"{movie}\" at {old_when} in {old_where} was modified to {when} in {where}" EVENTS_LIST = "[{finished}] \"{movie}\" by {user} at {when} in {where}\n" EVENT_MOVIE_NOT_CHOOSEN = "You should choose a film first using /movie <imdb_id>" EVENT_MOVIE_NOT_SET = "<None>" EVENT_USER_HAD_EVENT = "User {user} have already finished event, so he can't choose twice. See /next or /list" -NO_EVENTS = "No events" +NO_EVENTS = "No events." UNDEFINED_ERROR = "Exception: something unexpected happened. Check the logs." + +ANNOUNCEMENT_FINISHED_EVENT = "There is no planned events. Create one using /event <when> <where>" +ANNOUNCEMENT_TEMPLATE = """ +{intro} + +Movie: {movie_title} +Choosen by: @{user} +Runtime: {movie_runtime} minutes + +When: {when} +Where: {where} + +Rating: {rating} +Genres: {genres} + +https://imdb.com/title/tt{movie_id}/ +""" + +ABOUT = """ +v{version} #{commit} + +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. + +Project information: http://57.129.46.169/trac/wiki/python-cinema-club-bot +Source code: http://57.129.46.169/cgit/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/> + """ |