magic-campus-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- magic_campus_cli-0.1.0.dist-info/METADATA +51 -0
- magic_campus_cli-0.1.0.dist-info/RECORD +53 -0
- magic_campus_cli-0.1.0.dist-info/WHEEL +5 -0
- magic_campus_cli-0.1.0.dist-info/entry_points.txt +2 -0
- magic_campus_cli-0.1.0.dist-info/top_level.txt +2 -0
- magiccampus_cli/__init__.py +1 -0
- magiccampus_cli/__main__.py +9 -0
- magiccampus_cli/accounts.py +144 -0
- magiccampus_cli/cli.py +176 -0
- magiccampus_cli/client.py +54 -0
- magiccampus_cli/commands/auth.py +32 -0
- magiccampus_cli/commands/comment.py +38 -0
- magiccampus_cli/commands/config.py +95 -0
- magiccampus_cli/commands/feed.py +26 -0
- magiccampus_cli/commands/group.py +346 -0
- magiccampus_cli/commands/im.py +47 -0
- magiccampus_cli/commands/notify.py +81 -0
- magiccampus_cli/commands/playgroup.py +49 -0
- magiccampus_cli/commands/reaction.py +50 -0
- magiccampus_cli/commands/space.py +134 -0
- magiccampus_cli/commands/user.py +311 -0
- magiccampus_cli/config_store.py +61 -0
- magiccampus_cli/notify.py +493 -0
- magiccampus_cli/output.py +104 -0
- magiccampus_cli/prompts.py +58 -0
- magiccampus_cli/targets.py +26 -0
- magiccampus_cli/update.py +149 -0
- magiccampus_cli/utils.py +67 -0
- magiccampus_sdk/__init__.py +43 -0
- magiccampus_sdk/auth.py +111 -0
- magiccampus_sdk/comment_client.py +107 -0
- magiccampus_sdk/feed_api.py +61 -0
- magiccampus_sdk/feed_client.py +30 -0
- magiccampus_sdk/group_api.py +139 -0
- magiccampus_sdk/group_client.py +242 -0
- magiccampus_sdk/http/__init__.py +1 -0
- magiccampus_sdk/http/group_info_api.py +47 -0
- magiccampus_sdk/http/http_api.py +58 -0
- magiccampus_sdk/http/http_send.py +758 -0
- magiccampus_sdk/http/media.py +839 -0
- magiccampus_sdk/http/models.py +645 -0
- magiccampus_sdk/http/self_user_info_api.py +182 -0
- magiccampus_sdk/http/text.py +75 -0
- magiccampus_sdk/models.py +279 -0
- magiccampus_sdk/platform_client.py +137 -0
- magiccampus_sdk/platform_http.py +71 -0
- magiccampus_sdk/playgroup_api.py +104 -0
- magiccampus_sdk/playgroup_client.py +45 -0
- magiccampus_sdk/reaction_api.py +110 -0
- magiccampus_sdk/space_api.py +170 -0
- magiccampus_sdk/space_client.py +93 -0
- magiccampus_sdk/user_client.py +211 -0
- magiccampus_sdk/user_info_api.py +593 -0
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import Any, Dict, List, Mapping, Optional, Union
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _to_int(value: Any) -> int:
|
|
7
|
+
try:
|
|
8
|
+
return int(value)
|
|
9
|
+
except (TypeError, ValueError):
|
|
10
|
+
return 0
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _to_bool(value: Any) -> bool:
|
|
14
|
+
if isinstance(value, bool):
|
|
15
|
+
return value
|
|
16
|
+
if isinstance(value, str):
|
|
17
|
+
return value.lower() in {"1", "true", "yes", "on"}
|
|
18
|
+
if isinstance(value, int):
|
|
19
|
+
return value != 0
|
|
20
|
+
return bool(value)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _to_float(value: Any) -> float:
|
|
24
|
+
try:
|
|
25
|
+
return float(value)
|
|
26
|
+
except (TypeError, ValueError):
|
|
27
|
+
return 0.0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _parse_json(value: str) -> Any:
|
|
31
|
+
if not value:
|
|
32
|
+
return None
|
|
33
|
+
try:
|
|
34
|
+
return json.loads(value)
|
|
35
|
+
except Exception:
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ContentType:
|
|
40
|
+
TEXT = 101
|
|
41
|
+
PICTURE = 102
|
|
42
|
+
SOUND = 103
|
|
43
|
+
VIDEO = 104
|
|
44
|
+
FILE = 105
|
|
45
|
+
AT_TEXT = 106
|
|
46
|
+
MERGER = 107
|
|
47
|
+
CARD = 108
|
|
48
|
+
LOCATION = 109
|
|
49
|
+
CUSTOM = 110
|
|
50
|
+
TYPING = 113
|
|
51
|
+
QUOTE = 114
|
|
52
|
+
FACE = 115
|
|
53
|
+
ADVANCED_TEXT = 117
|
|
54
|
+
MARKDOWN_TEXT = 118
|
|
55
|
+
CUSTOM_MSG_NOT_TRIGGER_CONVERSATION = 119
|
|
56
|
+
CUSTOM_MSG_ONLINE_ONLY = 120
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
CONTENT_TYPE_NAMES: Dict[int, str] = {
|
|
60
|
+
ContentType.TEXT: "text",
|
|
61
|
+
ContentType.PICTURE: "picture",
|
|
62
|
+
ContentType.SOUND: "sound",
|
|
63
|
+
ContentType.VIDEO: "video",
|
|
64
|
+
ContentType.FILE: "file",
|
|
65
|
+
ContentType.AT_TEXT: "at_text",
|
|
66
|
+
ContentType.MERGER: "merger",
|
|
67
|
+
ContentType.CARD: "card",
|
|
68
|
+
ContentType.LOCATION: "location",
|
|
69
|
+
ContentType.CUSTOM: "custom",
|
|
70
|
+
ContentType.TYPING: "typing",
|
|
71
|
+
ContentType.QUOTE: "quote",
|
|
72
|
+
ContentType.FACE: "face",
|
|
73
|
+
ContentType.ADVANCED_TEXT: "advanced_text",
|
|
74
|
+
ContentType.MARKDOWN_TEXT: "markdown_text",
|
|
75
|
+
ContentType.CUSTOM_MSG_NOT_TRIGGER_CONVERSATION: "custom_not_trigger_conversation",
|
|
76
|
+
ContentType.CUSTOM_MSG_ONLINE_ONLY: "custom_online_only",
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_CONTENT_TYPE_ELEM_NAMES: Dict[int, str] = {
|
|
80
|
+
ContentType.TEXT: "textElem",
|
|
81
|
+
ContentType.PICTURE: "pictureElem",
|
|
82
|
+
ContentType.SOUND: "soundElem",
|
|
83
|
+
ContentType.VIDEO: "videoElem",
|
|
84
|
+
ContentType.FILE: "fileElem",
|
|
85
|
+
ContentType.AT_TEXT: "atTextElem",
|
|
86
|
+
ContentType.MERGER: "mergeElem",
|
|
87
|
+
ContentType.CARD: "cardElem",
|
|
88
|
+
ContentType.LOCATION: "locationElem",
|
|
89
|
+
ContentType.CUSTOM: "customElem",
|
|
90
|
+
ContentType.TYPING: "typingElem",
|
|
91
|
+
ContentType.QUOTE: "quoteElem",
|
|
92
|
+
ContentType.FACE: "faceElem",
|
|
93
|
+
ContentType.ADVANCED_TEXT: "advancedTextElem",
|
|
94
|
+
ContentType.MARKDOWN_TEXT: "markdownTextElem",
|
|
95
|
+
ContentType.CUSTOM_MSG_NOT_TRIGGER_CONVERSATION: "customElem",
|
|
96
|
+
ContentType.CUSTOM_MSG_ONLINE_ONLY: "customElem",
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass(frozen=True)
|
|
101
|
+
class PictureBaseInfo:
|
|
102
|
+
uuid: str = ""
|
|
103
|
+
type: str = ""
|
|
104
|
+
size: int = 0
|
|
105
|
+
width: int = 0
|
|
106
|
+
height: int = 0
|
|
107
|
+
url: str = ""
|
|
108
|
+
|
|
109
|
+
@classmethod
|
|
110
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "PictureBaseInfo":
|
|
111
|
+
return cls(
|
|
112
|
+
uuid=str(data.get("uuid", "") or ""),
|
|
113
|
+
type=str(data.get("type", "") or ""),
|
|
114
|
+
size=_to_int(data.get("size", 0)),
|
|
115
|
+
width=_to_int(data.get("width", 0)),
|
|
116
|
+
height=_to_int(data.get("height", 0)),
|
|
117
|
+
url=str(data.get("url", "") or ""),
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@dataclass(frozen=True)
|
|
122
|
+
class TextElem:
|
|
123
|
+
content: str = ""
|
|
124
|
+
|
|
125
|
+
@classmethod
|
|
126
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "TextElem":
|
|
127
|
+
return cls(content=str(data.get("content", "") or ""))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@dataclass(frozen=True)
|
|
131
|
+
class CardElem:
|
|
132
|
+
user_id: str = ""
|
|
133
|
+
nickname: str = ""
|
|
134
|
+
face_url: str = ""
|
|
135
|
+
ex: str = ""
|
|
136
|
+
|
|
137
|
+
@classmethod
|
|
138
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "CardElem":
|
|
139
|
+
return cls(
|
|
140
|
+
user_id=str(data.get("userID", "") or ""),
|
|
141
|
+
nickname=str(data.get("nickname", "") or ""),
|
|
142
|
+
face_url=str(data.get("faceURL", "") or ""),
|
|
143
|
+
ex=str(data.get("ex", "") or ""),
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@dataclass(frozen=True)
|
|
148
|
+
class PictureElem:
|
|
149
|
+
source_path: str = ""
|
|
150
|
+
source_picture: Optional[PictureBaseInfo] = None
|
|
151
|
+
big_picture: Optional[PictureBaseInfo] = None
|
|
152
|
+
snapshot_picture: Optional[PictureBaseInfo] = None
|
|
153
|
+
|
|
154
|
+
@classmethod
|
|
155
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "PictureElem":
|
|
156
|
+
source_picture_raw = data.get("sourcePicture")
|
|
157
|
+
big_picture_raw = data.get("bigPicture")
|
|
158
|
+
snapshot_picture_raw = data.get("snapshotPicture")
|
|
159
|
+
return cls(
|
|
160
|
+
source_path=str(data.get("sourcePath", "") or ""),
|
|
161
|
+
source_picture=PictureBaseInfo.from_dict(source_picture_raw)
|
|
162
|
+
if isinstance(source_picture_raw, Mapping)
|
|
163
|
+
else None,
|
|
164
|
+
big_picture=PictureBaseInfo.from_dict(big_picture_raw) if isinstance(big_picture_raw, Mapping) else None,
|
|
165
|
+
snapshot_picture=PictureBaseInfo.from_dict(snapshot_picture_raw)
|
|
166
|
+
if isinstance(snapshot_picture_raw, Mapping)
|
|
167
|
+
else None,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@dataclass(frozen=True)
|
|
172
|
+
class SoundElem:
|
|
173
|
+
uuid: str = ""
|
|
174
|
+
sound_path: str = ""
|
|
175
|
+
source_url: str = ""
|
|
176
|
+
data_size: int = 0
|
|
177
|
+
duration: int = 0
|
|
178
|
+
sound_type: str = ""
|
|
179
|
+
|
|
180
|
+
@classmethod
|
|
181
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "SoundElem":
|
|
182
|
+
return cls(
|
|
183
|
+
uuid=str(data.get("uuid", "") or ""),
|
|
184
|
+
sound_path=str(data.get("soundPath", "") or ""),
|
|
185
|
+
source_url=str(data.get("sourceUrl", "") or ""),
|
|
186
|
+
data_size=_to_int(data.get("dataSize", 0)),
|
|
187
|
+
duration=_to_int(data.get("duration", 0)),
|
|
188
|
+
sound_type=str(data.get("soundType", "") or ""),
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@dataclass(frozen=True)
|
|
193
|
+
class VideoElem:
|
|
194
|
+
video_path: str = ""
|
|
195
|
+
video_uuid: str = ""
|
|
196
|
+
video_url: str = ""
|
|
197
|
+
video_type: str = ""
|
|
198
|
+
video_size: int = 0
|
|
199
|
+
duration: int = 0
|
|
200
|
+
snapshot_path: str = ""
|
|
201
|
+
snapshot_uuid: str = ""
|
|
202
|
+
snapshot_size: int = 0
|
|
203
|
+
snapshot_url: str = ""
|
|
204
|
+
snapshot_width: int = 0
|
|
205
|
+
snapshot_height: int = 0
|
|
206
|
+
snapshot_type: str = ""
|
|
207
|
+
|
|
208
|
+
@classmethod
|
|
209
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "VideoElem":
|
|
210
|
+
return cls(
|
|
211
|
+
video_path=str(data.get("videoPath", "") or ""),
|
|
212
|
+
video_uuid=str(data.get("videoUUID", "") or ""),
|
|
213
|
+
video_url=str(data.get("videoUrl", "") or ""),
|
|
214
|
+
video_type=str(data.get("videoType", "") or ""),
|
|
215
|
+
video_size=_to_int(data.get("videoSize", 0)),
|
|
216
|
+
duration=_to_int(data.get("duration", 0)),
|
|
217
|
+
snapshot_path=str(data.get("snapshotPath", "") or ""),
|
|
218
|
+
snapshot_uuid=str(data.get("snapshotUUID", "") or ""),
|
|
219
|
+
snapshot_size=_to_int(data.get("snapshotSize", 0)),
|
|
220
|
+
snapshot_url=str(data.get("snapshotUrl", "") or ""),
|
|
221
|
+
snapshot_width=_to_int(data.get("snapshotWidth", 0)),
|
|
222
|
+
snapshot_height=_to_int(data.get("snapshotHeight", 0)),
|
|
223
|
+
snapshot_type=str(data.get("snapshotType", "") or ""),
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
@dataclass(frozen=True)
|
|
228
|
+
class FileElem:
|
|
229
|
+
file_path: str = ""
|
|
230
|
+
uuid: str = ""
|
|
231
|
+
source_url: str = ""
|
|
232
|
+
file_name: str = ""
|
|
233
|
+
file_size: int = 0
|
|
234
|
+
file_type: str = ""
|
|
235
|
+
|
|
236
|
+
@classmethod
|
|
237
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "FileElem":
|
|
238
|
+
return cls(
|
|
239
|
+
file_path=str(data.get("filePath", "") or ""),
|
|
240
|
+
uuid=str(data.get("uuid", "") or ""),
|
|
241
|
+
source_url=str(data.get("sourceUrl", "") or ""),
|
|
242
|
+
file_name=str(data.get("fileName", "") or ""),
|
|
243
|
+
file_size=_to_int(data.get("fileSize", 0)),
|
|
244
|
+
file_type=str(data.get("fileType", "") or ""),
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
@dataclass(frozen=True)
|
|
249
|
+
class MessageEntity:
|
|
250
|
+
type: str = ""
|
|
251
|
+
offset: int = 0
|
|
252
|
+
length: int = 0
|
|
253
|
+
url: str = ""
|
|
254
|
+
ex: str = ""
|
|
255
|
+
|
|
256
|
+
@classmethod
|
|
257
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "MessageEntity":
|
|
258
|
+
return cls(
|
|
259
|
+
type=str(data.get("type", "") or ""),
|
|
260
|
+
offset=_to_int(data.get("offset", 0)),
|
|
261
|
+
length=_to_int(data.get("length", 0)),
|
|
262
|
+
url=str(data.get("url", "") or ""),
|
|
263
|
+
ex=str(data.get("ex", "") or ""),
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
@dataclass(frozen=True)
|
|
268
|
+
class MergeElem:
|
|
269
|
+
title: str = ""
|
|
270
|
+
abstract_list: List[str] = field(default_factory=list)
|
|
271
|
+
multi_message: List[Dict[str, Any]] = field(default_factory=list)
|
|
272
|
+
message_entity_list: List[MessageEntity] = field(default_factory=list)
|
|
273
|
+
|
|
274
|
+
@classmethod
|
|
275
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "MergeElem":
|
|
276
|
+
abstract_list_raw = data.get("abstractList", [])
|
|
277
|
+
abstract_list = [str(v) for v in abstract_list_raw] if isinstance(abstract_list_raw, list) else []
|
|
278
|
+
multi_message_raw = data.get("multiMessage", [])
|
|
279
|
+
multi_message = [dict(v) for v in multi_message_raw if isinstance(v, Mapping)] if isinstance(multi_message_raw, list) else []
|
|
280
|
+
message_entity_raw = data.get("messageEntityList", [])
|
|
281
|
+
message_entity_list = (
|
|
282
|
+
[MessageEntity.from_dict(v) for v in message_entity_raw if isinstance(v, Mapping)]
|
|
283
|
+
if isinstance(message_entity_raw, list)
|
|
284
|
+
else []
|
|
285
|
+
)
|
|
286
|
+
return cls(
|
|
287
|
+
title=str(data.get("title", "") or ""),
|
|
288
|
+
abstract_list=abstract_list,
|
|
289
|
+
multi_message=multi_message,
|
|
290
|
+
message_entity_list=message_entity_list,
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
@dataclass(frozen=True)
|
|
295
|
+
class AtInfo:
|
|
296
|
+
at_user_id: str = ""
|
|
297
|
+
group_nickname: str = ""
|
|
298
|
+
|
|
299
|
+
@classmethod
|
|
300
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "AtInfo":
|
|
301
|
+
return cls(
|
|
302
|
+
at_user_id=str(data.get("atUserID", "") or ""),
|
|
303
|
+
group_nickname=str(data.get("groupNickname", "") or ""),
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
@dataclass(frozen=True)
|
|
308
|
+
class AtTextElem:
|
|
309
|
+
text: str = ""
|
|
310
|
+
at_user_list: List[str] = field(default_factory=list)
|
|
311
|
+
at_users_info: List[AtInfo] = field(default_factory=list)
|
|
312
|
+
quote_message: Dict[str, Any] = field(default_factory=dict)
|
|
313
|
+
is_at_self: bool = False
|
|
314
|
+
|
|
315
|
+
@classmethod
|
|
316
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "AtTextElem":
|
|
317
|
+
at_user_list_raw = data.get("atUserList", [])
|
|
318
|
+
at_users_info_raw = data.get("atUsersInfo", [])
|
|
319
|
+
quote_message_raw = data.get("quoteMessage", {})
|
|
320
|
+
return cls(
|
|
321
|
+
text=str(data.get("text", "") or ""),
|
|
322
|
+
at_user_list=[str(v) for v in at_user_list_raw] if isinstance(at_user_list_raw, list) else [],
|
|
323
|
+
at_users_info=[AtInfo.from_dict(v) for v in at_users_info_raw if isinstance(v, Mapping)]
|
|
324
|
+
if isinstance(at_users_info_raw, list)
|
|
325
|
+
else [],
|
|
326
|
+
quote_message=dict(quote_message_raw) if isinstance(quote_message_raw, Mapping) else {},
|
|
327
|
+
is_at_self=_to_bool(data.get("isAtSelf", False)),
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
@dataclass(frozen=True)
|
|
332
|
+
class FaceElem:
|
|
333
|
+
index: int = 0
|
|
334
|
+
data: str = ""
|
|
335
|
+
|
|
336
|
+
@classmethod
|
|
337
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "FaceElem":
|
|
338
|
+
return cls(
|
|
339
|
+
index=_to_int(data.get("index", 0)),
|
|
340
|
+
data=str(data.get("data", "") or ""),
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
@dataclass(frozen=True)
|
|
345
|
+
class LocationElem:
|
|
346
|
+
description: str = ""
|
|
347
|
+
longitude: float = 0.0
|
|
348
|
+
latitude: float = 0.0
|
|
349
|
+
|
|
350
|
+
@classmethod
|
|
351
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "LocationElem":
|
|
352
|
+
return cls(
|
|
353
|
+
description=str(data.get("description", "") or ""),
|
|
354
|
+
longitude=_to_float(data.get("longitude", 0)),
|
|
355
|
+
latitude=_to_float(data.get("latitude", 0)),
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
@dataclass(frozen=True)
|
|
360
|
+
class CustomElem:
|
|
361
|
+
data: Any = ""
|
|
362
|
+
description: str = ""
|
|
363
|
+
extension: str = ""
|
|
364
|
+
|
|
365
|
+
@classmethod
|
|
366
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "CustomElem":
|
|
367
|
+
payload = data.get("data", "")
|
|
368
|
+
if isinstance(payload, Mapping):
|
|
369
|
+
normalized_payload: Any = dict(payload)
|
|
370
|
+
elif isinstance(payload, list):
|
|
371
|
+
normalized_payload = list(payload)
|
|
372
|
+
else:
|
|
373
|
+
normalized_payload = str(payload or "") if payload is not None else ""
|
|
374
|
+
return cls(
|
|
375
|
+
data=normalized_payload,
|
|
376
|
+
description=str(data.get("description", "") or ""),
|
|
377
|
+
extension=str(data.get("extension", "") or ""),
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
@dataclass(frozen=True)
|
|
382
|
+
class QuoteElem:
|
|
383
|
+
text: str = ""
|
|
384
|
+
quote_message: Dict[str, Any] = field(default_factory=dict)
|
|
385
|
+
message_entity_list: List[MessageEntity] = field(default_factory=list)
|
|
386
|
+
|
|
387
|
+
@classmethod
|
|
388
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "QuoteElem":
|
|
389
|
+
quote_message_raw = data.get("quoteMessage", {})
|
|
390
|
+
message_entity_raw = data.get("messageEntityList", [])
|
|
391
|
+
return cls(
|
|
392
|
+
text=str(data.get("text", "") or ""),
|
|
393
|
+
quote_message=dict(quote_message_raw) if isinstance(quote_message_raw, Mapping) else {},
|
|
394
|
+
message_entity_list=[MessageEntity.from_dict(v) for v in message_entity_raw if isinstance(v, Mapping)]
|
|
395
|
+
if isinstance(message_entity_raw, list)
|
|
396
|
+
else [],
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
@dataclass(frozen=True)
|
|
401
|
+
class NotificationElem:
|
|
402
|
+
detail: str = ""
|
|
403
|
+
|
|
404
|
+
@classmethod
|
|
405
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "NotificationElem":
|
|
406
|
+
return cls(detail=str(data.get("detail", "") or ""))
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
@dataclass(frozen=True)
|
|
410
|
+
class AdvancedTextElem:
|
|
411
|
+
text: str = ""
|
|
412
|
+
message_entity_list: List[MessageEntity] = field(default_factory=list)
|
|
413
|
+
|
|
414
|
+
@classmethod
|
|
415
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "AdvancedTextElem":
|
|
416
|
+
message_entity_raw = data.get("messageEntityList", [])
|
|
417
|
+
return cls(
|
|
418
|
+
text=str(data.get("text", "") or ""),
|
|
419
|
+
message_entity_list=[MessageEntity.from_dict(v) for v in message_entity_raw if isinstance(v, Mapping)]
|
|
420
|
+
if isinstance(message_entity_raw, list)
|
|
421
|
+
else [],
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
@dataclass(frozen=True)
|
|
426
|
+
class TypingElem:
|
|
427
|
+
msg_tips: str = ""
|
|
428
|
+
|
|
429
|
+
@classmethod
|
|
430
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "TypingElem":
|
|
431
|
+
return cls(msg_tips=str(data.get("msgTips", "") or ""))
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
@dataclass(frozen=True)
|
|
435
|
+
class MarkdownTextElem:
|
|
436
|
+
content: str = ""
|
|
437
|
+
|
|
438
|
+
@classmethod
|
|
439
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "MarkdownTextElem":
|
|
440
|
+
return cls(content=str(data.get("content", "") or ""))
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
ParsedContent = Union[
|
|
444
|
+
TextElem,
|
|
445
|
+
PictureElem,
|
|
446
|
+
SoundElem,
|
|
447
|
+
VideoElem,
|
|
448
|
+
FileElem,
|
|
449
|
+
AtTextElem,
|
|
450
|
+
MergeElem,
|
|
451
|
+
CardElem,
|
|
452
|
+
LocationElem,
|
|
453
|
+
CustomElem,
|
|
454
|
+
TypingElem,
|
|
455
|
+
QuoteElem,
|
|
456
|
+
FaceElem,
|
|
457
|
+
AdvancedTextElem,
|
|
458
|
+
MarkdownTextElem,
|
|
459
|
+
NotificationElem,
|
|
460
|
+
]
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def _deserialize_content(content_type: int, payload: Any) -> Optional[ParsedContent]:
|
|
464
|
+
if not isinstance(payload, Mapping):
|
|
465
|
+
return None
|
|
466
|
+
if content_type == ContentType.TEXT:
|
|
467
|
+
return TextElem.from_dict(payload)
|
|
468
|
+
if content_type == ContentType.PICTURE:
|
|
469
|
+
return PictureElem.from_dict(payload)
|
|
470
|
+
if content_type == ContentType.SOUND:
|
|
471
|
+
return SoundElem.from_dict(payload)
|
|
472
|
+
if content_type == ContentType.VIDEO:
|
|
473
|
+
return VideoElem.from_dict(payload)
|
|
474
|
+
if content_type == ContentType.FILE:
|
|
475
|
+
return FileElem.from_dict(payload)
|
|
476
|
+
if content_type == ContentType.AT_TEXT:
|
|
477
|
+
return AtTextElem.from_dict(payload)
|
|
478
|
+
if content_type == ContentType.MERGER:
|
|
479
|
+
return MergeElem.from_dict(payload)
|
|
480
|
+
if content_type == ContentType.CARD:
|
|
481
|
+
return CardElem.from_dict(payload)
|
|
482
|
+
if content_type == ContentType.LOCATION:
|
|
483
|
+
return LocationElem.from_dict(payload)
|
|
484
|
+
if content_type in (
|
|
485
|
+
ContentType.CUSTOM,
|
|
486
|
+
ContentType.CUSTOM_MSG_NOT_TRIGGER_CONVERSATION,
|
|
487
|
+
ContentType.CUSTOM_MSG_ONLINE_ONLY,
|
|
488
|
+
):
|
|
489
|
+
return CustomElem.from_dict(payload)
|
|
490
|
+
if content_type == ContentType.TYPING:
|
|
491
|
+
return TypingElem.from_dict(payload)
|
|
492
|
+
if content_type == ContentType.QUOTE:
|
|
493
|
+
return QuoteElem.from_dict(payload)
|
|
494
|
+
if content_type == ContentType.FACE:
|
|
495
|
+
return FaceElem.from_dict(payload)
|
|
496
|
+
if content_type == ContentType.ADVANCED_TEXT:
|
|
497
|
+
return AdvancedTextElem.from_dict(payload)
|
|
498
|
+
if content_type == ContentType.MARKDOWN_TEXT:
|
|
499
|
+
return MarkdownTextElem.from_dict(payload)
|
|
500
|
+
return NotificationElem.from_dict(payload)
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
@dataclass(frozen=True)
|
|
504
|
+
class WSMessage:
|
|
505
|
+
conversation_id: str = ""
|
|
506
|
+
send_id: str = ""
|
|
507
|
+
recv_id: str = ""
|
|
508
|
+
group_id: str = ""
|
|
509
|
+
client_msg_id: str = ""
|
|
510
|
+
server_msg_id: str = ""
|
|
511
|
+
sender_platform_id: int = 0
|
|
512
|
+
sender_nickname: str = ""
|
|
513
|
+
sender_face_url: str = ""
|
|
514
|
+
session_type: int = 0
|
|
515
|
+
msg_from: int = 0
|
|
516
|
+
content_type: int = 0
|
|
517
|
+
content: str = ""
|
|
518
|
+
seq: int = 0
|
|
519
|
+
send_time: int = 0
|
|
520
|
+
create_time: int = 0
|
|
521
|
+
status: int = 0
|
|
522
|
+
is_read: bool = False
|
|
523
|
+
options: Dict[str, bool] = field(default_factory=dict)
|
|
524
|
+
offline_push_info: Dict[str, Any] = field(default_factory=dict)
|
|
525
|
+
at_user_id_list: List[str] = field(default_factory=list)
|
|
526
|
+
attached_info: str = ""
|
|
527
|
+
ex: str = ""
|
|
528
|
+
content_type_name: str = ""
|
|
529
|
+
content_json: Any = field(default=None, repr=False)
|
|
530
|
+
content_obj: Optional[ParsedContent] = None
|
|
531
|
+
raw: Dict[str, Any] = field(default_factory=dict, repr=False)
|
|
532
|
+
|
|
533
|
+
@classmethod
|
|
534
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "WSMessage":
|
|
535
|
+
options_raw = data.get("options", {})
|
|
536
|
+
options: Dict[str, bool] = {}
|
|
537
|
+
if isinstance(options_raw, Mapping):
|
|
538
|
+
options = {str(k): _to_bool(v) for k, v in options_raw.items()}
|
|
539
|
+
|
|
540
|
+
offline_push_info_raw = data.get("offlinePushInfo", {})
|
|
541
|
+
offline_push_info: Dict[str, Any] = {}
|
|
542
|
+
if isinstance(offline_push_info_raw, Mapping):
|
|
543
|
+
offline_push_info = dict(offline_push_info_raw)
|
|
544
|
+
|
|
545
|
+
at_user_id_list_raw = data.get("atUserIDList", [])
|
|
546
|
+
at_user_id_list: List[str] = []
|
|
547
|
+
if isinstance(at_user_id_list_raw, list):
|
|
548
|
+
at_user_id_list = [str(v) for v in at_user_id_list_raw]
|
|
549
|
+
|
|
550
|
+
content_text = str(data.get("content", "") or "")
|
|
551
|
+
content_type = _to_int(data.get("contentType", 0))
|
|
552
|
+
content_json = _parse_json(content_text)
|
|
553
|
+
content_obj = _deserialize_content(content_type, content_json)
|
|
554
|
+
|
|
555
|
+
return cls(
|
|
556
|
+
conversation_id=str(data.get("conversationID", "") or ""),
|
|
557
|
+
send_id=str(data.get("sendID", "") or ""),
|
|
558
|
+
recv_id=str(data.get("recvID", "") or ""),
|
|
559
|
+
group_id=str(data.get("groupID", "") or ""),
|
|
560
|
+
client_msg_id=str(data.get("clientMsgID", "") or ""),
|
|
561
|
+
server_msg_id=str(data.get("serverMsgID", "") or ""),
|
|
562
|
+
sender_platform_id=_to_int(data.get("senderPlatformID", 0)),
|
|
563
|
+
sender_nickname=str(data.get("senderNickname", "") or ""),
|
|
564
|
+
sender_face_url=str(data.get("senderFaceURL", "") or ""),
|
|
565
|
+
session_type=_to_int(data.get("sessionType", 0)),
|
|
566
|
+
msg_from=_to_int(data.get("msgFrom", 0)),
|
|
567
|
+
content_type=content_type,
|
|
568
|
+
content=content_text,
|
|
569
|
+
seq=_to_int(data.get("seq", 0)),
|
|
570
|
+
send_time=_to_int(data.get("sendTime", 0)),
|
|
571
|
+
create_time=_to_int(data.get("createTime", 0)),
|
|
572
|
+
status=_to_int(data.get("status", 0)),
|
|
573
|
+
is_read=_to_bool(data.get("isRead", False)),
|
|
574
|
+
options=options,
|
|
575
|
+
offline_push_info=offline_push_info,
|
|
576
|
+
at_user_id_list=at_user_id_list,
|
|
577
|
+
attached_info=str(data.get("attachedInfo", "") or ""),
|
|
578
|
+
ex=str(data.get("ex", "") or ""),
|
|
579
|
+
content_type_name=CONTENT_TYPE_NAMES.get(content_type, "notification"),
|
|
580
|
+
content_json=content_json,
|
|
581
|
+
content_obj=content_obj,
|
|
582
|
+
raw=dict(data),
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
def to_quote_message(self) -> Dict[str, Any]:
|
|
586
|
+
quote_message = {
|
|
587
|
+
"sendID": self.send_id,
|
|
588
|
+
"recvID": self.recv_id or self.group_id,
|
|
589
|
+
"groupID": self.group_id,
|
|
590
|
+
"clientMsgID": self.client_msg_id,
|
|
591
|
+
"serverMsgID": self.server_msg_id,
|
|
592
|
+
"senderPlatformID": self.sender_platform_id,
|
|
593
|
+
"senderNickname": self.sender_nickname,
|
|
594
|
+
"senderFaceUrl": self.sender_face_url,
|
|
595
|
+
"sessionType": self.session_type,
|
|
596
|
+
"msgFrom": self.msg_from,
|
|
597
|
+
"contentType": self.content_type,
|
|
598
|
+
"seq": self.seq,
|
|
599
|
+
"sendTime": self.send_time,
|
|
600
|
+
"createTime": self.create_time,
|
|
601
|
+
"status": self.status,
|
|
602
|
+
"ex": self.ex,
|
|
603
|
+
}
|
|
604
|
+
quote_message = {key: value for key, value in quote_message.items() if value not in ("", 0)}
|
|
605
|
+
quote_message["isRead"] = self.is_read
|
|
606
|
+
|
|
607
|
+
if self.offline_push_info:
|
|
608
|
+
quote_message["offlinePush"] = dict(self.offline_push_info)
|
|
609
|
+
|
|
610
|
+
attached_info_elem = _parse_json(self.attached_info)
|
|
611
|
+
if isinstance(attached_info_elem, Mapping) and attached_info_elem:
|
|
612
|
+
quote_message["attachedInfoElem"] = dict(attached_info_elem)
|
|
613
|
+
|
|
614
|
+
if isinstance(self.content_json, Mapping):
|
|
615
|
+
elem_name = _CONTENT_TYPE_ELEM_NAMES.get(self.content_type, "notificationElem")
|
|
616
|
+
quote_message[elem_name] = dict(self.content_json)
|
|
617
|
+
|
|
618
|
+
return quote_message
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
@dataclass(frozen=True)
|
|
622
|
+
class SelfUserInfo:
|
|
623
|
+
user_id: str = ""
|
|
624
|
+
nickname: str = ""
|
|
625
|
+
face_url: str = ""
|
|
626
|
+
create_time: int = 0
|
|
627
|
+
app_manger_level: int = 0
|
|
628
|
+
ex: str = ""
|
|
629
|
+
attached_info: str = ""
|
|
630
|
+
global_recv_msg_opt: int = 0
|
|
631
|
+
raw: Dict[str, Any] = field(default_factory=dict, repr=False)
|
|
632
|
+
|
|
633
|
+
@classmethod
|
|
634
|
+
def from_dict(cls, data: Mapping[str, Any]) -> "SelfUserInfo":
|
|
635
|
+
return cls(
|
|
636
|
+
user_id=str(data.get("userID", "") or ""),
|
|
637
|
+
nickname=str(data.get("nickname", "") or ""),
|
|
638
|
+
face_url=str(data.get("faceURL", "") or ""),
|
|
639
|
+
create_time=_to_int(data.get("createTime", 0)),
|
|
640
|
+
app_manger_level=_to_int(data.get("appMangerLevel", data.get("appManagerLevel", 0))),
|
|
641
|
+
ex=str(data.get("ex", "") or ""),
|
|
642
|
+
attached_info=str(data.get("attachedInfo", "") or ""),
|
|
643
|
+
global_recv_msg_opt=_to_int(data.get("globalRecvMsgOpt", 0)),
|
|
644
|
+
raw=dict(data),
|
|
645
|
+
)
|