nonebot-plugin-reboot


Namenonebot-plugin-reboot JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/18870/nonebot-plugin-reboot
SummaryReboot your bot by using command
upload_time2023-06-24 10:34:30
maintainer
docs_urlNone
author18870
requires_python>=3.7.3,<4.0.0
licenseMIT
keywords nonebot
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Nonebot-plugin-reboot 
![](https://img.shields.io/badge/Development-Inactive-inactive) ![](https://img.shields.io/badge/PullRequests-Welcome-success)

用命令重启 bot 

[![asciicast](https://asciinema.org/a/z10hzQ7Pgx4s9TVwj0nAv2TsV.svg)](https://asciinema.org/a/z10hzQ7Pgx4s9TVwj0nAv2TsV)

## :warning:注意事项
**必须要有** `bot.py`  
新版 nb-cli 默认不生成 bot.py,需要在 nb 菜单里选择 `生成机器人的入口文件` / `Generate entry file of your bot.` 生成一个,不需要修改。 ~~不要再去群里问bot.py在哪了~~

**不兼容** `fastapi_reload`,见 [#1](https://github.com/18870/nonebot-plugin-reboot/issues/1)、[#2](https://github.com/18870/nonebot-plugin-reboot/issues/2)。  
不推荐使用 nb-cli 的 `--reload` 参数,这个插件是 `--reload` 在生产环境中的替代品。

重启时直接对子进程使用 `process.terminate()`,如果你的其他插件启动了子进程,请确保它们能在设定的等待时间内正确关闭子进程,否则子进程会变成孤立进程。  
:warning: Windows 下因系统 API 的限制进程会直接被杀死, **没有** 等待时间。

<hr>  

插件依赖于 `multiprocessing` `spawn` 生成子进程方式工作,支持由 nb-cli 生成的 bot.py,以及其他在加载插件后调用 `nonebot.run()` 的启动方式。  


## 安装
通过 nb-cli 安装:  
`nb plugin install nonebot-plugin-reboot`  

新版 nb-cli 默认不生成 bot.py,需要在 nb 菜单里选择 `生成机器人的入口文件` / `Generate entry file of your bot.` 生成一个,不需要修改。


## 使用
**超级用户**向机器人**私聊**发送**命令** `重启`, `reboot` 或 `restart`  
> :warning: 注意命令的 `COMMAND_START`.  
> 例如 /重启 、 /reboot 、 /restart


## 配置项 
`reboot_load_command`: `bool` 
- 加载内置的 `onebot v11` 重启命令 
- 可以通过命令 `重启` `reboot` `restart` 触发重启 
- 默认值: `True` 

`reboot_grace_time_limit`: `int`
- 收到重启命令后等待进程退出的最长时间,超时会强制杀进程
- 在 Windows 下没有等待时间,会直接杀进程
- ~~真寻从ctrl+c到彻底退出居然要六秒~~
- 默认值: `20`


## `bot.py`
因为使用了 `spawn` 方式启动子进程,默认情况下会加载两次插件,如果你觉得这不是问题可以忽略这段,也不建议你在不懂的情况下修改 `bot.py`。

推荐的写法是将 插件加载部分 和 启动部分 分开,以避免插件在主进程和子进程都加载一遍

~~真寻启动居然要20秒~~

```python
#
# 上面省略
#

if __name__ == "__mp_main__": # 仅在子进程运行的代码
    # Please DO NOT modify this file unless you know what you are doing!
    # As an alternative, you should use command `nb` or modify `pyproject.toml` to load plugins
    # 加载插件
    nonebot.load_from_toml("pyproject.toml")
    # ...

if __name__ == "__main__": # 仅在主进程运行的代码
    # nonebot.logger.warning("Always use `nb run` to start the bot instead of manually running!")
    # 运行 nonebot
    nonebot.load_plugin("nonebot_plugin_reboot") # 加载重启插件
    nonebot.run(app="__mp_main__:app")
```


## API
```python
require("nonebot_plugin_reboot")
from nonebot_plugin_reboot import Reloader
Reloader.reload(delay=5) # 可选参数 5秒后触发重启
```


## 依赖 
- `nonebot2 >= 2.0.0beta.2`  

启用 `reboot_load_command` 时需要以下依赖  
- `nonebot-adapter-onebot`
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/18870/nonebot-plugin-reboot",
    "name": "nonebot-plugin-reboot",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7.3,<4.0.0",
    "maintainer_email": "",
    "keywords": "nonebot",
    "author": "18870",
    "author_email": "a20110123@163.com",
    "download_url": "https://files.pythonhosted.org/packages/8b/5c/b13132cbe6c12fe81a08bd1402a0ef20eb195358fe77edd08d0f9dbe7eeb/nonebot_plugin_reboot-0.1.4.tar.gz",
    "platform": null,
    "description": "# Nonebot-plugin-reboot \n![](https://img.shields.io/badge/Development-Inactive-inactive) ![](https://img.shields.io/badge/PullRequests-Welcome-success)\n\n\u7528\u547d\u4ee4\u91cd\u542f bot \n\n[![asciicast](https://asciinema.org/a/z10hzQ7Pgx4s9TVwj0nAv2TsV.svg)](https://asciinema.org/a/z10hzQ7Pgx4s9TVwj0nAv2TsV)\n\n## :warning:\u6ce8\u610f\u4e8b\u9879\n**\u5fc5\u987b\u8981\u6709** `bot.py`  \n\u65b0\u7248 nb-cli \u9ed8\u8ba4\u4e0d\u751f\u6210 bot.py\uff0c\u9700\u8981\u5728 nb \u83dc\u5355\u91cc\u9009\u62e9 `\u751f\u6210\u673a\u5668\u4eba\u7684\u5165\u53e3\u6587\u4ef6` / `Generate entry file of your bot.` \u751f\u6210\u4e00\u4e2a\uff0c\u4e0d\u9700\u8981\u4fee\u6539\u3002 ~~\u4e0d\u8981\u518d\u53bb\u7fa4\u91cc\u95eebot.py\u5728\u54ea\u4e86~~\n\n**\u4e0d\u517c\u5bb9** `fastapi_reload`\uff0c\u89c1 [#1](https://github.com/18870/nonebot-plugin-reboot/issues/1)\u3001[#2](https://github.com/18870/nonebot-plugin-reboot/issues/2)\u3002  \n\u4e0d\u63a8\u8350\u4f7f\u7528 nb-cli \u7684 `--reload` \u53c2\u6570\uff0c\u8fd9\u4e2a\u63d2\u4ef6\u662f `--reload` \u5728\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u66ff\u4ee3\u54c1\u3002\n\n\u91cd\u542f\u65f6\u76f4\u63a5\u5bf9\u5b50\u8fdb\u7a0b\u4f7f\u7528 `process.terminate()`\uff0c\u5982\u679c\u4f60\u7684\u5176\u4ed6\u63d2\u4ef6\u542f\u52a8\u4e86\u5b50\u8fdb\u7a0b\uff0c\u8bf7\u786e\u4fdd\u5b83\u4eec\u80fd\u5728\u8bbe\u5b9a\u7684\u7b49\u5f85\u65f6\u95f4\u5185\u6b63\u786e\u5173\u95ed\u5b50\u8fdb\u7a0b\uff0c\u5426\u5219\u5b50\u8fdb\u7a0b\u4f1a\u53d8\u6210\u5b64\u7acb\u8fdb\u7a0b\u3002  \n:warning: Windows \u4e0b\u56e0\u7cfb\u7edf API \u7684\u9650\u5236\u8fdb\u7a0b\u4f1a\u76f4\u63a5\u88ab\u6740\u6b7b\uff0c **\u6ca1\u6709** \u7b49\u5f85\u65f6\u95f4\u3002\n\n<hr>  \n\n\u63d2\u4ef6\u4f9d\u8d56\u4e8e `multiprocessing` `spawn` \u751f\u6210\u5b50\u8fdb\u7a0b\u65b9\u5f0f\u5de5\u4f5c\uff0c\u652f\u6301\u7531 nb-cli \u751f\u6210\u7684 bot.py\uff0c\u4ee5\u53ca\u5176\u4ed6\u5728\u52a0\u8f7d\u63d2\u4ef6\u540e\u8c03\u7528 `nonebot.run()` \u7684\u542f\u52a8\u65b9\u5f0f\u3002  \n\n\n## \u5b89\u88c5\n\u901a\u8fc7 nb-cli \u5b89\u88c5:  \n`nb plugin install nonebot-plugin-reboot`  \n\n\u65b0\u7248 nb-cli \u9ed8\u8ba4\u4e0d\u751f\u6210 bot.py\uff0c\u9700\u8981\u5728 nb \u83dc\u5355\u91cc\u9009\u62e9 `\u751f\u6210\u673a\u5668\u4eba\u7684\u5165\u53e3\u6587\u4ef6` / `Generate entry file of your bot.` \u751f\u6210\u4e00\u4e2a\uff0c\u4e0d\u9700\u8981\u4fee\u6539\u3002\n\n\n## \u4f7f\u7528\n**\u8d85\u7ea7\u7528\u6237**\u5411\u673a\u5668\u4eba**\u79c1\u804a**\u53d1\u9001**\u547d\u4ee4** `\u91cd\u542f`, `reboot` \u6216 `restart`  \n> :warning: \u6ce8\u610f\u547d\u4ee4\u7684 `COMMAND_START`.  \n> \u4f8b\u5982 /\u91cd\u542f \u3001 /reboot \u3001 /restart\n\n\n## \u914d\u7f6e\u9879 \n`reboot_load_command`: `bool` \n- \u52a0\u8f7d\u5185\u7f6e\u7684 `onebot v11` \u91cd\u542f\u547d\u4ee4 \n- \u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4 `\u91cd\u542f` `reboot` `restart` \u89e6\u53d1\u91cd\u542f \n- \u9ed8\u8ba4\u503c: `True` \n\n`reboot_grace_time_limit`: `int`\n- \u6536\u5230\u91cd\u542f\u547d\u4ee4\u540e\u7b49\u5f85\u8fdb\u7a0b\u9000\u51fa\u7684\u6700\u957f\u65f6\u95f4\uff0c\u8d85\u65f6\u4f1a\u5f3a\u5236\u6740\u8fdb\u7a0b\n- \u5728 Windows \u4e0b\u6ca1\u6709\u7b49\u5f85\u65f6\u95f4\uff0c\u4f1a\u76f4\u63a5\u6740\u8fdb\u7a0b\n- ~~\u771f\u5bfb\u4ecectrl+c\u5230\u5f7b\u5e95\u9000\u51fa\u5c45\u7136\u8981\u516d\u79d2~~\n- \u9ed8\u8ba4\u503c: `20`\n\n\n## `bot.py`\n\u56e0\u4e3a\u4f7f\u7528\u4e86 `spawn` \u65b9\u5f0f\u542f\u52a8\u5b50\u8fdb\u7a0b\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u52a0\u8f7d\u4e24\u6b21\u63d2\u4ef6\uff0c\u5982\u679c\u4f60\u89c9\u5f97\u8fd9\u4e0d\u662f\u95ee\u9898\u53ef\u4ee5\u5ffd\u7565\u8fd9\u6bb5\uff0c\u4e5f\u4e0d\u5efa\u8bae\u4f60\u5728\u4e0d\u61c2\u7684\u60c5\u51b5\u4e0b\u4fee\u6539 `bot.py`\u3002\n\n\u63a8\u8350\u7684\u5199\u6cd5\u662f\u5c06 \u63d2\u4ef6\u52a0\u8f7d\u90e8\u5206 \u548c \u542f\u52a8\u90e8\u5206 \u5206\u5f00\uff0c\u4ee5\u907f\u514d\u63d2\u4ef6\u5728\u4e3b\u8fdb\u7a0b\u548c\u5b50\u8fdb\u7a0b\u90fd\u52a0\u8f7d\u4e00\u904d\n\n~~\u771f\u5bfb\u542f\u52a8\u5c45\u7136\u898120\u79d2~~\n\n```python\n#\n# \u4e0a\u9762\u7701\u7565\n#\n\nif __name__ == \"__mp_main__\": # \u4ec5\u5728\u5b50\u8fdb\u7a0b\u8fd0\u884c\u7684\u4ee3\u7801\n    # Please DO NOT modify this file unless you know what you are doing!\n    # As an alternative, you should use command `nb` or modify `pyproject.toml` to load plugins\n    # \u52a0\u8f7d\u63d2\u4ef6\n    nonebot.load_from_toml(\"pyproject.toml\")\n    # ...\n\nif __name__ == \"__main__\": # \u4ec5\u5728\u4e3b\u8fdb\u7a0b\u8fd0\u884c\u7684\u4ee3\u7801\n    # nonebot.logger.warning(\"Always use `nb run` to start the bot instead of manually running!\")\n    # \u8fd0\u884c nonebot\n    nonebot.load_plugin(\"nonebot_plugin_reboot\") # \u52a0\u8f7d\u91cd\u542f\u63d2\u4ef6\n    nonebot.run(app=\"__mp_main__:app\")\n```\n\n\n## API\n```python\nrequire(\"nonebot_plugin_reboot\")\nfrom nonebot_plugin_reboot import Reloader\nReloader.reload(delay=5) # \u53ef\u9009\u53c2\u6570 5\u79d2\u540e\u89e6\u53d1\u91cd\u542f\n```\n\n\n## \u4f9d\u8d56 \n- `nonebot2 >= 2.0.0beta.2`  \n\n\u542f\u7528 `reboot_load_command` \u65f6\u9700\u8981\u4ee5\u4e0b\u4f9d\u8d56  \n- `nonebot-adapter-onebot`",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Reboot your bot by using command",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/18870/nonebot-plugin-reboot",
        "Repository": "https://github.com/18870/nonebot-plugin-reboot"
    },
    "split_keywords": [
        "nonebot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b49a3c4c7df895e2863539898e2ac0304c35338f1acc24ddbc8534d3672fbe91",
                "md5": "a4b47ddd077be2df4e4292c41ce8ebad",
                "sha256": "93ff1cdc7397e361cd8f16008f74d8f015bf35adfe96d44a4156c2e135cf6a77"
            },
            "downloads": -1,
            "filename": "nonebot_plugin_reboot-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a4b47ddd077be2df4e4292c41ce8ebad",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.3,<4.0.0",
            "size": 5961,
            "upload_time": "2023-06-24T10:34:29",
            "upload_time_iso_8601": "2023-06-24T10:34:29.338115Z",
            "url": "https://files.pythonhosted.org/packages/b4/9a/3c4c7df895e2863539898e2ac0304c35338f1acc24ddbc8534d3672fbe91/nonebot_plugin_reboot-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b5cb13132cbe6c12fe81a08bd1402a0ef20eb195358fe77edd08d0f9dbe7eeb",
                "md5": "1dde86b40db39a28275357fcdf0ff049",
                "sha256": "d1864f31d0360a0e7271d7411c34e80ccac41008aa6082d7470175b6cb8721dc"
            },
            "downloads": -1,
            "filename": "nonebot_plugin_reboot-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "1dde86b40db39a28275357fcdf0ff049",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.3,<4.0.0",
            "size": 4939,
            "upload_time": "2023-06-24T10:34:30",
            "upload_time_iso_8601": "2023-06-24T10:34:30.715471Z",
            "url": "https://files.pythonhosted.org/packages/8b/5c/b13132cbe6c12fe81a08bd1402a0ef20eb195358fe77edd08d0f9dbe7eeb/nonebot_plugin_reboot-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-24 10:34:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "18870",
    "github_project": "nonebot-plugin-reboot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nonebot-plugin-reboot"
}
        
Elapsed time: 0.11234s