fix: Catch UnknownTarget exception in sender
This commit is contained in:
parent
1b00ae2326
commit
cfd8a57cee
@ -5,7 +5,7 @@ from typing import Optional, List, Dict, Any, Union, Callable, Tuple
|
||||
|
||||
from graia.ariadne import Ariadne
|
||||
from graia.ariadne.connection.config import config as AriadneConfig, HttpClientConfig, WebsocketClientConfig
|
||||
from graia.ariadne.exception import RemoteException, AccountMuted
|
||||
from graia.ariadne.exception import RemoteException, AccountMuted, UnknownTarget
|
||||
from graia.ariadne.message.chain import MessageChain
|
||||
from graia.ariadne.message.element import At, AtAll
|
||||
from graia.ariadne.model import LogConfig, MemberPerm
|
||||
@ -90,6 +90,8 @@ class Bot(BaseModel):
|
||||
except AccountMuted:
|
||||
logger.warning(f"Bot({self.qq}) 在群 {msg.id} 中被禁言")
|
||||
return
|
||||
except UnknownTarget:
|
||||
return
|
||||
except RemoteException as ex:
|
||||
if "AT_ALL_LIMITED" in str(ex):
|
||||
logger.warning(f"Bot({self.qq}) 今日的@全体成员次数已达到上限")
|
||||
@ -145,7 +147,10 @@ class Bot(BaseModel):
|
||||
chain = chain.exclude(AtAll)
|
||||
|
||||
# 过滤 Bot 不是群管理员时的 @全体成员 消息
|
||||
try:
|
||||
bot_info = await self.__bot.get_member(message.id, self.qq)
|
||||
except UnknownTarget:
|
||||
return new_chains, exception
|
||||
if bot_info.permission < MemberPerm.Administrator:
|
||||
exception = NoPermissionException()
|
||||
chain = chain.exclude(AtAll)
|
||||
|
@ -10,6 +10,7 @@ from io import BytesIO
|
||||
from typing import Tuple, List, Dict, Sized, Optional, Any, Union
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
from loguru import logger
|
||||
|
||||
from . import config
|
||||
from .Credential import Credential
|
||||
@ -166,7 +167,8 @@ async def get_unames_and_faces_by_uids(uids: List[str]) -> Tuple[List[str], List
|
||||
user_info_url = f"https://api.vc.bilibili.com/account/v1/user/cards?uids={','.join(uids)}"
|
||||
try:
|
||||
infos_list = await request("GET", user_info_url)
|
||||
except ResponseCodeException:
|
||||
except ResponseCodeException as ex:
|
||||
logger.exception("批量获取昵称和头像图片异常", ex)
|
||||
return [], []
|
||||
infos = dict(zip([x["mid"] for x in infos_list], infos_list))
|
||||
unames = [infos[int(uid)]["name"] if int(uid) in infos else "" for uid in uids]
|
||||
|
Loading…
x
Reference in New Issue
Block a user