{ "info": { "author": "Timoth\u00e9e Mazzucotelli", "author_email": "pawamoy@pm.me", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# privibot\nThis library provides decorators to restrict access to your Telegram bot handlers based on privileges given to users.\nThe privileges are stored in a database through SQLAlchemy (SQLite, Postgres, etc.).\n\n## Requirements\nprivibot requires Python 3.6 or above.\n\n
\nTo install Python 3.6, I recommend using pyenv.\n\n```bash\n# install pyenv\ngit clone https://github.com/pyenv/pyenv ~/.pyenv\n\n# setup pyenv (you should also put these three lines in .bashrc or similar)\nexport PATH=\"${HOME}/.pyenv/bin:${PATH}\"\nexport PYENV_ROOT=\"${HOME}/.pyenv\"\neval \"$(pyenv init -)\"\n\n# install Python 3.6\npyenv install 3.6.8\n\n# make it available globally\npyenv global system 3.6.8\n```\n
\n\n## Installation\nWith `pip`:\n```bash\npython3.6 -m pip install privibot\n```\n\nWith [`pipx`](https://github.com/cs01/pipx):\n```bash\npython3.6 -m pip install --user pipx\n\npipx install --python python3.6 privibot\n```\n\n\n## Usage\nTo restrict access to a handler, decorate your callback functions like following:\n\n```python\nfrom privibot import require_access, require_admin\n\n\n@require_access\ndef callback_for_registered_users(update, context):\n pass\n \n \n@require_admin\ndef callback_for_admins_only(update, context):\n pass\n```\n\nTo use custom privileges, define them like so:\n\n```python\n# privileges.py\nfrom privibot import Privilege, Privileges as Ps\n\n\nclass Privileges(Ps):\n MEDIA_MANAGER = Privilege(\n name=\"media_manager\",\n verbose_name=\"Media Manager\",\n description=\"This privilege allows users to act (accept or reject) on media-related requests.\",\n )\n USER_MANAGER = Privilege(\n \"user_manager\", \"User Manager\", \"This privilege allows users to manage access of other users to the bot.\"\n )\n TESTER = Privilege(\"tester\", \"Tester\", \"This privilege allows users to test new things.\")\n```\n\nNow simply use these privileges with the decorator:\n\n```python\nfrom privibot import require_privileges\n\nfrom .privileges import Privileges\n\n\n@require_privileges([Privileges.USER_MANAGER])\ndef callback_for_user_managers_only(update, context):\n pass\n```\n\nYou can also manually check for privileges like so:\n\n```python\nfrom privibot import User\n\nfrom .privileges import Privileges\n\n\ndef some_callback(update, context):\n telegram_user = update.effective_user\n db_user = User.get_with_id(telegram_user.id)\n \n if db_user.has_privilege(Privileges.TESTER):\n # do something\n elif db_user.has_privileges([Privileges.MEDIA_MANAGER, Privileges.USER_MANAGER]):\n # do something else\n```\n\nUsers who do not pass the privilege test will receive a message saying they have been denied access.\n\n### Built-in handlers\nThis library also provides handlers and their callbacks for the following commands:\n- /start\n- /help\n- /requestAccess\n- /myPrivileges\n- /grant\n- /revoke\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/pawamoy/privibot", "keywords": "telegram-bot", "license": "", "maintainer": "Timoth\u00e9e Mazzucotelli", "maintainer_email": "pawamoy@pm.me", "name": "privibot", "package_url": "https://pypi.org/project/privibot/", "platform": "", "project_url": "https://pypi.org/project/privibot/", "project_urls": { "Homepage": "https://github.com/pawamoy/privibot", "Repository": "https://github.com/pawamoy/privibot" }, "release_url": "https://pypi.org/project/privibot/0.1.1/", "requires_dist": [ "python-telegram-bot (==12.0.0b1)", "sqlalchemy (>=1.3,<2.0)" ], "requires_python": ">=3.6,<4.0", "summary": "A library to build Telegram Bot with a privilege system.", "version": "0.1.1", "yanked": false, "yanked_reason": null }, "last_serial": 6037274, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "19018ba4f84ba10e46e77042950fb79f", "sha256": "28996682a4bdfd7fb3a5993fe3449a68e0fb027ded33e3f7954c9c1fae1083ea" }, "downloads": -1, "filename": "privibot-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "19018ba4f84ba10e46e77042950fb79f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 10266, "upload_time": "2019-10-25T16:59:54", "upload_time_iso_8601": "2019-10-25T16:59:54.076542Z", "url": "https://files.pythonhosted.org/packages/36/63/93536316c85467809ce05cf6d399a320ad238e36d6b4ac4ae916728b6af2/privibot-0.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "77b90e1fdd6ec915ed77cc01a3f96ad3", "sha256": "3eb9fb5e3a450bb10e7b2fb778cdaa5cef8d102c8156efdb076654335940bcbc" }, "downloads": -1, "filename": "privibot-0.1.0.tar.gz", "has_sig": false, "md5_digest": "77b90e1fdd6ec915ed77cc01a3f96ad3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 7899, "upload_time": "2019-10-25T16:59:56", "upload_time_iso_8601": "2019-10-25T16:59:56.200673Z", "url": "https://files.pythonhosted.org/packages/75/1c/995b2650eb91a5d47b1904fc36c10efbfd8055bcbbaefc68aa448539e82b/privibot-0.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "88846d6e9cd6240afd098f85661aea98", "sha256": "aa5cd667db385ef09806b29a4f5dcba812652a26b97091ed683221c6d1ecf017" }, "downloads": -1, "filename": "privibot-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "88846d6e9cd6240afd098f85661aea98", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 11085, "upload_time": "2019-10-27T14:56:34", "upload_time_iso_8601": "2019-10-27T14:56:34.807422Z", "url": "https://files.pythonhosted.org/packages/0e/98/fb51a1afc7a8d5eb4c0e29668763980d7dcd41aa575d8659802cdb3e3d78/privibot-0.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "b3e3fae0e95a5317db826cb1a1b12fa4", "sha256": "01d7320bfa9a7ddd8e86de6b72cdb1872271a94b46779f9d9188a4cd78cfac89" }, "downloads": -1, "filename": "privibot-0.1.1.tar.gz", "has_sig": false, "md5_digest": "b3e3fae0e95a5317db826cb1a1b12fa4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 8838, "upload_time": "2019-10-27T14:56:36", "upload_time_iso_8601": "2019-10-27T14:56:36.447612Z", "url": "https://files.pythonhosted.org/packages/3f/cd/44e6f6dae156a5b759a049a76898986e970f38b06f6745606ed4a7da4801/privibot-0.1.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "88846d6e9cd6240afd098f85661aea98", "sha256": "aa5cd667db385ef09806b29a4f5dcba812652a26b97091ed683221c6d1ecf017" }, "downloads": -1, "filename": "privibot-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "88846d6e9cd6240afd098f85661aea98", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 11085, "upload_time": "2019-10-27T14:56:34", "upload_time_iso_8601": "2019-10-27T14:56:34.807422Z", "url": "https://files.pythonhosted.org/packages/0e/98/fb51a1afc7a8d5eb4c0e29668763980d7dcd41aa575d8659802cdb3e3d78/privibot-0.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "b3e3fae0e95a5317db826cb1a1b12fa4", "sha256": "01d7320bfa9a7ddd8e86de6b72cdb1872271a94b46779f9d9188a4cd78cfac89" }, "downloads": -1, "filename": "privibot-0.1.1.tar.gz", "has_sig": false, "md5_digest": "b3e3fae0e95a5317db826cb1a1b12fa4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 8838, "upload_time": "2019-10-27T14:56:36", "upload_time_iso_8601": "2019-10-27T14:56:36.447612Z", "url": "https://files.pythonhosted.org/packages/3f/cd/44e6f6dae156a5b759a049a76898986e970f38b06f6745606ed4a7da4801/privibot-0.1.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }