{"id":23149253,"url":"https://github.com/antares0982/antares-bot","last_synced_at":"2026-03-03T21:01:08.769Z","repository":{"id":134216509,"uuid":"380503095","full_name":"Antares0982/antares-bot","owner":"Antares0982","description":"A Telegram bot framework wrapping many things.","archived":false,"fork":false,"pushed_at":"2025-12-21T14:48:27.000Z","size":304,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-23T05:14:41.004Z","etag":null,"topics":["api","bot","python","python-telegram-bot","telegram","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Antares0982.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-06-26T13:02:45.000Z","updated_at":"2025-12-21T14:48:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"29518c41-069b-4c56-92ac-5db27eb8f67f","html_url":"https://github.com/Antares0982/antares-bot","commit_stats":null,"previous_names":["antares0982/telegram-bot-template"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Antares0982/antares-bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antares0982%2Fantares-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antares0982%2Fantares-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antares0982%2Fantares-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antares0982%2Fantares-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Antares0982","download_url":"https://codeload.github.com/Antares0982/antares-bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antares0982%2Fantares-bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30060624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api","bot","python","python-telegram-bot","telegram","wrapper"],"created_at":"2024-12-17T17:16:25.263Z","updated_at":"2026-03-03T21:01:08.753Z","avatar_url":"https://github.com/Antares0982.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AntaresBot\nA Telegram bot framework wrapping many things.\n\n### How to use\n\n* `pip install antares_bot`. If you want to use pika for logging, `pip install antares_bot[pika]`\n* Run `antares_bot` once in working directory to generate the `bot_cfg.py`\n* Complete the `bot_cfg.py`\n* Write your module in `modules` directory under working directory\n* Run `antares_bot` to start your bot\n\n### Examples\n\nThe documentation is far from completed, so here we only introduce a small part of features. We assume that you are already familiar with [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot).\n\nCreating a bot with command `/echo`. First create a file `modules/echo.py`.\n\n```python\nfrom typing import TYPE_CHECKING\n\nfrom antares_bot.module_base import TelegramBotModuleBase\nfrom antares_bot.framework import command_callback_wrapper\n\nif TYPE_CHECKING:\n    from telegram import Update\n\n    from antares_bot.context import RichCallbackContext\n\n\nclass Echo(TelegramBotModuleBase):\n    def mark_handlers(self):\n        return [self.echo]\n\n    @command_callback_wrapper\n    async def echo(self, update: \"Update\", context: \"RichCallbackContext\") -\u003e bool:\n        assert update.message is not None\n        assert update.message.text is not None\n        text = update.message.text.strip()\n        if text.startswith(\"/echo\"):\n            text = text[len(\"/echo\"):].strip()\n        if text:\n            await self.reply(text)\n```\n\n`antares_bot` will automatically scan the files under `modules` directory and find the class derived from `TelegramBotModuleBase`, with the same name pattern as the file (`CamelCase` for class name, `snake_case` for file name, for example: `my_example.py` corresponds to `class MyExample(TelegramBotModuleBase):`)\n\nModule interfaces:\n\n* Override `mark_handlers` to define the handlers. Handler wrappers can be found in `antares_bot.framework`.\n* Override `do_init` to init. `__init__` is not recommanded.\n* Override `post_init` to run some async function right after all modules are inited.\n* Override `do_stop` to run some async function when exiting.\n\nWe use contexts to store the needed information for sending a message, so you only need to pass the message text when using the method `reply`.\n\nMethods sending texts like `reply` (defined in `TelegramBotBaseWrapper`, `bot_method_wrapper.py`) have 4 different versions. These methods will automatically split the long text into parts, so it may send many messages. The original version returns id of the last message. V2 returns a list of ids of all messages (sorted). V3 returns the last `Message` object, and V4 returns all `Message` objects (sorted).\n\nCreating a bot with command `/timer`\n\n```python\nimport time\nfrom typing import TYPE_CHECKING\n\nfrom antares_bot.framework import command_callback_wrapper\nfrom antares_bot.module_base import TelegramBotModuleBase\nfrom antares_bot.context_manager import callback_job_wrapper\n\n\nif TYPE_CHECKING:\n    from telegram import Update\n\n    from antares_bot.context import RichCallbackContext\n\n\nclass Timer(TelegramBotModuleBase):\n    def mark_handlers(self):\n        return [self.timer]\n\n    @command_callback_wrapper\n    async def timer(self, update: \"Update\", context: \"RichCallbackContext\") -\u003e bool:\n        assert update.message is not None\n        assert update.message.text is not None\n\n        @callback_job_wrapper\n        async def cb(context_new):\n            await self.reply(\"Time up!\")\n        self.job_queue.run_once(cb, 5, name=f\"{time.time()}\")\n        return True\n```\n\nWe use `callback_job_wrapper` to wrap the outer context for the nested function `cb`, and thus `reply` can reply to the correct message after 5 seconds.\n\ni18n:\n\n```python\nfrom antares_bot.basic_language import BasicLanguage as Lang\nawait self.send_to(self.get_master_id(), Lang.t(Lang.UNKNOWN_ERROR))\n```\n\nYou can define any i18n config like `Lang.UNKNOWN_ERROR`\n\n```python\nUNKNOWN_ERROR = {\n    \"zh-CN\": \"哎呀，出现了未知的错误呢……\",\n    \"en\": \"Oops, an unknown error occurred...\",\n}\n```\n\nCall `set_lang` for each user to define their language.\n\nCustom commands:\n\n* `/exec` execute some python code (master only). `self` is defined to be the `TelegramBot` object in `bot_inst.py`.\n\n  ```python\n  /exec import objgraph\n  return list(map(lambda x:x.misfire_grace_time, objgraph.by_type(\"Job\")))\n  # Execution succeeded, return value: [60, 60]\n  ```\n\n* `restart`, `stop` restart/stop the bot (master only). If `AntaresBotConfig.SYSTEMD_SERVICE_NAME` is configured, `/restart` will try to call `systemctl restart` for you. If `AntaresBotConfig.PULL_WHEN_STOP` is configured, these two commands will perform `git pull`.\n\n* `get_id` see `/help get_id`.\n\n* `help` check the docstring of command. For more information see `/help help`.\n\n* `debug_mode` switch the logging level to `DEBUG` (master only).\n\nAlso, you can start the bot by yourself, without calling `antares_bot` in the command line.\n\n```python\nif __name__ == \"__main__\":\n    from antares_bot import __main__\n    inst = __main__.bootstrap()\n    inst.run()\n```\n\n\n\n### Note\n\n* Only support Python version \u003e= 3.10\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantares0982%2Fantares-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantares0982%2Fantares-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantares0982%2Fantares-bot/lists"}