{"id":17553530,"url":"https://github.com/ashokshau/ptbmod","last_synced_at":"2025-04-24T03:44:57.395Z","repository":{"id":257824496,"uuid":"872014928","full_name":"AshokShau/PtbMod","owner":"AshokShau","description":"Patch for python-telegram-bot providing decorator support for easy command handling and admin verification.","archived":false,"fork":false,"pushed_at":"2025-02-14T21:10:30.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T17:52:07.305Z","etag":null,"topics":["bot","monkey-patching","ptb","ptb-patch","ptbmod","python-telegram-bot","telegram"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AshokShau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-13T15:09:46.000Z","updated_at":"2025-03-03T13:33:38.000Z","dependencies_parsed_at":"2025-03-07T06:31:17.427Z","dependency_job_id":"4c026501-9c78-40e8-b973-3506c1f10550","html_url":"https://github.com/AshokShau/PtbMod","commit_stats":null,"previous_names":["ashokshau/ptbmod"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshokShau%2FPtbMod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshokShau%2FPtbMod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshokShau%2FPtbMod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshokShau%2FPtbMod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AshokShau","download_url":"https://codeload.github.com/AshokShau/PtbMod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250559866,"owners_count":21450168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","monkey-patching","ptb","ptb-patch","ptbmod","python-telegram-bot","telegram"],"created_at":"2024-10-21T06:42:44.916Z","updated_at":"2025-04-24T03:44:57.387Z","avatar_url":"https://github.com/AshokShau.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Ptbmod\n================\n\nA Python Patch for `python-telegram-bot` with Decorator Support\n---------------------------------------------------------\n\n### Overview\n\nPtbmod is a patch for the popular `python-telegram-bot` library that introduces decorator support for cleaner and more efficient handling of commands and messages within your Telegram bot applications.\n\n### Key Features\n\n* **Command and Message Handlers**: Simplify the process of registering command and message handlers with the `TelegramHandler`.\n* **Admin Decorators**: Easily check user permissions directly in your command functions with decorators like `@Admins` and `verify_anonymous_admin`.\n\n### Installation\n\nTo install ptbmod, run the following command:\n```bash\npip install ptbmod\n```\nOr, to install with additional dependencies:\n```bash\npip install ptbmod[all]\n```\n### Usage\n\nTo utilize the new decorators and handlers, follow these steps:\n\n1. Import the necessary modules:\n\n```python\nfrom ptbmod import TelegramHandler, verifyAnonymousAdmin, Admins\n```\n\n2. Create a `TelegramHandler` instance:\n```python\nCmd = TelegramHandler(application).command\nMsg = TelegramHandler(application).message\n```\n\n3. Define your bot commands and message handlers using the `Cmd` and `Msg` shortcuts:\n```python\n@Cmd(command=[\"start\", \"help\"])\n@Admins(is_both=True)\nasync def start(update: Update, context: ContextTypes.DEFAULT_TYPE):\n    # Command handler code here\n```\n### Example\n\nFor a complete example, see the [example code](#example) below.\n\n### Requirements\n\n* `python-telegram-bot`\n* `cachetools`\n* `python-dotenv`\n\n### License\n\nPtbmod is licensed under the [MIT License](/LICENSE).\n\n### Contributing\n\nContributions are welcome! Please submit a pull request with your changes.\n\n### Example\n\n```python\nimport logging\n\nfrom telegram import Message, Update\nfrom telegram.ext import ApplicationBuilder, ContextTypes, filters, CallbackQueryHandler, Defaults\n\nfrom ptbmod import TelegramHandler, verifyAnonymousAdmin, Admins\nfrom ptbmod.decorator.cache import is_admin\n\nlogging.basicConfig(\n    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n    level=logging.INFO\n)\nlogging.getLogger('httpx').setLevel(logging.WARNING)\n\napplication = (\n    ApplicationBuilder()\n    .token('TOKEN')\n    .arbitrary_callback_data(True)\n    .defaults(Defaults(allow_sending_without_reply=True))\n    .build()\n)\n\nCmd = TelegramHandler(application).command\nMsg = TelegramHandler(application).message\n\n\n@Cmd(command=[\"start\", \"help\"])\nasync def start(update: Update, context: ContextTypes.DEFAULT_TYPE):\n    \"\"\"\n    Send a message when the command /start or /help is issued.\n    \"\"\"\n    await context.bot.send_message(\n        chat_id=update.effective_chat.id,\n        text=\"Hello! I am a bot.\\nUse /kick to kick a user from the chat.\"\n    )\n\n\n@Cmd(command=[\"kick\"])\n@Admins(permissions=\"can_restrict_members\", is_both=True, allow_pm=False)\nasync def ban(update: Update, _: ContextTypes.DEFAULT_TYPE) -\u003e Message:\n    \"\"\"\n    Kick a user from the chat.\n    \"\"\"\n    msg = update.effective_message\n    reply = msg.reply_to_message\n    chat = update.effective_chat\n    if not reply:\n        return await msg.reply_text(\"Please reply to a user to kick them.\")\n    \n    user = reply.from_user\n    if await is_admin(chat.id, user.id):\n        return await msg.reply_text(\"You can't kick an admin.\")\n    \n    await chat.unban_member(user.id)\n    return await msg.reply_text(f\"Kicked user {user.full_name}\")\n\n\n@Msg(filters=filters.ChatType.PRIVATE \u0026 ~filters.COMMAND)\nasync def message(update: Update, context: ContextTypes.DEFAULT_TYPE):\n    \"\"\"\n    Send a message with the same text as the user's message in a private chat when the\n    message is not a command.\n    \"\"\"\n    await context.bot.copy_message(\n        chat_id=update.effective_chat.id,\n        from_chat_id=update.effective_chat.id,\n        message_id=update.effective_message.message_id\n    )\n\n\nif __name__ == '__main__':\n    application.add_handler(CallbackQueryHandler(verifyAnonymousAdmin, pattern=r\"^anon.\"))\n    application.run_polling()\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashokshau%2Fptbmod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashokshau%2Fptbmod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashokshau%2Fptbmod/lists"}