nonebot/adapter-onebot

MessageSegment.node_custom 的 user_id 的类型注释应该同时支持 int 与 str

Harry-Jing opened this issue · 3 comments

最后都会类型转换

目前:

    @staticmethod
    def node_custom(
        user_id: int, nickname: str, content: Union[str, "Message"]
    ) -> "MessageSegment":
        return MessageSegment(
            "node", {"user_id": str(user_id), "nickname": nickname, "content": content}
        )

期待:

    @staticmethod
    def node_custom(
        user_id: Union[str, int], nickname: str, content: Union[str, "Message"]
    ) -> "MessageSegment":
        return MessageSegment(
            "node", {"user_id": str(user_id), "nickname": nickname, "content": content}
        )

根据onebot协议规定,这里就是int

主要是感觉每次转换都很麻烦(

要写成

MessageSegment.node_custom(
            user_id=int(bot.self_id),
            nickname='name',
            content='echo',
        )

而不是

MessageSegment.node_custom(
            user_id=bot.self_id,
            nickname='name',
            content='echo',
        )