Skip to content

Commit 9df58ad

Browse files
committed
fix: FinishedException() handling in handle_net
1 parent 697cdbf commit 9df58ad

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Data directory
2+
data/
3+
4+
# Python cache
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# IDEs
10+
.vscode/
11+
.idea/

nonebot_plugin_maimaimonitor/maimai_plugin_v11.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from nonebot import on_command, on_message, get_driver, require
44
from nonebot.rule import Rule
55
from nonebot.matcher import Matcher
6+
from nonebot.exception import FinishedException
67
from nonebot.adapters.onebot.v11 import Bot, Event, Message, MessageSegment
78
from nonebot.params import CommandArg
89
import httpx
@@ -65,11 +66,12 @@ async def handle_net(matcher: Matcher):
6566
if cache_file.exists():
6667
if time.time() - cache_file.stat().st_mtime < CACHE_TTL:
6768
try:
68-
await matcher.send(MessageSegment.image(cache_file.read_bytes()))
69+
img_data = cache_file.read_bytes()
70+
await matcher.send(MessageSegment.image(img_data))
6971
await matcher.finish()
70-
except Exception as e:
71-
if "FinishedException" in type(e).__name__:
72-
raise e
72+
except FinishedException:
73+
raise
74+
except Exception:
7375
cache_file.unlink(missing_ok=True)
7476

7577
try:
@@ -87,16 +89,17 @@ async def handle_net(matcher: Matcher):
8789
except Exception:
8890
try:
8991
await matcher.send(MessageSegment.image(OG_API_URL))
90-
except Exception as e:
91-
raise e
92+
except FinishedException:
93+
raise
94+
except Exception:
95+
pass
9296

9397
await matcher.finish()
9498
else:
9599
await matcher.finish(f"获取状态图失败 (HTTP {response.status_code})\nURL: {OG_API_URL}\n请检查网络连接或 API 状态。")
100+
except FinishedException:
101+
raise
96102
except Exception as e:
97-
if "FinishedException" in type(e).__name__:
98-
raise e
99-
100103
error_type = type(e).__name__
101104
error_details = str(e)
102105
tb = traceback.format_exc()

0 commit comments

Comments
 (0)