From b44332121ae7e1eea6bff6f16a36e1d17c301608 Mon Sep 17 00:00:00 2001 From: AkashiCoin Date: Mon, 26 Aug 2024 11:38:19 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=94=AF=E6=8C=81bot=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=A3=80=E6=9F=A5=20(#1576)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/bot_check.yml | 43 +++++++++++++++++++++++++++++++++ scripts/bot_check.py | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 .github/workflows/bot_check.yml create mode 100644 scripts/bot_check.py diff --git a/.github/workflows/bot_check.yml b/.github/workflows/bot_check.yml new file mode 100644 index 000000000..eba97e85a --- /dev/null +++ b/.github/workflows/bot_check.yml @@ -0,0 +1,43 @@ +name: 检查bot是否运行正常 + +on: + push: + branches: [ "dev", "main"] + pull_request: + branches: [ "dev", "main"] + +jobs: + bot-check: + runs-on: ubuntu-latest + name: bot check + steps: + - uses: actions/checkout@v4 + + - name: Setup Python + id: setup_python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Install Poetry + run: pip install poetry + + # Poetry cache depends on OS, Python version and Poetry version. + - name: Cache Poetry cache + uses: actions/cache@v3 + with: + path: ~/.cache/pypoetry + key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }} + + - name: Install dependencies + run: | + mv scripts/bot_check.py bot_check.py + rm -rf poetry.lock + poetry source remove ali + poetry install --no-root + poetry run pip install pydantic==1.10 + + - name: Check bot run + id: bot_check_run + run: | + poetry run python3 bot_check.py \ No newline at end of file diff --git a/scripts/bot_check.py b/scripts/bot_check.py new file mode 100644 index 000000000..2f68c1ed0 --- /dev/null +++ b/scripts/bot_check.py @@ -0,0 +1,43 @@ +import re +import nonebot + +# from nonebot.adapters.discord import Adapter as DiscordAdapter +from nonebot.adapters.dodo import Adapter as DoDoAdapter +from nonebot.adapters.kaiheila import Adapter as KaiheilaAdapter +from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter +from regex import F + +nonebot.init() + +from zhenxun.models.plugin_info import PluginInfo + +driver = nonebot.get_driver() +driver.register_adapter(OneBotV11Adapter) +driver.register_adapter(KaiheilaAdapter) +driver.register_adapter(DoDoAdapter) +# driver.register_adapter(DiscordAdapter) + +# nonebot.load_builtin_plugins("echo") +nonebot.load_plugins("zhenxun/builtin_plugins") +nonebot.load_plugins("zhenxun/plugins") + +all_plugins = [name.replace(":", ".") for name in nonebot.get_available_plugin_names()] +print("所有插件:", all_plugins) +loaded_plugins = tuple(re.sub(r"^zhenxun\.(plugins|builtin_plugins)\.", "", plugin.module_name) for plugin in nonebot.get_loaded_plugins()) +print("已加载插件:", loaded_plugins) + +for plugin in all_plugins.copy(): + if plugin.startswith(("platform")): + print(f"平台插件:{plugin}") + elif plugin.endswith(loaded_plugins): + print(f"已加载插件:{plugin}") + else: + print(f"未加载插件:{plugin}") + continue + all_plugins.remove(plugin) + +if all_plugins: + print("出现未加载的插件:", all_plugins) + exit(1) +else: + print("所有插件均已加载") \ No newline at end of file