satori-python-adapter-milky 0.5.0__tar.gz → 0.5.2__tar.gz
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.
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/.mina/adapter_milky.toml +1 -1
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/PKG-INFO +2 -1
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/README.md +1 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/pyproject.toml +1 -1
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/base.py +9 -1
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/events/group.py +19 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/message.py +34 -8
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/utils.py +2 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/LICENSE +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/__init__.py +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/api.py +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/events/__init__.py +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/events/base.py +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/events/message.py +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/events/request.py +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/main.py +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/sse.py +0 -0
- {satori_python_adapter_milky-0.5.0 → satori_python_adapter_milky-0.5.2}/src/satori/adapters/milky/webhook.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: satori-python-adapter-milky
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: Satori Protocol SDK for python, adapter for Milky
|
|
5
5
|
Home-page: https://github.com/RF-Tar-Railt/satori-python
|
|
6
6
|
Author-Email: RF-Tar-Railt <rf_tar_railt@qq.com>
|
|
@@ -77,6 +77,7 @@ pip install satori-python-server
|
|
|
77
77
|
| Console | `pip install satori-python-adapter-console` | satori.adapters.console |
|
|
78
78
|
| Milky | `pip install satori-python-adapter-milky` | satori.adapters.milky.main, satori.adapters.milky.webhook, satori.adapters.milky.sse |
|
|
79
79
|
| QQ | `pip install satori-python-adapter-qq` | satori.adapters.qq.main, satori.adapters.qq.websocket |
|
|
80
|
+
| WxClaw | `pip install satori-python-adapter-wxclaw` | satori.adapters.wxclaw |
|
|
80
81
|
|
|
81
82
|
### 社区适配器
|
|
82
83
|
|
|
@@ -55,6 +55,7 @@ pip install satori-python-server
|
|
|
55
55
|
| Console | `pip install satori-python-adapter-console` | satori.adapters.console |
|
|
56
56
|
| Milky | `pip install satori-python-adapter-milky` | satori.adapters.milky.main, satori.adapters.milky.webhook, satori.adapters.milky.sse |
|
|
57
57
|
| QQ | `pip install satori-python-adapter-qq` | satori.adapters.qq.main, satori.adapters.qq.websocket |
|
|
58
|
+
| WxClaw | `pip install satori-python-adapter-wxclaw` | satori.adapters.wxclaw |
|
|
58
59
|
|
|
59
60
|
### 社区适配器
|
|
60
61
|
|
|
@@ -35,6 +35,8 @@ class MilkyBaseConfig:
|
|
|
35
35
|
"""是否将 token 放在查询参数中, 默认为 False"""
|
|
36
36
|
headers: dict[str, str] = field(default_factory=dict)
|
|
37
37
|
"""连接时使用的自定义请求头, 默认为空字典"""
|
|
38
|
+
fetch_forward_message: bool = False
|
|
39
|
+
"""是否在事件中获取转发消息, 默认为 False"""
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
TMilkyBaseConfig = TypeVar("TMilkyBaseConfig", bound=MilkyBaseConfig, default=MilkyBaseConfig)
|
|
@@ -58,6 +60,7 @@ class MilkyBaseAdapter(BaseAdapter[TMilkyBaseConfig], ABC):
|
|
|
58
60
|
self.headers = config.headers.copy()
|
|
59
61
|
self.session = None
|
|
60
62
|
self.logins: dict[str, Login] = {}
|
|
63
|
+
self.fetch_forward_message = config.fetch_forward_message
|
|
61
64
|
self.features: list[str] = list(DEFAULT_FEATURES)
|
|
62
65
|
apply(self, lambda _: self, self._get_login)
|
|
63
66
|
|
|
@@ -152,7 +155,12 @@ class MilkyBaseAdapter(BaseAdapter[TMilkyBaseConfig], ABC):
|
|
|
152
155
|
return
|
|
153
156
|
user = decode_login_user(data)
|
|
154
157
|
login = Login(
|
|
155
|
-
sn=0,
|
|
158
|
+
sn=0,
|
|
159
|
+
status=LoginStatus.ONLINE,
|
|
160
|
+
adapter="milky",
|
|
161
|
+
platform="qq-client",
|
|
162
|
+
user=user,
|
|
163
|
+
features=self.features.copy(),
|
|
156
164
|
)
|
|
157
165
|
self_id = login.id
|
|
158
166
|
previous = self.logins.get(self_id)
|
|
@@ -75,6 +75,25 @@ async def group_member_decrease(login, net, raw):
|
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
@register_event("group_disband")
|
|
79
|
+
async def group_disband(login, net, raw):
|
|
80
|
+
data = raw["data"]
|
|
81
|
+
guild_id = str(data["group_id"])
|
|
82
|
+
guild = Guild(guild_id, avatar=group_avatar(guild_id))
|
|
83
|
+
channel = Channel(guild_id, ChannelType.TEXT)
|
|
84
|
+
operator = None
|
|
85
|
+
if data.get("operator_id"):
|
|
86
|
+
operator = User(str(data["operator_id"]), avatar=user_avatar(data["operator_id"]))
|
|
87
|
+
return Event(
|
|
88
|
+
EventType.GUILD_REMOVED,
|
|
89
|
+
datetime.now(),
|
|
90
|
+
login,
|
|
91
|
+
guild=guild,
|
|
92
|
+
channel=channel,
|
|
93
|
+
operator=operator,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
78
97
|
@register_event("group_name_change")
|
|
79
98
|
async def group_name_change(login, net, raw):
|
|
80
99
|
data = raw["data"]
|
|
@@ -139,10 +139,17 @@ class MilkyMessageEncoder:
|
|
|
139
139
|
return
|
|
140
140
|
if match := _BASE64_RE.match(uri):
|
|
141
141
|
uri = f"base64://{uri[len(match.group(0)) :]}"
|
|
142
|
+
sub_type = "normal"
|
|
143
|
+
if "sub_type" in attrs:
|
|
144
|
+
sub_type = attrs["sub_type"]
|
|
145
|
+
if "subType" in attrs:
|
|
146
|
+
sub_type = attrs["subType"]
|
|
147
|
+
if "milky:type" in attrs:
|
|
148
|
+
sub_type = attrs["milky:type"]
|
|
142
149
|
self.segments.append(
|
|
143
150
|
{
|
|
144
151
|
"type": "image",
|
|
145
|
-
"data": {"uri": uri, "sub_type":
|
|
152
|
+
"data": {"uri": uri, "sub_type": sub_type},
|
|
146
153
|
}
|
|
147
154
|
)
|
|
148
155
|
case "audio":
|
|
@@ -177,6 +184,9 @@ class MilkyMessageEncoder:
|
|
|
177
184
|
self.segments.append(
|
|
178
185
|
{"type": "light_app", "data": {"json_payload": attrs.get("json_payload", attrs["jsonPayload"])}}
|
|
179
186
|
)
|
|
187
|
+
case "markdown" | "milky:markdown":
|
|
188
|
+
await self.flush()
|
|
189
|
+
self.segments.append({"type": "markdown", "data": {"content": str(children[0])}})
|
|
180
190
|
case "author":
|
|
181
191
|
self.stack[0].author.update(attrs)
|
|
182
192
|
case "quote":
|
|
@@ -255,6 +265,7 @@ class MilkyMessageEncoder:
|
|
|
255
265
|
"user_id": origin["message"]["sender_id"],
|
|
256
266
|
"sender_name": nickname,
|
|
257
267
|
"segments": await self.sendable(segments),
|
|
268
|
+
"time": origin["message"]["time"],
|
|
258
269
|
}
|
|
259
270
|
)
|
|
260
271
|
else:
|
|
@@ -263,6 +274,7 @@ class MilkyMessageEncoder:
|
|
|
263
274
|
"user_id": int(author.get("id", self.login.id)),
|
|
264
275
|
"sender_name": author.get("name", self.login.user.name or self.login.id),
|
|
265
276
|
"segments": self.segments,
|
|
277
|
+
"time": int(author.get("time", datetime.now().timestamp())),
|
|
266
278
|
}
|
|
267
279
|
)
|
|
268
280
|
self.segments = []
|
|
@@ -380,13 +392,13 @@ async def _decode_segments(net: MilkyNetwork, payload: dict, segments: Sequence[
|
|
|
380
392
|
case "face":
|
|
381
393
|
result.append(E.emoji(str(data.get("face_id"))))
|
|
382
394
|
case "image":
|
|
383
|
-
result.append(E.image(_resource_url(data)))
|
|
395
|
+
result.append(E.image(await _resource_url(net, data)))
|
|
384
396
|
case "record":
|
|
385
|
-
result.append(E.audio(_resource_url(data)))
|
|
397
|
+
result.append(E.audio(await _resource_url(net, data)))
|
|
386
398
|
case "video":
|
|
387
|
-
result.append(E.video(_resource_url(data)))
|
|
399
|
+
result.append(E.video(await _resource_url(net, data)))
|
|
388
400
|
case "file":
|
|
389
|
-
result.append(E.file(_resource_url(data)))
|
|
401
|
+
result.append(E.file(await _resource_url(net, data)))
|
|
390
402
|
case "reply":
|
|
391
403
|
seq = data.get("message_seq")
|
|
392
404
|
if seq is not None:
|
|
@@ -396,6 +408,9 @@ async def _decode_segments(net: MilkyNetwork, payload: dict, segments: Sequence[
|
|
|
396
408
|
case "forward":
|
|
397
409
|
forward_id = data.get("forward_id")
|
|
398
410
|
if forward_id is not None:
|
|
411
|
+
if not net.fetch_forward_message:
|
|
412
|
+
result.append(E.message(forward_id, content=[], forward=True))
|
|
413
|
+
continue
|
|
399
414
|
try:
|
|
400
415
|
messages = (await net.call_api("get_forwarded_messages", {"forward_id": forward_id}))[
|
|
401
416
|
"messages"
|
|
@@ -441,7 +456,10 @@ async def _decode_segments(net: MilkyNetwork, payload: dict, segments: Sequence[
|
|
|
441
456
|
forward_elements.append(E.message(str(msg.get("message_seq")), content=content))
|
|
442
457
|
result.append(E.message(forward_id, content=forward_elements, forward=True))
|
|
443
458
|
case _:
|
|
444
|
-
|
|
459
|
+
elem = Custom(f"milky:{seg_type}", data)
|
|
460
|
+
if seg_type == "market_face" and "url" in data:
|
|
461
|
+
elem.children.append(E.image(data["url"]))
|
|
462
|
+
result.append(elem)
|
|
445
463
|
return result
|
|
446
464
|
|
|
447
465
|
|
|
@@ -476,5 +494,13 @@ async def _decode_reply(net: MilkyNetwork, payload: dict, data: dict, message_se
|
|
|
476
494
|
return E.quote(str(message_seq), content=content)
|
|
477
495
|
|
|
478
496
|
|
|
479
|
-
def _resource_url(data: dict) -> str:
|
|
480
|
-
|
|
497
|
+
async def _resource_url(net: MilkyNetwork, data: dict) -> str:
|
|
498
|
+
if "uri" in data:
|
|
499
|
+
return data["uri"]
|
|
500
|
+
if "url" in data:
|
|
501
|
+
return data["url"]
|
|
502
|
+
if "temp_url" in data:
|
|
503
|
+
return data["temp_url"]
|
|
504
|
+
if "resource_id" in data:
|
|
505
|
+
return (await net.call_api("get_resource_temp_url", {"resource_id": data["resource_id"]}))["url"]
|
|
506
|
+
return ""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|