Skip to content
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

✨ 发送部分丰富日志记录,扩大可刷新bot的异常范围 #508

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions nonebot_bison/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from collections import deque

from nonebot.log import logger
from nonebot.exception import ActionFailed
from nonebot_plugin_saa.auto_select_bot import refresh_bots
from nonebot.adapters.onebot.v11.exception import ActionFailed
from nonebot_plugin_saa import MessageFactory, PlatformTarget, AggregatedMessageFactory

from .plugin_config import plugin_config
Expand All @@ -18,9 +18,9 @@
async def _do_send(send_target: PlatformTarget, msg: Sendable):
try:
await msg.send_to(send_target)
except ActionFailed: # TODO: catch exception of other adapters
except ActionFailed: # catch exception of sending message
await refresh_bots()
logger.warning("send msg failed, refresh bots")
logger.warning(f"send msg: {msg!s} to {send_target} failed, refresh bots")


async def do_send_msgs():
Expand All @@ -34,17 +34,15 @@ async def do_send_msgs():
# So, read from queue first then pop from it
send_target, msg_factory, retry_time = QUEUE[0]
try:
logger.debug(f"send msg {msg_factory!s} to {send_target}")
await _do_send(send_target, msg_factory)
except Exception as e:
await asyncio.sleep(MESSGE_SEND_INTERVAL)
QUEUE.popleft()
if retry_time > 0:
QUEUE.appendleft((send_target, msg_factory, retry_time - 1))
else:
msg_str = str(msg_factory)
if len(msg_str) > 50:
msg_str = msg_str[:50] + "..."
logger.warning(f"send msg err {e} {msg_str}")
logger.warning(f"send msg to {send_target} err {e}: {msg_factory!s}")
else:
# sleeping after popping may also cause re-execution error like above mentioned
await asyncio.sleep(MESSGE_SEND_INTERVAL)
Expand Down
Loading