Changeset 6623428 in python-cinema-club-bot
- Timestamp:
- Oct 9, 2024, 10:46:19 PM (5 weeks ago)
- Branches:
- master
- Children:
- 9be02d9
- Parents:
- 0d48ea2
- git-author:
- Mikhail Kirillov <w96k@…> (10/09/24 04:53:26)
- git-committer:
- Mikhail Kirillov <w96k@…> (10/09/24 22:46:19)
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
commands/__init__.py
r0d48ea2 r6623428 11 11 12 12 from .meta import about 13 from .users import set_users, add_users, list_users, remove_users, chooser_user 13 from .users import set_users, add_users, list_users, remove_users, \ 14 chooser_user, who_is_next 15 from .movie import movie, movies, remove_movies -
commands/users.py
r0d48ea2 r6623428 15 15 16 16 from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \ 17 EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE 18 from utils import context_init 17 EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE, ADD_MORE_USERS, \ 18 NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE 19 from utils import context_init, create_users_string 19 20 20 21 … … 54 55 context_init(context) 55 56 56 await update.message.reply_text(context.chat_data["users"]) 57 users = context.chat_data["users"] 58 59 await update.message.reply_markdown(create_users_string(users)) 60 61 62 async def who_is_next( 63 update: Update, 64 context: ContextTypes.DEFAULT_TYPE 65 ) -> None: 66 context_init(context) 67 68 users = context.chat_data["users"] 69 70 if len(users) > 0: 71 await update.message.reply_text(NEXT_MOVIE_USER.format(user=users[0])) 72 else: 73 await update.message.reply_text(ADD_MORE_USERS) 57 74 58 75 … … 92 109 users = deque(context.chat_data["users"]) 93 110 94 chooser_index = users.index(chooser) 111 try: 112 chooser_index = users.index(chooser) 113 except ValueError: 114 raise error.TelegramError(USER_NOT_FOUND.format(user=chooser)) 115 95 116 users.rotate(-chooser_index) 117 users = list(users) 96 118 97 context.chat_data["users"] = list(users)119 context.chat_data["users"] = users 98 120 99 await update.message.reply_text(context.chat_data["users"]) 121 await update.message.reply_text(USER_CHOOSE.format(user=users[0])) 122 123 await update.message.reply_markdown(create_users_string(users)) -
main.py
r0d48ea2 r6623428 17 17 import logging 18 18 19 from strings import INVALID_COMMAND 19 from strings import INVALID_COMMAND, UNDEFINED_ERROR 20 20 from persistence import Persistence 21 21 import commands … … 39 39 logging.error("Exception:", exc_info=context.error) 40 40 41 error_message = context.error.message \ 42 if hasattr(context.error, "message") else UNDEFINED_ERROR 43 41 44 await context.bot.send_message( 42 45 chat_id=update.effective_chat.id, 43 text= context.error.message46 text=error_message 44 47 ) 45 48 … … 53 56 54 57 # Movie commands 58 app.add_handler(CommandHandler("movie", commands.movie)) 59 app.add_handler(CommandHandler("movies", commands.movies)) 60 app.add_handler(CommandHandler("movies_remove", commands.remove_movies)) 61 62 # Users commands 55 63 app.add_handler(CommandHandler("set", commands.set_users)) 56 64 app.add_handler(CommandHandler("add", commands.add_users)) … … 58 66 app.add_handler(CommandHandler("remove", commands.remove_users)) 59 67 app.add_handler(CommandHandler("chooser", commands.chooser_user)) 68 app.add_handler(CommandHandler("next", commands.who_is_next)) 60 69 61 70 app.add_handler(MessageHandler(filters.COMMAND, unknown)) -
requirements.txt
r0d48ea2 r6623428 1 1 python-dotenv==0.20.0 2 2 python-telegram-bot==21.6 3 cinemagoer==2023.5.1 -
strings.py
r0d48ea2 r6623428 11 11 12 12 INVALID_COMMAND = "Invalid command. Available commands: /add /list /remove /chooser /about" 13 14 MOVIE_ANOTHER_USER = "Movie should choose another user ({user})" 15 MOVIE_NOT_PROVIDED = "Movie is not provided" 16 MOVIE_NOT_FOUND = "Movie not found on IMDB" 17 EXPECTED_ONE_MOVIE = "Expected only one movie" 18 FETCHING_MOVIE = "Movie with ID {id} is being fetched: https://imdb.com/title/tt{id}/" 19 FETCHING_ERROR = "Couldn't fetch movie or it is not found. Provide IMDB id, for example: 0133093" 20 MOVIE_REMOVE = "Movie \"{title}\" with id {id} has been removed" 21 MOVIE_SET = "Movie \"{title}\" proposed by {user} is succesfully set as next to watch" 22 23 USER_NOT_FOUND = "Provided user ({user}) not found. Check /list" 13 24 USER_NOT_PROVIDED = "User(s) is not provided" 14 25 EXPECTED_ONE_USER = "Expected only one user" 26 ADD_MORE_USERS = "There is no users added. You can add people who can choose movies using /add nickname" 27 NEXT_MOVIE_USER = "Next movie choice is up to {user}" 28 15 29 USER_ADD = "User {user} has been added" 16 30 USERS_ADDED = "Users have been added successfully. Use /list to view." 31 17 32 USER_REMOVE = "User {user} has been removed. Use /list to view." 18 33 USERS_REMOVED = "Users has been removed" 34 19 35 USER_SET = "Users have been set successfully. Use /list to view." 36 USER_CHOOSE = "Next movie should choose: {user}" 20 37 38 UNDEFINED_ERROR = "Exception: something unexpected happened. Check the logs." -
utils.py
r0d48ea2 r6623428 14 14 15 15 def context_init(context: ContextTypes.DEFAULT_TYPE): 16 '''16 """ 17 17 Initialize chat context with starting values 18 '''18 """ 19 19 20 20 if "users" not in context.chat_data: 21 21 context.chat_data["users"]: list[str] = [] 22 22 23 if "movies" not in context.chat_data: 24 context.chat_data["movies"]: list[dict] = [] 25 23 26 return context 27 28 29 def normalize_username(username: str): 30 return username.replace("@", "") 31 32 33 def create_users_string(users: list[str]) -> str: 34 return "`" + ", ".join(users) + "`"
Note:
See TracChangeset
for help on using the changeset viewer.