-
-
Notifications
You must be signed in to change notification settings - Fork 9
Feature: 支持自定义快捷指令 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,39 @@ | ||
| from nonebot import logger, get_driver | ||
| from nonebot_plugin_alconna import command_manager | ||
|
|
||
| from .exception import RequestException | ||
| from .config import RESOURCE_ROUTES, config | ||
| from .download import GameResourceDownloader | ||
| from .config import CACHE_DIR, RESOURCE_ROUTES, config | ||
|
|
||
| driver = get_driver() | ||
| shortcut_cache = CACHE_DIR / "shortcut.db" | ||
|
|
||
|
|
||
| @driver.on_startup | ||
| async def startup(): | ||
| command_manager.load_cache(shortcut_cache) | ||
| logger.debug("Skland shortcuts cache loaded") | ||
|
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Cache operations on startup are clear. 将启动时的缓存加载和转储操作包装在 try/except 块中,以捕获启动或关闭期间的 IO 错误。 Suggested implementation: @driver.on_startup
async def startup():
try:
command_manager.load_cache(shortcut_cache)
logger.debug("Skland shortcuts cache loaded")
except Exception as e:
logger.error("Failed to load shortcut cache on startup", exc_info=e)
if config.check_res_update:
try:
if version := await GameResourceDownloader.check_update():
for route in RESOURCE_ROUTES:
logger.info(f"正在下载: {route}")
await GameResourceDownloader.download_all(
owner="yuanyan3060",
repo="ArknightsGameResource",
route=route,
branch="main",
)
except Exception as e:
logger.error("Error during resource update", exc_info=e)If there is a cache dump operation in your shutdown function (for example, within a @driver.on_shutdown decorated function), Wrap that operation in a similar try/except block to catch and log any IO errors during shutdown. Original comment in Englishsuggestion (bug_risk): Cache operations on startup are clear. Wrap cache load and dump in a try/except to catch IO errors during startup or shutdown. Suggested implementation: @driver.on_startup
async def startup():
try:
command_manager.load_cache(shortcut_cache)
logger.debug("Skland shortcuts cache loaded")
except Exception as e:
logger.error("Failed to load shortcut cache on startup", exc_info=e)
if config.check_res_update:
try:
if version := await GameResourceDownloader.check_update():
for route in RESOURCE_ROUTES:
logger.info(f"正在下载: {route}")
await GameResourceDownloader.download_all(
owner="yuanyan3060",
repo="ArknightsGameResource",
route=route,
branch="main",
)
except Exception as e:
logger.error("Error during resource update", exc_info=e)If there is a cache dump operation in your shutdown function (for example, within a @driver.on_shutdown decorated function), Wrap that operation in a similar try/except block to catch and log any IO errors during shutdown. |
||
| if config.check_res_update: | ||
| try: | ||
| if version := await GameResourceDownloader.check_update(): | ||
| logger.info("开始下载游戏资源") | ||
| for route in RESOURCE_ROUTES: | ||
| logger.info(f"正在下载: {route}") | ||
| await GameResourceDownloader.download_all( | ||
| owner="yuanyan3060", repo="ArknightsGameResource", route=route, branch="main" | ||
| owner="yuanyan3060", | ||
| repo="ArknightsGameResource", | ||
| route=route, | ||
| branch="main", | ||
| ) | ||
| except RequestException as e: | ||
| logger.error(f"下载游戏资源失败: {e}") | ||
| return | ||
| if version: | ||
| GameResourceDownloader.update_version_file(version) | ||
| logger.success(f"游戏资源已更新到版本:{version}") | ||
|
|
||
|
|
||
| @driver.on_shutdown | ||
| async def shutdown(): | ||
| command_manager.dump_cache(shortcut_cache) | ||
| logger.debug("Skland shortcuts cache dumped") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: 澄清关于自定义命令的
COMMAND_START的说明。“自定义指令不带 COMMAND_START” 一句不太清晰,因为示例别名
/兔兔签到已包含/。请说明“自定义指令”指的是快捷别名还是目标命令字符串,并举例说明何时需手动添加COMMAND_START。Original comment in English
suggestion: Clarify the note about
COMMAND_STARTfor custom commands.“自定义指令不带 COMMAND_START” 一句不太清晰,因为示例别名
/兔兔签到已包含/。请说明“自定义指令”指的是快捷别名还是目标命令字符串,并举例说明何时需手动添加COMMAND_START。