Skip to content

feat: new ProtoStruct #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lagrange/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .utils.sign import sign_provider
from .info import InfoManager
from .info.app import app_list
from .utils.binary.protobuf.models import evaluate_all


class Lagrange:
Expand Down Expand Up @@ -66,3 +67,6 @@ def launch(self):
log.root.info("Program exited by user")
else:
log.root.info("Program exited normally")


evaluate_all()
2 changes: 1 addition & 1 deletion lagrange/client/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def _task_exec(self, client: "Client", event: "BaseEvent", handler: EVENT_
try:
await handler(client, event)
except Exception as e:
log.root.error(
log.root.exception(
f"Unhandled exception on task {event}", exc_info=e
)

Expand Down
6 changes: 3 additions & 3 deletions lagrange/pb/highway/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class AudioExtInfo(ProtoStruct):


class ExtBizInfo(ProtoStruct):
pic: PicExtInfo = proto_field(1, default=PicExtInfo())
video: VideoExtInfo = proto_field(2, default=VideoExtInfo())
audio: AudioExtInfo = proto_field(3, default=AudioExtInfo())
pic: PicExtInfo = proto_field(1, default_factory=PicExtInfo)
video: VideoExtInfo = proto_field(2, default_factory=VideoExtInfo)
audio: AudioExtInfo = proto_field(3, default_factory=AudioExtInfo)
bus_type: Optional[int] = proto_field(4, default=None)


Expand Down
4 changes: 2 additions & 2 deletions lagrange/pb/highway/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class DownloadVideoExt(ProtoStruct):

class DownloadExt(ProtoStruct):
pic_ext: Optional[bytes] = proto_field(1, default=None)
video_ext: DownloadVideoExt = proto_field(2, default=DownloadVideoExt())
video_ext: DownloadVideoExt = proto_field(2, default_factory=DownloadVideoExt)
ptt_ext: Optional[bytes] = proto_field(3, default=None)


class DownloadReq(ProtoStruct):
node: IndexNode = proto_field(1)
ext: DownloadExt = proto_field(2, default=DownloadExt())
ext: DownloadExt = proto_field(2, default_factory=DownloadExt)


class NTV2RichMediaReq(ProtoStruct):
Expand Down
4 changes: 2 additions & 2 deletions lagrange/pb/highway/rsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class DownloadInfo(ProtoStruct):
domain: str = proto_field(1)
url_path: str = proto_field(2)
https_port: Optional[int] = proto_field(3, default=None)
v4_addrs: list[IPv4] = proto_field(4, default=[])
v6_addrs: list[IPv6] = proto_field(5, default=[])
v4_addrs: list[IPv4] = proto_field(4, default_factory=list)
v6_addrs: list[IPv6] = proto_field(5, default_factory=list)
pic_info: Optional[PicUrlExtInfo] = proto_field(6, default=None)
video_info: Optional[VideoExtInfo] = proto_field(7, default=None)

Expand Down
6 changes: 3 additions & 3 deletions lagrange/pb/message/rich_text/elems.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NotOnlineImage(ProtoStruct):
width: int = proto_field(9)
res_id: str = proto_field(10)
origin_path: Optional[str] = proto_field(15, default=None)
args: ImageReserveArgs = proto_field(34, default=ImageReserveArgs())
args: ImageReserveArgs = proto_field(34, default_factory=ImageReserveArgs)


class TransElem(ProtoStruct):
Expand Down Expand Up @@ -90,7 +90,7 @@ class CustomFace(ProtoStruct):
width: int = proto_field(22)
height: int = proto_field(23)
size: int = proto_field(25)
args: ImageReserveArgs = proto_field(34, default=ImageReserveArgs())
args: ImageReserveArgs = proto_field(34, default_factory=ImageReserveArgs)


class ExtraInfo(ProtoStruct):
Expand All @@ -110,7 +110,7 @@ class SrcMsg(ProtoStruct):
seq: int = proto_field(1)
uin: int = proto_field(2, default=0)
timestamp: int = proto_field(3)
elems: list[dict] = proto_field(5, default=[{}])
elems: list[dict] = proto_field(5, default_factory=lambda: [{}])
pb_reserved: Optional[SrcMsgArgs] = proto_field(8, default=None)
to_uin: int = proto_field(10, default=0)

Expand Down
2 changes: 1 addition & 1 deletion lagrange/pb/service/friend.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PBGetFriendListRequest(ProtoStruct):
f7: int = proto_field(7, default=2147483647) # MaxValue
body: list[GetFriendBody] = proto_field(
10001,
default=[
default_factory=lambda: [
GetFriendBody(type=1, f2=GetFriendNumbers(f1=[103, 102, 20002, 27394])),
GetFriendBody(type=4, f2=GetFriendNumbers(f1=[100, 101, 102])),
],
Expand Down
26 changes: 13 additions & 13 deletions lagrange/pb/service/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ class MemberInfoLevel(ProtoStruct):
num: int = proto_field(2)


class GetGrpMemberInfoRsp(ProtoStruct):
grp_id: int = proto_field(1)
body: "list[GetGrpMemberInfoRspBody]" = proto_field(2)
next_key: Optional[bytes] = proto_field(15, default=None) # base64(pb)


class GetGrpMemberInfoRspBody(ProtoStruct):
account: AccountInfo = proto_field(1)
nickname: str = proto_field(10, default="")
Expand All @@ -342,12 +348,6 @@ def is_owner(self) -> bool:
return not self.is_admin and self.permission == 2


class GetGrpMemberInfoRsp(ProtoStruct):
grp_id: int = proto_field(1)
body: list[GetGrpMemberInfoRspBody] = proto_field(2)
next_key: Optional[bytes] = proto_field(15, default=None) # base64(pb)


class GetGrpListReqBody(ProtoStruct):
cfg1: bytes = proto_field(1)
cfg2: bytes = proto_field(2)
Expand Down Expand Up @@ -396,7 +396,7 @@ class GrpInfo(ProtoStruct):


class GetGrpListResponse(ProtoStruct):
grp_list: list[GrpInfo] = proto_field(2, default=[])
grp_list: list[GrpInfo] = proto_field(2, default_factory=list)


class PBGetInfoFromUidReq(ProtoStruct):
Expand Down Expand Up @@ -425,19 +425,19 @@ def to_str(self) -> str:


class GetInfoRspField(ProtoStruct, debug=True):
int_t: list[GetInfoRspF1] = proto_field(1, default=[])
str_t: list[GetInfoRspF2] = proto_field(2, default=[])
int_t: list[GetInfoRspF1] = proto_field(1, default_factory=list)
str_t: list[GetInfoRspF2] = proto_field(2, default_factory=list)


class GetInfoFromUidRsp(ProtoStruct):
body: list["GetInfoRspBody"] = proto_field(1)


class GetInfoRspBody(ProtoStruct):
uid: str = proto_field(1)
fields: GetInfoRspField = proto_field(2)


class GetInfoFromUidRsp(ProtoStruct):
body: list[GetInfoRspBody] = proto_field(1)


class Oidb88D0Args(ProtoStruct):
seq: Optional[int] = proto_field(22, default=None)

Expand Down
14 changes: 7 additions & 7 deletions lagrange/pb/status/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ class GroupSub16Head(ProtoStruct):
f44: Optional[PBGroupReaction] = proto_field(44, default=None) # set reaction only


class GroupSub20Head(ProtoStruct):
f1: int = proto_field(1) # 20
grp_id: int = proto_field(4)
f13: int = proto_field(13) # 19
body: "GroupSub20Body" = proto_field(26)


class GroupSub20Body(ProtoStruct):
type: int = proto_field(1) # 12: nudge, 14: group_sign
# f2: int = proto_field(2) # 1061
Expand All @@ -121,13 +128,6 @@ class GroupSub20Body(ProtoStruct):
f10: int = proto_field(10) # rand?


class GroupSub20Head(ProtoStruct):
f1: int = proto_field(1) # 20
grp_id: int = proto_field(4)
f13: int = proto_field(13) # 19
body: GroupSub20Body = proto_field(26)


class PBGroupAlbumUpdateBody(ProtoStruct):
# f1: 6
args: str = proto_field(2)
Expand Down
Loading