Skip to content

Commit

Permalink
🐛 version 0.2.1
Browse files Browse the repository at this point in the history
fix event.get_session_id
  • Loading branch information
RF-Tar-Railt committed Sep 14, 2023
1 parent 8dd266d commit 9f4f9d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
38 changes: 29 additions & 9 deletions nonebot/adapters/red/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
)
Expand All @@ -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]
Expand All @@ -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):
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"},
Expand Down

0 comments on commit 9f4f9d4

Please sign in to comment.