Skip to content

Conversation

@sileence114
Copy link
Contributor

client.py

  • 添加 Client.fetch_message(...)
  • 增加 Client.fetch_direct_message(...)

message.py

QuotedMessage - PublicQuotedMessage
              - PrivateQuotedMessage
RawMessage - Event
           - Message - PublicMessage{quote: PublicQuotedMessage}
                     - PrivateMessage{quote: PrivateQuotedMessage}

更改为

RawMessage - Event
           - Message(LazyLoadable) - PublicMessage{quote: PublicMessage}
                                   - PrivateMessage{quote: PrivateMessage}
  • 将 *QuotedMessage 视为未加载的 *Message,与 *Message 合并;
  • 更多的方法被抽象到 Message 类中;
  • P*Message 的构造函数支持:
    • P*Message(**data_from_event) # 从事件接收的 pkg 构造;
    • P*Message(**data_from_view) # 从 *msg/view 返回数据构造;
    • P*Message(**data_from_event_or_view.quote) # 从以上两者的 .get('quote') 构造(引用);
  • 兼容性:
    • 从 event 构造的对象字段与之前的版本完全兼容;
    • 从 view 和 quote 构造对象的 extra 属性为 {};
    • 从 quote 构造对象的部分字段不可用,需要 .load() 后才能使用;
  • RawMessage 应当重命名为 RawEvent 以提高可读性。

其他

  • PrivateChannel 的 target_info 类型更改 Dict of raw_user -> User;
  • 增加部分 rule 的类型判断;
  • 完善部分 type hints 及注释。

Copy link
Owner

@TWT233 TWT233 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还没看 message.py,这个文件改动有点太大了,要稍晚一点看

khl/channel.py Outdated
self.is_blocked: bool = kwargs.get('is_blocked')
self.is_target_blocked: bool = kwargs.get('is_target_blocked')
self.target_info: Dict = kwargs.get('target_info')
self.target_info: User = kwargs.get('target_info')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换成 User 的话需要构造,因为构造函数内部还有逻辑,不是纯 data class

Copy link
Contributor Author

@sileence114 sileence114 Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我保留一下兼容性:

self.target: User = User(...)
self._target_info: Dict = kwargs.get('target_info')
@property
def target_info(self):
    warnings.warn("deprecated", ...)
    return self._target_info

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以单独开一个MR改这里的,因为看起来和当前MR主题关联不紧密

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

推荐单独提MR,拆成小commit过得也很快

khl/client.py Outdated
req = api.Message.view(msg_id=msg_id)
return PublicMessage(_gate_=self.gate, **(await self.gate.exec_req(req)))

async def fetch_direct_message(self, chat_code: str, msg_id: str):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async def fetch_direct_message(self, chat_code: str, msg_id: str):
async def fetch_private_message(self, chat_code: str, msg_id: str):

client层可以屏蔽掉底层API的命名,切换成我们提供的概念,统一性和可理解性更好

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以单独提MR?不过涉及 PublicMessage,有没有先后次序关系

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也可以单独提,不过这个typo改动很小,合并进来也可以

khl/util.py Outdated

def unpack_id(obj):
"""extract obj's id if not basic data type"""
"""extract objet's id if not basic data type"""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""extract objet's id if not basic data type"""
"""extract object's id if not basic data type"""

不过就用 obj 的话能对应参数名,方便理解

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obj's IDE 会划波浪线,不过不该也无所谓

@TWT233 TWT233 added changes requested reviewed but question pops need review new / changed labels Jan 18, 2024
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有点太大了,review时间可能会有点长

@sileence114
Copy link
Contributor Author

sileence114 commented Feb 6, 2024

两个小的MR已提交,修改doc-string的那个不管了。
msg.py等下次抽空整理一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes requested reviewed but question pops need review new / changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants