entari-plugin-server 0.6.2__tar.gz → 0.7.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.
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/PKG-INFO +2 -2
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/pyproject.toml +8 -5
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/__init__.py +47 -35
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/patch.py +1 -1
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/LICENSE +0 -0
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/README.md +0 -0
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/README.md +0 -0
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/_adapter.py +0 -0
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/config.py +0 -0
- {entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/tests/__init__.py +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: entari-plugin-server
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Summary: Entari plugin for running Satori Server
|
|
5
5
|
Author-Email: RF-Tar-Railt <rf_tar_railt@qq.com>
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: homepage, https://github.com/ArcletProject/entari-plugin-server
|
|
8
8
|
Project-URL: repository, https://github.com/ArcletProject/entari-plugin-server
|
|
9
9
|
Requires-Python: >=3.10
|
|
10
|
-
Requires-Dist: arclet-entari<0.
|
|
10
|
+
Requires-Dist: arclet-entari<0.19.0,>=0.18.0rc4
|
|
11
11
|
Requires-Dist: satori-python-server<1.4.0,>=1.3.0
|
|
12
12
|
Provides-Extra: fastapi
|
|
13
13
|
Requires-Dist: fastapi>=0.116.1; extra == "fastapi"
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "entari-plugin-server"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.1"
|
|
4
4
|
description = "Entari plugin for running Satori Server"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "RF-Tar-Railt", email = "rf_tar_railt@qq.com" },
|
|
7
7
|
]
|
|
8
8
|
dependencies = [
|
|
9
|
-
"arclet-entari<0.
|
|
9
|
+
"arclet-entari<0.19.0,>=0.18.0rc4",
|
|
10
10
|
"satori-python-server<1.4.0,>=1.3.0",
|
|
11
11
|
]
|
|
12
12
|
requires-python = ">=3.10"
|
|
@@ -33,12 +33,15 @@ build-backend = "pdm.backend"
|
|
|
33
33
|
[tool.pdm]
|
|
34
34
|
distribution = true
|
|
35
35
|
|
|
36
|
+
[tool.pyright]
|
|
37
|
+
typeCheckingMode = "basic"
|
|
38
|
+
|
|
36
39
|
[dependency-groups]
|
|
37
40
|
dev = [
|
|
38
41
|
"arclet-entari[dotenv,reload,yaml]>=0.17.0",
|
|
39
|
-
"satori-python-adapter-onebot11>=0.4.
|
|
40
|
-
"satori-python-adapter-console>=0.5.
|
|
42
|
+
"satori-python-adapter-onebot11>=0.4.4",
|
|
43
|
+
"satori-python-adapter-console>=0.5.3",
|
|
41
44
|
"fastapi>=0.116.1",
|
|
42
45
|
"graia-amnesia>=0.11.5",
|
|
43
|
-
"satori-python-adapter-qq>=0.
|
|
46
|
+
"satori-python-adapter-qq>=0.4.0rc4",
|
|
44
47
|
]
|
{entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/__init__.py
RENAMED
|
@@ -8,12 +8,13 @@ from typing import TYPE_CHECKING, Any, Callable, Optional, Union, cast
|
|
|
8
8
|
from arclet.entari.config.models.default import BasicConfModel
|
|
9
9
|
from typing_extensions import TypeAlias
|
|
10
10
|
|
|
11
|
-
from arclet.entari import plugin
|
|
11
|
+
from arclet.entari import Plugin, plugin
|
|
12
|
+
from arclet.entari.plugin import PluginRole
|
|
12
13
|
from arclet.entari.config import EntariConfig
|
|
13
14
|
from arclet.entari.config import config_model_validate
|
|
14
15
|
from arclet.entari import logger as log_m
|
|
15
16
|
|
|
16
|
-
from arclet.letoderea.
|
|
17
|
+
from arclet.letoderea.utils import TCallable
|
|
17
18
|
from graia.amnesia.builtins.asgi import uvicorn, asgitypes
|
|
18
19
|
from satori.server import Adapter, Server
|
|
19
20
|
from starlette.applications import Starlette
|
|
@@ -28,11 +29,13 @@ DISPOSE: TypeAlias = Callable[[], None]
|
|
|
28
29
|
uvicorn.LoguruHandler = log_m.LoguruHandler
|
|
29
30
|
|
|
30
31
|
|
|
32
|
+
plg = Plugin.current()
|
|
31
33
|
plugin.declare_static()
|
|
32
34
|
plugin.metadata(
|
|
33
35
|
"server",
|
|
36
|
+
PluginRole.LIBRARY,
|
|
34
37
|
[{"name": "RF-Tar-Railt", "email": "rf_tar_railt@qq.com"}],
|
|
35
|
-
"0.
|
|
38
|
+
"0.7.1",
|
|
36
39
|
description="为 Entari 提供 Satori 服务器支持,基于此为 Entari 提供 ASGI 服务、适配器连接等功能",
|
|
37
40
|
urls={
|
|
38
41
|
"homepage": "https://github.com/ArcletProject/entari-plugin-server",
|
|
@@ -117,11 +120,19 @@ plugin.add_service(ASGI := server.asgi_service)
|
|
|
117
120
|
plugin.add_service(server)
|
|
118
121
|
|
|
119
122
|
|
|
123
|
+
def _remove_subsequence(seq, subseq):
|
|
124
|
+
# 找到子序列的起始索引
|
|
125
|
+
for i in range(len(seq) - len(subseq) + 1):
|
|
126
|
+
if seq[i:i + len(subseq)] == subseq:
|
|
127
|
+
return seq[:i] + seq[i + len(subseq):]
|
|
128
|
+
return seq # 如果没找到,返回原序列
|
|
129
|
+
|
|
130
|
+
|
|
120
131
|
def get_asgi() -> Any:
|
|
121
132
|
return server.app
|
|
122
133
|
|
|
123
134
|
|
|
124
|
-
def replace_asgi(app: Union[ASGIApp, asgitypes.ASGI3Application])
|
|
135
|
+
def replace_asgi(app: Union[ASGIApp, asgitypes.ASGI3Application]):
|
|
125
136
|
"""
|
|
126
137
|
替换当前的 ASGI 应用
|
|
127
138
|
|
|
@@ -132,26 +143,21 @@ def replace_asgi(app: Union[ASGIApp, asgitypes.ASGI3Application]) -> DISPOSE:
|
|
|
132
143
|
logger.warning("Server is blocking, cannot replace ASGI app")
|
|
133
144
|
return lambda: None
|
|
134
145
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def remove_subsequence(seq, subseq):
|
|
141
|
-
# 找到子序列的起始索引
|
|
142
|
-
for i in range(len(seq) - len(subseq) + 1):
|
|
143
|
-
if seq[i:i + len(subseq)] == subseq:
|
|
144
|
-
return seq[:i] + seq[i + len(subseq):]
|
|
145
|
-
return seq # 如果没找到,返回原序列
|
|
146
|
-
|
|
147
|
-
def dispose(_old=old_app, _old_routes=old_routes):
|
|
148
|
-
server.app.router.routes = remove_subsequence( # type: ignore
|
|
149
|
-
cast(Starlette, server.app).router.routes, _old_routes
|
|
150
|
-
)
|
|
151
|
-
server.app = _old
|
|
146
|
+
def _():
|
|
147
|
+
old_app = server.app
|
|
148
|
+
old_routes = cast(Starlette, old_app).router.routes.copy()
|
|
149
|
+
server.app = app
|
|
150
|
+
server.app.router.routes[:0] = old_routes # type: ignore
|
|
152
151
|
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
def dispose(_old=old_app, _old_routes=old_routes):
|
|
153
|
+
server.app.router.routes = _remove_subsequence( # type: ignore
|
|
154
|
+
cast(Starlette, server.app).router.routes, _old_routes
|
|
155
|
+
)
|
|
156
|
+
server.app = _old
|
|
157
|
+
|
|
158
|
+
return dispose
|
|
159
|
+
|
|
160
|
+
return plg.effect(_, "replace_asgi")
|
|
155
161
|
|
|
156
162
|
|
|
157
163
|
def add_route(
|
|
@@ -175,12 +181,15 @@ def add_route(
|
|
|
175
181
|
def wrapper(endpoint: TCallable, /) -> TCallable:
|
|
176
182
|
app = cast(Starlette, server.app)
|
|
177
183
|
fn = getattr(app.router, "add_api_route", app.router.add_route)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
|
|
185
|
+
def _():
|
|
186
|
+
fn(
|
|
187
|
+
path, endpoint, methods=methods, name=name, include_in_schema=include_in_schema, **kwargs
|
|
188
|
+
)
|
|
189
|
+
route = app.router.routes[-1]
|
|
190
|
+
return lambda: app.router.routes.remove(route)
|
|
191
|
+
|
|
192
|
+
plg.effect(_, f"add_route {path} {methods}")
|
|
184
193
|
return endpoint
|
|
185
194
|
|
|
186
195
|
return wrapper
|
|
@@ -203,12 +212,15 @@ def add_websocket_route(
|
|
|
203
212
|
def wrapper(endpoint: TCallable, /) -> TCallable:
|
|
204
213
|
app = cast(Starlette, server.app)
|
|
205
214
|
fn = getattr(app.router, "add_api_websocket_route", app.router.add_websocket_route)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
215
|
+
|
|
216
|
+
def _():
|
|
217
|
+
fn(
|
|
218
|
+
path, endpoint, name=name, **kwargs
|
|
219
|
+
)
|
|
220
|
+
route = app.router.routes[-1]
|
|
221
|
+
return lambda: app.router.routes.remove(route)
|
|
222
|
+
|
|
223
|
+
plg.effect(_, f"add_websocket_route {path}")
|
|
212
224
|
return endpoint
|
|
213
225
|
|
|
214
226
|
return wrapper
|
|
@@ -104,7 +104,7 @@ class DirectAdapterServer(Server):
|
|
|
104
104
|
)
|
|
105
105
|
acc.protocol.server = self
|
|
106
106
|
app.accounts[login_sn] = acc
|
|
107
|
-
logger.
|
|
107
|
+
logger.debug(f"account added: {acc}")
|
|
108
108
|
else:
|
|
109
109
|
acc = app.accounts[login_sn].custom(protocol_cls=DirectAdapterProtocol)
|
|
110
110
|
acc.protocol.server = self
|
|
File without changes
|
|
File without changes
|
{entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/README.md
RENAMED
|
File without changes
|
{entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/_adapter.py
RENAMED
|
File without changes
|
{entari_plugin_server-0.6.2 → entari_plugin_server-0.7.1}/src/entari_plugin_server/config.py
RENAMED
|
File without changes
|
|
File without changes
|