mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✨ 更好的Bot运行检查
This commit is contained in:
parent
ab1d0d22dd
commit
ee11893074
18
.github/workflows/bot_check.yml
vendored
18
.github/workflows/bot_check.yml
vendored
@ -2,9 +2,9 @@ name: 检查bot是否运行正常
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "dev", "main"]
|
branches: ["dev", "main"]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "dev", "main"]
|
branches: ["dev", "main"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
bot-check:
|
bot-check:
|
||||||
@ -24,14 +24,21 @@ jobs:
|
|||||||
|
|
||||||
# Poetry cache depends on OS, Python version and Poetry version.
|
# Poetry cache depends on OS, Python version and Poetry version.
|
||||||
- name: Cache Poetry cache
|
- name: Cache Poetry cache
|
||||||
|
id: cache-poetry
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.cache/pypoetry
|
path: ~/.cache/pypoetry
|
||||||
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}
|
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}
|
||||||
|
|
||||||
|
- name: Cache Data cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/data
|
||||||
|
key: data-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
if: steps.cache-poetry.outputs.cache-hit != 'true'
|
||||||
run: |
|
run: |
|
||||||
mv scripts/bot_check.py bot_check.py
|
|
||||||
rm -rf poetry.lock
|
rm -rf poetry.lock
|
||||||
poetry source remove ali
|
poetry source remove ali
|
||||||
poetry install --no-root
|
poetry install --no-root
|
||||||
@ -40,4 +47,5 @@ jobs:
|
|||||||
- name: Check bot run
|
- name: Check bot run
|
||||||
id: bot_check_run
|
id: bot_check_run
|
||||||
run: |
|
run: |
|
||||||
poetry run python3 bot_check.py
|
mv scripts/bot_check.py bot_check.py
|
||||||
|
poetry run python3 bot_check.py
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import nonebot
|
import nonebot
|
||||||
|
from nonebot.log import logger
|
||||||
|
|
||||||
# from nonebot.adapters.discord import Adapter as DiscordAdapter
|
# from nonebot.adapters.discord import Adapter as DiscordAdapter
|
||||||
from nonebot.adapters.dodo import Adapter as DoDoAdapter
|
from nonebot.adapters.dodo import Adapter as DoDoAdapter
|
||||||
@ -9,37 +12,52 @@ from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter
|
|||||||
|
|
||||||
nonebot.init()
|
nonebot.init()
|
||||||
|
|
||||||
|
from zhenxun.services.db_context import init, disconnect
|
||||||
|
|
||||||
driver = nonebot.get_driver()
|
driver = nonebot.get_driver()
|
||||||
|
|
||||||
driver.register_adapter(OneBotV11Adapter)
|
driver.register_adapter(OneBotV11Adapter)
|
||||||
driver.register_adapter(KaiheilaAdapter)
|
driver.register_adapter(KaiheilaAdapter)
|
||||||
driver.register_adapter(DoDoAdapter)
|
driver.register_adapter(DoDoAdapter)
|
||||||
# driver.register_adapter(DiscordAdapter)
|
|
||||||
|
|
||||||
|
driver.on_startup(init)
|
||||||
|
driver.on_shutdown(disconnect)
|
||||||
|
|
||||||
|
|
||||||
# nonebot.load_builtin_plugins("echo")
|
# nonebot.load_builtin_plugins("echo")
|
||||||
nonebot.load_plugins("zhenxun/builtin_plugins")
|
nonebot.load_plugins("zhenxun/builtin_plugins")
|
||||||
nonebot.load_plugins("zhenxun/plugins")
|
nonebot.load_plugins("zhenxun/plugins")
|
||||||
|
|
||||||
all_plugins = [name.replace(":", ".") for name in nonebot.get_available_plugin_names()]
|
all_plugins = [name.replace(":", ".") for name in nonebot.get_available_plugin_names()]
|
||||||
print("所有插件:", all_plugins)
|
logger.info(f"所有插件:{all_plugins}")
|
||||||
loaded_plugins = tuple(
|
loaded_plugins = tuple(
|
||||||
re.sub(r"^zhenxun\.(plugins|builtin_plugins)\.", "", plugin.module_name)
|
re.sub(r"^zhenxun\.(plugins|builtin_plugins)\.", "", plugin.module_name)
|
||||||
for plugin in nonebot.get_loaded_plugins()
|
for plugin in nonebot.get_loaded_plugins()
|
||||||
)
|
)
|
||||||
print("已加载插件:", loaded_plugins)
|
logger.info(f"已加载插件:{loaded_plugins}")
|
||||||
|
|
||||||
for plugin in all_plugins.copy():
|
for plugin in all_plugins.copy():
|
||||||
if plugin.startswith(("platform",)):
|
if plugin.startswith(("platform",)):
|
||||||
print(f"平台插件:{plugin}")
|
logger.info(f"平台插件:{plugin}")
|
||||||
elif plugin.endswith(loaded_plugins):
|
elif plugin.endswith(loaded_plugins):
|
||||||
print(f"已加载插件:{plugin}")
|
logger.info(f"已加载插件:{plugin}")
|
||||||
else:
|
else:
|
||||||
print(f"未加载插件:{plugin}")
|
logger.info(f"未加载插件:{plugin}")
|
||||||
continue
|
continue
|
||||||
all_plugins.remove(plugin)
|
all_plugins.remove(plugin)
|
||||||
|
|
||||||
if all_plugins:
|
if all_plugins:
|
||||||
print("出现未加载的插件:", all_plugins)
|
logger.info(f"出现未加载的插件:{all_plugins}")
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
print("所有插件均已加载")
|
logger.info("所有插件均已加载")
|
||||||
|
|
||||||
|
|
||||||
|
@driver.on_startup
|
||||||
|
async def _():
|
||||||
|
task = asyncio.create_task(asyncio.sleep(1))
|
||||||
|
task.add_done_callback(lambda _: driver._lifespan.on_ready(os._exit(0)))
|
||||||
|
|
||||||
|
|
||||||
|
nonebot.run()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user