Changeset 0d48ea2
- Timestamp:
- Oct 9, 2024, 3:40:27 AM (5 weeks ago)
- Branches:
- master
- Children:
- 6623428
- Parents:
- cc34991
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
commands/__init__.py
rcc34991 r0d48ea2 11 11 12 12 from .meta import about 13 from .users import add_users, list_users, remove_users, chooser_user13 from .users import set_users, add_users, list_users, remove_users, chooser_user -
commands/users.py
rcc34991 r0d48ea2 14 14 from collections import deque 15 15 16 from strings import USER_NOT_PROVIDED, USER_ADDED, USER_REMOVED, EXPECTED_ONE_USER 16 from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \ 17 EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE 17 18 from utils import context_init 18 19 19 from rich import inspect20 20 21 async def set_users( 22 update: Update, 23 context: ContextTypes.DEFAULT_TYPE 24 ) -> None: 25 context_init(context) 26 27 if context.args == []: 28 raise error.TelegramError(USER_NOT_PROVIDED) 29 30 context.chat_data["users"] = context.args 31 32 await update.message.reply_text(USER_SET) 21 33 22 34 async def add_users( … … 27 39 28 40 if context.args == []: 29 await update.message.reply_text(USER_NOT_PROVIDED)30 41 raise error.TelegramError(USER_NOT_PROVIDED) 31 42 32 43 for user in context.args: 33 44 context.chat_data["users"].append(user) 34 await update.message.reply_text(USER_ADD ED.format(user=user))45 await update.message.reply_text(USER_ADD.format(user=user)) 35 46 36 await update.message.reply_text( context.chat_data["users"])47 await update.message.reply_text(USERS_ADDED) 37 48 38 49 … … 53 64 54 65 if context.args == []: 55 await update.message.reply_text(USER_NOT_PROVIDED)56 66 raise error.TelegramError(USER_NOT_PROVIDED) 57 67 … … 62 72 63 73 context.chat_data["users"].remove(user) 64 await update.message.reply_text(USER_REMOVE D.format(user=user))74 await update.message.reply_text(USER_REMOVE.format(user=user)) 65 75 66 await update.message.reply_text( context.chat_data["users"])76 await update.message.reply_text(USERS_REMOVED) 67 77 68 78 … … 74 84 75 85 if context.args == []: 76 await update.message.reply_text(USER_NOT_PROVIDED)77 86 raise error.TelegramError(USER_NOT_PROVIDED) 78 87 79 88 if len(context.args) > 1: 80 await update.message.reply_text(EXPECTED_ONE_USER)81 89 raise error.TelegramError(EXPECTED_ONE_USER) 82 90 … … 89 97 context.chat_data["users"] = list(users) 90 98 91 await update.message.reply_text(context.chat_data )99 await update.message.reply_text(context.chat_data["users"]) -
main.py
rcc34991 r0d48ea2 36 36 ) 37 37 38 async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> None: 39 logging.error("Exception:", exc_info=context.error) 40 41 await context.bot.send_message( 42 chat_id=update.effective_chat.id, 43 text=context.error.message 44 ) 38 45 39 46 if __name__ == "__main__": … … 42 49 ).persistence(Persistence).build() 43 50 51 # Meta commands 44 52 app.add_handler(CommandHandler("about", commands.about)) 53 54 # Movie commands 55 app.add_handler(CommandHandler("set", commands.set_users)) 45 56 app.add_handler(CommandHandler("add", commands.add_users)) 46 57 app.add_handler(CommandHandler("list", commands.list_users)) … … 48 59 app.add_handler(CommandHandler("chooser", commands.chooser_user)) 49 60 61 app.add_handler(MessageHandler(filters.COMMAND, unknown)) 62 app.add_error_handler(error_handler) 50 63 51 app.add_handler(MessageHandler(filters.COMMAND, unknown))52 64 53 65 app.run_polling() 66 -
strings.py
rcc34991 r0d48ea2 10 10 # <http://creativecommons.org/publicdomain/zero/1.0/> 11 11 12 INVALID_COMMAND = "Invalid command. Available commands: /add "12 INVALID_COMMAND = "Invalid command. Available commands: /add /list /remove /chooser /about" 13 13 USER_NOT_PROVIDED = "User(s) is not provided" 14 14 EXPECTED_ONE_USER = "Expected only one user" 15 USER_ADDED = "User {user} has been added" 16 USER_REMOVED = "User {user} has been removed" 15 USER_ADD = "User {user} has been added" 16 USERS_ADDED = "Users have been added successfully. Use /list to view." 17 USER_REMOVE = "User {user} has been removed. Use /list to view." 18 USERS_REMOVED = "Users has been removed" 19 USER_SET = "Users have been set successfully. Use /list to view." 20
Note:
See TracChangeset
for help on using the changeset viewer.