diff --git a/nonebot/adapters/red/event.py b/nonebot/adapters/red/event.py index bf9edd5..6e597ba 100644 --- a/nonebot/adapters/red/event.py +++ b/nonebot/adapters/red/event.py @@ -92,7 +92,7 @@ def get_user_id(self) -> str: @override def get_session_id(self) -> str: # 获取事件会话 ID 的方法,根据事件具体实现,如果事件没有相关 ID,则抛出异常 - return self.msgId + return f"{self.peerUin or self.peerUid}_{self.senderUin or self.senderUid}" @override def is_tome(self) -> bool: @@ -154,11 +154,6 @@ def get_type(self) -> str: def get_event_name(self) -> str: return "notice" - @override - def get_session_id(self) -> str: - # 获取事件会话 ID 的方法,根据事件具体实现,如果事件没有相关 ID,则抛出异常 - return self.msgId - @property def scene(self) -> str: """群组或好友的id""" @@ -193,6 +188,11 @@ def get_user_id(self) -> str: raise ValueError("user_id doesn't exist.") return self.operatorUid + @override + def get_session_id(self) -> str: + # 获取事件会话 ID 的方法,根据事件具体实现,如果事件没有相关 ID,则抛出异常 + return f"{self.peerUin or self.peerUid}_{self.operatorUid}" + @classmethod @override def convert(cls, obj: Any): @@ -236,6 +236,11 @@ def get_event_description(self) -> str: def get_user_id(self) -> str: return self.memberUid + @override + def get_session_id(self) -> str: + # 获取事件会话 ID 的方法,根据事件具体实现,如果事件没有相关 ID,则抛出异常 + return f"{self.peerUin or self.peerUid}_{self.memberUid}" + legacy_invite_message = re.compile( r'jp="(\d+)".*jp="(\d+)"', re.DOTALL | re.MULTILINE | re.IGNORECASE ) @@ -256,7 +261,11 @@ def convert(cls, obj: Any): "peerUin": obj.peerUin, } if obj.elements[0].grayTipElement.xmlElement: # type: ignore - if not (mat := cls.legacy_invite_message.match(obj.elements[0].grayTipElement.xmlElement.content)): # type: ignore # noqa: E501 + if not ( + mat := cls.legacy_invite_message.match( + obj.elements[0].grayTipElement.xmlElement.content + ) + ): # type: ignore # noqa: E501 raise ValueError("Invalid legacy invite message.") params["operatorUid"] = mat[1] params["memberUid"] = mat[2] @@ -279,6 +288,11 @@ class MemberMuteEvent(NoticeEvent): def get_user_id(self) -> str: return self.member.uin or self.member.uid + @override + def get_session_id(self) -> str: + # 获取事件会话 ID 的方法,根据事件具体实现,如果事件没有相关 ID,则抛出异常 + return f"{self.peerUin or self.peerUid}_{self.member.uin or self.member.uid}" + @classmethod @override def convert(cls, obj: Any): @@ -293,8 +307,14 @@ def convert(cls, obj: Any): "subMsgType": obj.subMsgType, "peerUid": obj.peerUid, "peerUin": obj.peerUin, - "start": datetime.fromtimestamp(obj.elements[0].grayTipElement.groupElement.shutUp.curTime), # type: ignore # noqa: E501 - "duration": timedelta(seconds=obj.elements[0].grayTipElement.groupElement.shutUp.duration), # type: ignore # noqa: E501 + "start": datetime.fromtimestamp( + obj.elements[0].grayTipElement.groupElement.shutUp.curTime + ), + # type: ignore # noqa: E501 + "duration": timedelta( + seconds=obj.elements[0].grayTipElement.groupElement.shutUp.duration + ), + # type: ignore # noqa: E501 "operator": obj.elements[0].grayTipElement.groupElement.shutUp.admin, # type: ignore # noqa: E501 "member": obj.elements[0].grayTipElement.groupElement.shutUp.member, # type: ignore # noqa: E501 } diff --git a/pyproject.toml b/pyproject.toml index 99e29fe..59d3814 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot-adapter-red" -version = "0.2.0" +version = "0.2.1" description = "Red Protocol Adapter for Nonebot2" authors = [ {name = "zhaomaoniu"},