33from nonebot import on_command , on_message , get_driver , require
44from nonebot .rule import Rule
55from nonebot .matcher import Matcher
6+ from nonebot .exception import FinishedException
67from nonebot .adapters .onebot .v11 import Bot , Event , Message , MessageSegment
78from nonebot .params import CommandArg
89import 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 } )\n URL: { 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