Skip to content

Commit bf43226

Browse files
committed
feat(msg): parse GreyTips
1 parent c8a895c commit bf43226

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

lagrange/client/message/decoder.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import zlib
23
from typing import TYPE_CHECKING, cast, Literal, Union
34
from collections.abc import Sequence
@@ -76,7 +77,7 @@ async def parse_msg_new(
7677
for raw in el:
7778
if not raw or raw == Elems():
7879
continue
79-
elif raw.elem_flags2 or raw.general_flags or raw.extra_info:
80+
elif raw.elem_flags2 or raw.extra_info:
8081
# unused flags
8182
continue
8283
elif ignore_next:
@@ -100,6 +101,11 @@ async def parse_msg_new(
100101
)
101102
else:
102103
raise AssertionError("Invalid message")
104+
elif raw.general_flags and raw.general_flags.PbReserve:
105+
gf = raw.general_flags
106+
if gf.PbReserve.grey:
107+
content = json.loads(gf.PbReserve.grey.body.content)
108+
msg_chain.append(elems.GreyTips(text=content["gray_tip"]))
103109
elif raw.face: # q emoji
104110
emo = raw.face
105111
msg_chain.append(elems.Emoji(id=emo.index))

lagrange/client/message/elems.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,6 @@ class GreyTips(Text):
187187
建议搭配Text使用
188188
冷却3分钟左右?
189189
"""
190-
...
190+
@property
191+
def display(self) -> str:
192+
return f"<GreyTips: {self.text}>"

lagrange/client/message/encoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def build_message(msg_chain: list[Element], compatible=True) -> RichText:
189189
msg_pb.append(
190190
Elems(
191191
general_flags=GeneralFlags(
192-
PbReserve=PBGreyTips.build(content).encode()
192+
PbReserve=PBGreyTips.build(content)
193193
)
194194
)
195195
)

lagrange/pb/message/rich_text/elems.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,28 @@ class GroupFileExtra(ProtoStruct):
198198
inner: GroupFileExtraInner = proto_field(7)
199199

200200

201+
class GreyTipsExtraInfo(ProtoStruct):
202+
typ: int = proto_field(1, default=1)
203+
content: str = proto_field(2) # json
204+
205+
206+
class GreyTipsExtra(ProtoStruct):
207+
body: GreyTipsExtraInfo = proto_field(1)
208+
209+
class PBGreyTips(ProtoStruct):
210+
grey: Optional[GreyTipsExtra] = proto_field(101, default=None)
211+
212+
@classmethod
213+
def build(cls, content: str) -> "PBGreyTips":
214+
return cls(
215+
grey=GreyTipsExtra(
216+
body=GreyTipsExtraInfo(
217+
content=content,
218+
)
219+
)
220+
)
221+
222+
201223
class GeneralFlags(ProtoStruct):
202224
BubbleDiyTextId: Optional[int] = proto_field(1, default=None)
203225
GroupFlagNew: Optional[int] = proto_field(2, default=None)
@@ -217,26 +239,4 @@ class GeneralFlags(ProtoStruct):
217239
BubbleSubId: Optional[int] = proto_field(16, default=None)
218240
PendantId: Optional[int] = proto_field(17, default=None)
219241
RpIndex: Optional[bytes] = proto_field(18, default=None)
220-
PbReserve: Optional[bytes] = proto_field(19)
221-
222-
223-
class GreyTipsExtraInfo(ProtoStruct):
224-
typ: int = proto_field(1, default=1)
225-
content: str = proto_field(2) # json
226-
227-
228-
class GreyTipsExtra(ProtoStruct):
229-
body: GreyTipsExtraInfo = proto_field(1)
230-
231-
class PBGreyTips(ProtoStruct):
232-
grey: GreyTipsExtra = proto_field(101)
233-
234-
@classmethod
235-
def build(cls, content: str) -> "PBGreyTips":
236-
return cls(
237-
grey=GreyTipsExtra(
238-
body=GreyTipsExtraInfo(
239-
content=content,
240-
)
241-
)
242-
)
242+
PbReserve: Optional[PBGreyTips] = proto_field(19, default=None)

0 commit comments

Comments
 (0)