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.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: entari-plugin-server
3
- Version: 0.6.2
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.18.0,>=0.17.0rc1
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.6.2"
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.18.0,>=0.17.0rc1",
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.1",
40
- "satori-python-adapter-console>=0.5.1",
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.2.0",
46
+ "satori-python-adapter-qq>=0.4.0rc4",
44
47
  ]
@@ -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.typing import TCallable
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.6.2",
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]) -> DISPOSE:
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
- old_app = server.app
136
- old_routes = cast(Starlette, old_app).router.routes.copy()
137
- server.app = app
138
- server.app.router.routes[:0] = old_routes # type: ignore
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
- plugin.collect_disposes(cast(DISPOSE, dispose))
154
- return cast(DISPOSE, dispose)
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
- fn(
179
- path, endpoint, methods=methods, name=name, include_in_schema=include_in_schema, **kwargs
180
- )
181
- route = app.router.routes[-1]
182
- plug = plugin.get_plugin(1)
183
- plug.collect(lambda: app.router.routes.remove(route))
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
- fn(
207
- path, endpoint, name=name, **kwargs
208
- )
209
- route = app.router.routes[-1]
210
- plug = plugin.get_plugin(1)
211
- plug.collect(lambda: app.router.routes.remove(route))
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.info(f"account added: {acc}")
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