添加对会员/活动特殊动图(创意玩法)戳一戳处理

添加对创意玩法内只有表情动图而不带文字描述的会员与活动特殊戳一戳进行处理

已知问题:动图只能够识别第一帧(可以尝试通过动图URL解析成文字描述,但如果官方更新可能会失效(?),而且我不会python :( )
pull/70/head
IMIG 2025-11-02 08:59:35 +08:00 committed by GitHub
parent 424ca5b473
commit 218c16c60c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 56 additions and 19 deletions

View File

@ -175,11 +175,11 @@ class NoticeHandler:
) -> Tuple[Seg | None, UserInfo | None]:
# sourcery skip: merge-comparisons, merge-duplicate-blocks, remove-redundant-if, remove-unnecessary-else, swap-if-else-branches
self_info: dict = await get_self_info(self.server_connection)
if not self_info:
logger.error("自身信息获取失败")
return None, None
self_id = raw_message.get("self_id")
target_id = raw_message.get("target_id")
target_name: str = None
@ -195,17 +195,15 @@ class NoticeHandler:
else:
user_name = "QQ用户"
user_cardname = "QQ用户"
logger.info("无法获取戳一戳对方的用户昵称")
logger.info("无法获取戳一戳对方的用户昵称,使用默认昵称")
# 计算Seg
if self_id == target_id:
display_name = ""
target_name = self_info.get("nickname")
elif self_id == user_id:
# 让ada不发送麦麦戳别人的消息
return None, None
else:
# 老实说这一步判定没啥意义,毕竟私聊是没有其他人之间的戳一戳,但是感觉可以有这个判定来强限制群聊环境
if group_id:
@ -214,31 +212,70 @@ class NoticeHandler:
target_name = fetched_member_info.get("nickname")
else:
target_name = "QQ用户"
logger.info("无法获取被戳一戳方的用户昵称")
logger.info("无法获取被戳一戳方的用户昵称,使用默认昵称")
display_name = user_name
else:
return None, None
first_txt: str = "戳了戳"
second_txt: str = ""
try:
first_txt = raw_info[2].get("txt", "戳了戳")
second_txt = raw_info[4].get("txt", "")
except Exception as e:
logger.warning(f"解析戳一戳消息失败: {str(e)},将使用默认文本")
user_info: UserInfo = UserInfo(
platform=global_config.maibot_server.platform_name,
user_id=user_id,
user_nickname=user_name,
user_cardname=user_cardname,
)
seg_data: Seg = Seg(
seg_data: List[Seg] = []
acton_seg: Seg = Seg(type=RealMessageType.text, data="戳了戳")
action: str = "戳了戳"
second_txt: str = ""
submit_notice_seg: Seg = None
try:
if raw_info[2].get("type") == "qq":
"""
#可选不处理任意用户自戳
if raw_info[2].get("tp") == "1":
logger.info("不处理用户自戳")
return None, None
"""
try:
image_base64 = await get_image_base64(raw_info[1].get("src"))
acton_seg = Seg(type="emoji", data=image_base64)
except Exception as e:
logger.error(f"会员/活动戳一戳动图处理失败: {str(e)}")
acton_seg = Seg(type=RealMessageType.text, data="戳了戳")
second_txt = raw_info[3].get("txt", "")
suffix: str = f"{target_name}{second_txt}"
seg_data.append(Seg(type=RealMessageType.text, data=display_name))
seg_data.append(acton_seg)
seg_data.append(Seg(type=RealMessageType.text, data=suffix))
submit_notice_seg = Seg(
type="seglist",
data=seg_data,
)
return submit_notice_seg, user_info
else:
if raw_info[3].get("tp") == "1":
logger.info("不处理bot自戳")
return None, None
action = raw_info[2].get("txt", "戳了戳")
second_txt = raw_info[4].get("txt", "")
#Lagrange poke
#logger.info(f"action:{action}")
#logger.info(f"suffix:{second_txt}")
#action = raw_message.get("action", "戳了戳")
#second_txt = raw_message.get("suffix", "")
except Exception as e:
logger.warning(f"解析戳一戳消息失败: {str(e)},将使用默认文本")
submit_notice_seg = Seg(
type="text",
data=f"{display_name}{first_txt}{target_name}{second_txt}这是QQ的一个功能用于提及某人但没那么明显",
data=f"{display_name}{action}{target_name}{second_txt}这是QQ的一个功能用于提及某人但没那么明显",
#data=f"{display_name}{action}{target_name}{second_txt}",
)
return seg_data, user_info
return submit_notice_seg, user_info
async def handle_ban_notify(self, raw_message: dict, group_id: int) -> Tuple[Seg, UserInfo] | Tuple[None, None]:
if not group_id: