satori-python-adapter-milky 0.3.2__tar.gz → 0.4.1__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.3.2 → satori_python_adapter_milky-0.4.1}/.mina/adapter_milky.toml +1 -1
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/PKG-INFO +1 -1
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/pyproject.toml +1 -1
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/events/group.py +22 -2
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/message.py +51 -3
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/LICENSE +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/README.md +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/__init__.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/api.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/base.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/events/__init__.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/events/base.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/events/message.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/events/request.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/main.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/sse.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/utils.py +0 -0
- {satori_python_adapter_milky-0.3.2 → satori_python_adapter_milky-0.4.1}/src/satori/adapters/milky/webhook.py +0 -0
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
|
|
5
5
|
from satori import EventType
|
|
6
|
-
from satori.model import Channel, ChannelType, Event, Guild, Member, User
|
|
6
|
+
from satori.model import Channel, ChannelType, Event, Guild, Member, Role, User
|
|
7
7
|
|
|
8
8
|
from ..utils import group_avatar, user_avatar
|
|
9
9
|
from .base import register_event
|
|
@@ -15,8 +15,18 @@ async def group_member_increase(login, net, raw):
|
|
|
15
15
|
guild_id = str(data["group_id"])
|
|
16
16
|
guild = Guild(guild_id, avatar=group_avatar(guild_id))
|
|
17
17
|
channel = Channel(guild_id, ChannelType.TEXT)
|
|
18
|
+
if data["user_id"] == raw["self_id"]:
|
|
19
|
+
return Event(
|
|
20
|
+
EventType.GUILD_ADDED,
|
|
21
|
+
datetime.now(),
|
|
22
|
+
login=login,
|
|
23
|
+
user=login.user,
|
|
24
|
+
member=Member(login.user, avatar=user_avatar(data["user_id"]), roles=[Role("member", "群成员")]),
|
|
25
|
+
guild=guild,
|
|
26
|
+
channel=channel,
|
|
27
|
+
)
|
|
18
28
|
user = User(str(data["user_id"]), avatar=user_avatar(data["user_id"]))
|
|
19
|
-
member = Member(user, avatar=user.avatar)
|
|
29
|
+
member = Member(user, avatar=user.avatar, roles=[Role("member", "群成员")])
|
|
20
30
|
operator = None
|
|
21
31
|
if data.get("operator_id"):
|
|
22
32
|
operator = User(str(data["operator_id"]), avatar=user_avatar(data["operator_id"]))
|
|
@@ -38,6 +48,16 @@ async def group_member_decrease(login, net, raw):
|
|
|
38
48
|
guild_id = str(data["group_id"])
|
|
39
49
|
guild = Guild(guild_id, avatar=group_avatar(guild_id))
|
|
40
50
|
channel = Channel(guild_id, ChannelType.TEXT)
|
|
51
|
+
if data["user_id"] == raw["self_id"]:
|
|
52
|
+
return Event(
|
|
53
|
+
EventType.GUILD_REMOVED,
|
|
54
|
+
datetime.now(),
|
|
55
|
+
login=login,
|
|
56
|
+
user=login.user,
|
|
57
|
+
member=Member(login.user, avatar=user_avatar(data["user_id"]), roles=[Role("member", "群成员")]),
|
|
58
|
+
guild=guild,
|
|
59
|
+
channel=channel,
|
|
60
|
+
)
|
|
41
61
|
user = User(str(data["user_id"]), avatar=user_avatar(data["user_id"]))
|
|
42
62
|
member = Member(user, avatar=user.avatar)
|
|
43
63
|
operator = None
|
|
@@ -167,6 +167,9 @@ class MilkyMessageEncoder:
|
|
|
167
167
|
case "file":
|
|
168
168
|
await self.flush()
|
|
169
169
|
await self._send_file(attrs)
|
|
170
|
+
case "milky:light_app":
|
|
171
|
+
await self.flush()
|
|
172
|
+
self.segments.append({"type": "light_app", "data": {"json_payload": attrs["json_payload"]}})
|
|
170
173
|
case "author":
|
|
171
174
|
self.stack[0].author.update(attrs)
|
|
172
175
|
case "quote":
|
|
@@ -364,7 +367,7 @@ async def _decode_segments(net: MilkyNetwork, payload: dict, segments: Sequence[
|
|
|
364
367
|
case "text":
|
|
365
368
|
result.append(E.text(data.get("text", "")))
|
|
366
369
|
case "mention":
|
|
367
|
-
result.append(E.at(str(data.get("user_id"))))
|
|
370
|
+
result.append(E.at(str(data.get("user_id")), name=data.get("name")))
|
|
368
371
|
case "mention_all":
|
|
369
372
|
result.append(E.at_all())
|
|
370
373
|
case "face":
|
|
@@ -380,15 +383,60 @@ async def _decode_segments(net: MilkyNetwork, payload: dict, segments: Sequence[
|
|
|
380
383
|
case "reply":
|
|
381
384
|
seq = data.get("message_seq")
|
|
382
385
|
if seq is not None:
|
|
383
|
-
quote = await _decode_reply(net, payload, int(seq))
|
|
386
|
+
quote = await _decode_reply(net, payload, data, int(seq))
|
|
384
387
|
if quote:
|
|
385
388
|
result.append(quote)
|
|
389
|
+
case "forward":
|
|
390
|
+
forward_id = data.get("forward_id")
|
|
391
|
+
if forward_id is not None:
|
|
392
|
+
messages = (await net.call_api("get_forwarded_messages", {"forward_id": forward_id}))["messages"]
|
|
393
|
+
forward_elements = []
|
|
394
|
+
for msg in messages:
|
|
395
|
+
sender_name = msg.get("sender_name")
|
|
396
|
+
avatar = msg.get("avatar_url")
|
|
397
|
+
response = {}
|
|
398
|
+
if "message_seq" in msg:
|
|
399
|
+
try:
|
|
400
|
+
response = await net.call_api(
|
|
401
|
+
"get_message",
|
|
402
|
+
{
|
|
403
|
+
"message_scene": payload["message_scene"],
|
|
404
|
+
"peer_id": payload["peer_id"],
|
|
405
|
+
"message_seq": msg["message_seq"],
|
|
406
|
+
},
|
|
407
|
+
)
|
|
408
|
+
except Exception:
|
|
409
|
+
pass
|
|
410
|
+
if response:
|
|
411
|
+
origin = await decode_message(net, response["message"])
|
|
412
|
+
content = []
|
|
413
|
+
if origin.user:
|
|
414
|
+
content.append(
|
|
415
|
+
E.author(
|
|
416
|
+
origin.user.id, origin.user.name or sender_name, origin.user.avatar or avatar
|
|
417
|
+
)
|
|
418
|
+
)
|
|
419
|
+
content.extend(origin.message)
|
|
420
|
+
|
|
421
|
+
else:
|
|
422
|
+
content = await _decode_segments(net, payload, msg.get("segments", []))
|
|
423
|
+
content.insert(0, E.author(str(msg.get("sender_id")), sender_name, avatar))
|
|
424
|
+
forward_elements.append(E.message(str(msg.get("message_seq")), content=content))
|
|
425
|
+
result.append(E.message(forward_id, content=forward_elements, forward=True))
|
|
386
426
|
case _:
|
|
387
427
|
result.append(Custom(f"milky:{seg_type}", data))
|
|
388
428
|
return result
|
|
389
429
|
|
|
390
430
|
|
|
391
|
-
async def _decode_reply(net: MilkyNetwork, payload: dict, message_seq: int) -> Element | None:
|
|
431
|
+
async def _decode_reply(net: MilkyNetwork, payload: dict, data: dict, message_seq: int) -> Element | None:
|
|
432
|
+
if all(k in data for k in ("sender_id", "time", "segments")):
|
|
433
|
+
user = User(str(data["sender_id"]), data.get("sender_name"), avatar=user_avatar(data["sender_id"]))
|
|
434
|
+
elements = await _decode_segments(net, payload, data["segments"])
|
|
435
|
+
content = []
|
|
436
|
+
if user:
|
|
437
|
+
content.append(E.author(user.id, user.name, user.avatar))
|
|
438
|
+
content.extend(elements)
|
|
439
|
+
return E.quote(str(message_seq), content=content)
|
|
392
440
|
try:
|
|
393
441
|
response = await net.call_api(
|
|
394
442
|
"get_message",
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|