-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
156 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## Plugin Commands | ||
|
||
### 轻雪`liteyuki` | ||
|
||
```shell | ||
reload-liteyuki # 重载轻雪 | ||
update-liteyuki # 更新轻雪 | ||
liteyuki # 查看轻雪信息 | ||
``` | ||
|
||
### 轻雪Nonebot插件管理 `liteyuki_npm` | ||
|
||
```shell | ||
npm update # 更新插件索引 | ||
npm install <plugin_name> # 安装插件 | ||
npm uninstall <plugin_name> # 卸载插件 | ||
npm search <keywords...> # 搜索插件 | ||
------ | ||
Alias: npm 插件, update 更新, install 安装, uninstall 卸载, search 搜索 | ||
``` | ||
|
||
```shell | ||
enable <plugin_name> # 启用插件 | ||
disable <plugin_name> # 禁用插件 | ||
enable-global <plugin_name> # 全局启用插件 | ||
disable-global <plugin_name> # 全局禁用插件 | ||
list-plugin # 列出所有插件 | ||
------ | ||
Alias: enable 启用, disable 停用, enable-global 全局启用, disable-global 全局停用, list-plugin 列出插件/插件列表 | ||
``` | ||
|
||
### 轻雪用户管理`liteyuki_user` | ||
|
||
```shell | ||
profile # 查看用户信息菜单 | ||
profile set <key> [value] # 设置用户信息或打开属性设置菜单 | ||
profile get <key> # 获取用户信息 | ||
------ | ||
Alias: profile 个人信息, set 设置, get 查询 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import threading | ||
from multiprocessing import get_context | ||
|
||
import nonebot | ||
from nonebot import logger | ||
from typing import List, Optional | ||
|
||
from nonebot import get_driver | ||
from pydantic import BaseSettings | ||
|
||
|
||
reboot_grace_time_limit: int = 20 | ||
|
||
_nb_run = nonebot.run | ||
|
||
|
||
class Reloader: | ||
event: threading.Event = None | ||
|
||
@classmethod | ||
def reload(cls, delay: int = 0): | ||
if cls.event is None: | ||
raise RuntimeError() | ||
if delay > 0: | ||
threading.Timer(delay, function=cls.event.set).start() | ||
return | ||
cls.event.set() | ||
|
||
|
||
def _run(ev: threading.Event, *args, **kwargs): | ||
Reloader.event = ev | ||
_nb_run(*args, **kwargs) | ||
|
||
|
||
def run(*args, **kwargs): | ||
should_exit = False | ||
ctx = get_context("spawn") | ||
while not should_exit: | ||
event = ctx.Event() | ||
process = ctx.Process( | ||
target=_run, | ||
args=( | ||
event, | ||
*args, | ||
), | ||
kwargs=kwargs, | ||
) | ||
process.start() | ||
while not should_exit: | ||
if event.wait(1): | ||
logger.info("Receive reboot event") | ||
process.terminate() | ||
process.join(reboot_grace_time_limit) | ||
if process.is_alive(): | ||
logger.warning( | ||
f"Cannot shutdown gracefully in {reboot_grace_time_limit} second, force kill process." | ||
) | ||
process.kill() | ||
break | ||
elif process.is_alive(): | ||
continue | ||
else: | ||
# Process stoped without setting event | ||
should_exit = True | ||
|
||
|
||
nonebot.run = run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters