satori-python-adapter-qq 0.3.2__tar.gz → 0.4.0rc1__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_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/.mina/adapter_qq.toml +1 -1
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/PKG-INFO +1 -1
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/pyproject.toml +1 -1
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/api.py +26 -5
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/events/group.py +7 -3
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/events/message.py +66 -2
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/message.py +16 -2
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/utils.py +3 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/LICENSE +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/README.md +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/__init__.py +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/audit_store.py +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/events/__init__.py +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/events/base.py +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/events/guild.py +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/events/interaction.py +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/exception.py +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/main.py +0 -0
- {satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/websocket.py +0 -0
{satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/api.py
RENAMED
|
@@ -29,7 +29,7 @@ from satori.server.route import (
|
|
|
29
29
|
)
|
|
30
30
|
|
|
31
31
|
from .message import QQGroupMessageEncoder, QQGuildMessageEncoder, decode_segments
|
|
32
|
-
from .utils import ROLE_MAPPING, QQBotNetwork, decode_channel, decode_guild, decode_member, decode_user
|
|
32
|
+
from .utils import ROLE_MAPPING, USER_AVATAR_URL, QQBotNetwork, decode_channel, decode_guild, decode_member, decode_user
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
def apply(
|
|
@@ -141,7 +141,14 @@ def apply(
|
|
|
141
141
|
)
|
|
142
142
|
return decode_user(res)
|
|
143
143
|
raise NotFoundException("qqguild platform does not support user.get without guild_id")
|
|
144
|
-
raise NotFoundException("qq platform does not support user.get")
|
|
144
|
+
# raise NotFoundException("qq platform does not support user.get")
|
|
145
|
+
app_id = net.bot_id_mapping[login_getter(request.self_id, request.platform == "qqguild").id]
|
|
146
|
+
return decode_user(
|
|
147
|
+
{
|
|
148
|
+
"id": request.params["user_id"],
|
|
149
|
+
"avatar": USER_AVATAR_URL.format(app_id=app_id, user_id=request.params["user_id"]),
|
|
150
|
+
}
|
|
151
|
+
)
|
|
145
152
|
|
|
146
153
|
@adapter.route(Api.GUILD_GET)
|
|
147
154
|
async def guild_get(request: Request[GuildGetParam]):
|
|
@@ -152,7 +159,8 @@ def apply(
|
|
|
152
159
|
f"guilds/{request.params['guild_id']}",
|
|
153
160
|
)
|
|
154
161
|
return decode_guild(res)
|
|
155
|
-
raise NotFoundException("qq platform does not support guild.get")
|
|
162
|
+
# raise NotFoundException("qq platform does not support guild.get")
|
|
163
|
+
return Guild(request.params["guild_id"]) # type: ignore
|
|
156
164
|
|
|
157
165
|
@adapter.route(Api.GUILD_LIST)
|
|
158
166
|
async def guild_list(request: Request[GuildListParam]):
|
|
@@ -177,7 +185,9 @@ def apply(
|
|
|
177
185
|
f"channels/{channel_id}",
|
|
178
186
|
)
|
|
179
187
|
return decode_channel(res)
|
|
180
|
-
raise NotFoundException("qq platform does not support channel.get")
|
|
188
|
+
# raise NotFoundException("qq platform does not support channel.get")
|
|
189
|
+
is_private = request.params["channel_id"].startswith("private:")
|
|
190
|
+
return Channel(request.params["channel_id"], ChannelType.DIRECT if is_private else ChannelType.TEXT) # type: ignore
|
|
181
191
|
|
|
182
192
|
@adapter.route(Api.CHANNEL_LIST)
|
|
183
193
|
async def channel_list(request: Request[ChannelListParam]):
|
|
@@ -253,7 +263,18 @@ def apply(
|
|
|
253
263
|
f"guilds/{guild_id}/members/{request.params['user_id']}",
|
|
254
264
|
)
|
|
255
265
|
return decode_member(res)
|
|
256
|
-
raise NotFoundException("qq platform does not support guild.member.get")
|
|
266
|
+
# raise NotFoundException("qq platform does not support guild.member.get")
|
|
267
|
+
app_id = net.bot_id_mapping[login_getter(request.self_id, request.platform == "qqguild").id]
|
|
268
|
+
return Member(
|
|
269
|
+
decode_user(
|
|
270
|
+
{
|
|
271
|
+
"id": request.params["user_id"],
|
|
272
|
+
"avatar": USER_AVATAR_URL.format(app_id=app_id, user_id=request.params["user_id"]),
|
|
273
|
+
}
|
|
274
|
+
),
|
|
275
|
+
joined_at=None,
|
|
276
|
+
roles=[ROLE_MAPPING["1"]],
|
|
277
|
+
)
|
|
257
278
|
|
|
258
279
|
@adapter.route(Api.GUILD_MEMBER_LIST)
|
|
259
280
|
async def guild_list_member(request: Request[GuildXXXListParam]):
|
|
@@ -5,7 +5,7 @@ from datetime import datetime
|
|
|
5
5
|
from satori import EventType
|
|
6
6
|
from satori.model import Channel, ChannelType, Event, Guild, User
|
|
7
7
|
|
|
8
|
-
from ..utils import Payload
|
|
8
|
+
from ..utils import USER_AVATAR_URL, Payload
|
|
9
9
|
from .base import register_event
|
|
10
10
|
|
|
11
11
|
|
|
@@ -17,7 +17,8 @@ async def friend_event(login, guild_login, net, payload: Payload):
|
|
|
17
17
|
"FRIEND_ADD": EventType.FRIEND_ADDED,
|
|
18
18
|
"FRIEND_DEL": EventType.FRIEND_REMOVED,
|
|
19
19
|
}[payload.type or ""]
|
|
20
|
-
|
|
20
|
+
app_id = net.bot_id_mapping[login.id]
|
|
21
|
+
user = User(raw["openid"], avatar=USER_AVATAR_URL.format(app_id=app_id, user_id=raw["openid"]))
|
|
21
22
|
return Event(
|
|
22
23
|
t,
|
|
23
24
|
(
|
|
@@ -40,7 +41,10 @@ async def group_event(login, guild_login, net, payload: Payload):
|
|
|
40
41
|
guild = Guild(raw["group_openid"])
|
|
41
42
|
else:
|
|
42
43
|
guild = Guild(raw["guild_id"])
|
|
43
|
-
|
|
44
|
+
app_id = net.bot_id_mapping[login.id]
|
|
45
|
+
operator = User(
|
|
46
|
+
raw["op_member_openid"], avatar=USER_AVATAR_URL.format(app_id=app_id, user_id=raw["op_member_openid"])
|
|
47
|
+
)
|
|
44
48
|
t = {
|
|
45
49
|
"GROUP_ADD_ROBOT": EventType.GUILD_ADDED,
|
|
46
50
|
"GROUP_DEL_ROBOT": EventType.GUILD_REMOVED,
|
|
@@ -82,6 +82,62 @@ async def direct_message_create(login, guild_login, net, payload: Payload):
|
|
|
82
82
|
)
|
|
83
83
|
|
|
84
84
|
|
|
85
|
+
@register_event("GROUP_MESSAGE_CREATE")
|
|
86
|
+
async def group_message_create(login, guild_login, net, payload: Payload):
|
|
87
|
+
raw = payload.data
|
|
88
|
+
if "group_openid" in raw:
|
|
89
|
+
channel = Channel(raw["group_openid"], ChannelType.TEXT)
|
|
90
|
+
else:
|
|
91
|
+
channel = Channel(raw["group_id"], ChannelType.TEXT)
|
|
92
|
+
app_id = net.bot_id_mapping[login.id]
|
|
93
|
+
name = raw["author"].get("username")
|
|
94
|
+
if "member_openid" in raw["author"]:
|
|
95
|
+
user = User(
|
|
96
|
+
raw["author"]["member_openid"],
|
|
97
|
+
name=name,
|
|
98
|
+
avatar=USER_AVATAR_URL.format(app_id=app_id, user_id=raw["author"]["member_openid"]),
|
|
99
|
+
is_bot=raw["author"].get("bot", False),
|
|
100
|
+
)
|
|
101
|
+
else:
|
|
102
|
+
user = User(
|
|
103
|
+
raw["author"]["id"],
|
|
104
|
+
name=name,
|
|
105
|
+
avatar=USER_AVATAR_URL.format(app_id=app_id, user_id=raw["author"]["id"]),
|
|
106
|
+
is_bot=raw["author"].get("bot", False),
|
|
107
|
+
)
|
|
108
|
+
member = Member(user, avatar=user.avatar)
|
|
109
|
+
msg = decode_segments(raw)
|
|
110
|
+
if msg and isinstance(elem := msg[0], At) and elem.id == "all" and isinstance(msg[1], Text):
|
|
111
|
+
text = msg[1].text.lstrip()
|
|
112
|
+
if not text:
|
|
113
|
+
msg.pop(1)
|
|
114
|
+
else:
|
|
115
|
+
msg[1] = Text(text)
|
|
116
|
+
for mention in reversed(raw["mentions"]):
|
|
117
|
+
if mention["scope"] == "all":
|
|
118
|
+
continue
|
|
119
|
+
msg.insert(0, At(mention["id"], name=mention.get("username")))
|
|
120
|
+
return Event(
|
|
121
|
+
EventType.MESSAGE_CREATED,
|
|
122
|
+
(
|
|
123
|
+
datetime.fromtimestamp(int(raw["timestamp"]))
|
|
124
|
+
if isinstance(raw["timestamp"], (int, float)) or raw["timestamp"].isdigit()
|
|
125
|
+
else datetime.fromisoformat(str(raw["timestamp"]))
|
|
126
|
+
),
|
|
127
|
+
login,
|
|
128
|
+
channel=channel,
|
|
129
|
+
guild=Guild(channel.id),
|
|
130
|
+
member=member,
|
|
131
|
+
user=user,
|
|
132
|
+
message=MessageObject.from_elements(raw["id"], msg),
|
|
133
|
+
referrer={
|
|
134
|
+
"msg_id": raw["id"],
|
|
135
|
+
"msg_seq": -1,
|
|
136
|
+
"msg_scene": raw["message_scene"],
|
|
137
|
+
},
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
85
141
|
@register_event("GROUP_AT_MESSAGE_CREATE")
|
|
86
142
|
async def group_at_message_create(login, guild_login, net, payload: Payload):
|
|
87
143
|
raw = payload.data
|
|
@@ -96,10 +152,14 @@ async def group_at_message_create(login, guild_login, net, payload: Payload):
|
|
|
96
152
|
raw["author"]["member_openid"],
|
|
97
153
|
name=name,
|
|
98
154
|
avatar=USER_AVATAR_URL.format(app_id=app_id, user_id=raw["author"]["member_openid"]),
|
|
155
|
+
is_bot=raw["author"].get("bot", False),
|
|
99
156
|
)
|
|
100
157
|
else:
|
|
101
158
|
user = User(
|
|
102
|
-
raw["author"]["id"],
|
|
159
|
+
raw["author"]["id"],
|
|
160
|
+
name=name,
|
|
161
|
+
avatar=USER_AVATAR_URL.format(app_id=app_id, user_id=raw["author"]["id"]),
|
|
162
|
+
is_bot=raw["author"].get("bot", False),
|
|
103
163
|
)
|
|
104
164
|
member = Member(user, avatar=user.avatar)
|
|
105
165
|
msg = decode_segments(raw)
|
|
@@ -141,10 +201,14 @@ async def c2c_message_create(login, guild_login, net, payload: Payload):
|
|
|
141
201
|
raw["author"]["user_openid"],
|
|
142
202
|
name,
|
|
143
203
|
avatar=USER_AVATAR_URL.format(app_id=app_id, user_id=raw["author"]["user_openid"]),
|
|
204
|
+
is_bot=raw["author"].get("bot"),
|
|
144
205
|
)
|
|
145
206
|
else:
|
|
146
207
|
user = User(
|
|
147
|
-
raw["author"]["id"],
|
|
208
|
+
raw["author"]["id"],
|
|
209
|
+
name,
|
|
210
|
+
avatar=USER_AVATAR_URL.format(app_id=app_id, user_id=raw["author"]["id"]),
|
|
211
|
+
is_bot=raw["author"].get("bot"),
|
|
148
212
|
)
|
|
149
213
|
channel = Channel(f"private:{user.id}", ChannelType.DIRECT)
|
|
150
214
|
return Event(
|
|
@@ -21,6 +21,17 @@ from .utils import QQBotNetwork, parse_file_uri
|
|
|
21
21
|
|
|
22
22
|
_BASE64_RE = re.compile(r"^data:([\w/.+-]+);base64,")
|
|
23
23
|
MAX_FILESIZE_ONCE = 10 * 1024 * 1024 # 10MB
|
|
24
|
+
BUTTON_STYLES = {
|
|
25
|
+
"grey": 0,
|
|
26
|
+
"secondary": 0,
|
|
27
|
+
"blue": 1,
|
|
28
|
+
"primary": 1,
|
|
29
|
+
"success": 1,
|
|
30
|
+
"info": 2,
|
|
31
|
+
"warning": 3,
|
|
32
|
+
"danger": 3,
|
|
33
|
+
"link": 4,
|
|
34
|
+
}
|
|
24
35
|
|
|
25
36
|
|
|
26
37
|
def escape(s: str) -> str:
|
|
@@ -530,7 +541,7 @@ class QQGroupMessageEncoder(QQBotMessageEncoder):
|
|
|
530
541
|
"render_data": {
|
|
531
542
|
"label": label,
|
|
532
543
|
"visited_label": label,
|
|
533
|
-
"style":
|
|
544
|
+
"style": BUTTON_STYLES.get(attrs.get("class", "grey"), 1),
|
|
534
545
|
},
|
|
535
546
|
"action": {
|
|
536
547
|
"type": {"input": 2, "link": 0}.get(attrs.get("type", "action"), 1),
|
|
@@ -586,7 +597,10 @@ def decode_segments(event: dict) -> list[Element]:
|
|
|
586
597
|
if seg_type == "text":
|
|
587
598
|
result.append(E.text(i["text"]))
|
|
588
599
|
elif seg_type == "mention_user":
|
|
589
|
-
|
|
600
|
+
if i["user_id"] == "all":
|
|
601
|
+
result.append(E.at_all())
|
|
602
|
+
else:
|
|
603
|
+
result.append(E.at(i["user_id"]))
|
|
590
604
|
elif seg_type == "mention_channel":
|
|
591
605
|
result.append(E.sharp(i["channel_id"]))
|
|
592
606
|
elif seg_type == "emoji":
|
{satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/utils.py
RENAMED
|
@@ -18,6 +18,9 @@ CallMethod = Literal["get", "post", "fetch", "update", "multipart", "put", "dele
|
|
|
18
18
|
class QQBotNetwork(Protocol):
|
|
19
19
|
session: ClientSession
|
|
20
20
|
|
|
21
|
+
@property
|
|
22
|
+
def bot_id_mapping(self) -> dict[str, str]: ...
|
|
23
|
+
|
|
21
24
|
async def call_api(self, method: CallMethod, action: str, params: dict | None = None) -> dict: ...
|
|
22
25
|
|
|
23
26
|
|
|
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
|
{satori_python_adapter_qq-0.3.2 → satori_python_adapter_qq-0.4.0rc1}/src/satori/adapters/qq/main.py
RENAMED
|
File without changes
|
|
File without changes
|