ErisPulse 2.3.4.dev2__py3-none-any.whl → 2.3.4.dev114514__py3-none-any.whl

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.
Files changed (40) hide show
  1. ErisPulse/Core/Bases/module.py +1 -53
  2. ErisPulse/Core/Bases/module.pyi +0 -43
  3. ErisPulse/Core/Event/command.py +1 -6
  4. ErisPulse/Core/_self_config.py +1 -1
  5. ErisPulse/Core/adapter.py +10 -70
  6. ErisPulse/Core/adapter.pyi +1 -18
  7. ErisPulse/Core/exceptions.py +2 -4
  8. ErisPulse/Core/lifecycle.py +0 -9
  9. ErisPulse/Core/logger.py +15 -21
  10. ErisPulse/Core/logger.pyi +1 -2
  11. ErisPulse/Core/module.py +9 -57
  12. ErisPulse/Core/module.pyi +1 -12
  13. ErisPulse/Core/router.py +5 -13
  14. ErisPulse/Core/storage.py +256 -94
  15. ErisPulse/Core/storage.pyi +66 -13
  16. ErisPulse/__init__.py +1237 -35
  17. ErisPulse/__init__.pyi +290 -3
  18. ErisPulse/sdk_protocol.py +143 -0
  19. ErisPulse/sdk_protocol.pyi +97 -0
  20. {erispulse-2.3.4.dev2.dist-info → erispulse-2.3.4.dev114514.dist-info}/METADATA +1 -1
  21. {erispulse-2.3.4.dev2.dist-info → erispulse-2.3.4.dev114514.dist-info}/RECORD +24 -38
  22. ErisPulse/Core/Bases/manager.py +0 -136
  23. ErisPulse/Core/Bases/manager.pyi +0 -108
  24. ErisPulse/loaders/__init__.py +0 -22
  25. ErisPulse/loaders/__init__.pyi +0 -21
  26. ErisPulse/loaders/adapter_loader.py +0 -187
  27. ErisPulse/loaders/adapter_loader.pyi +0 -82
  28. ErisPulse/loaders/base_loader.py +0 -162
  29. ErisPulse/loaders/base_loader.pyi +0 -23
  30. ErisPulse/loaders/initializer.py +0 -150
  31. ErisPulse/loaders/initializer.pyi +0 -60
  32. ErisPulse/loaders/module_loader.py +0 -618
  33. ErisPulse/loaders/module_loader.pyi +0 -179
  34. ErisPulse/loaders/strategy.py +0 -129
  35. ErisPulse/loaders/strategy.pyi +0 -90
  36. ErisPulse/sdk.py +0 -435
  37. ErisPulse/sdk.pyi +0 -158
  38. {erispulse-2.3.4.dev2.dist-info → erispulse-2.3.4.dev114514.dist-info}/WHEEL +0 -0
  39. {erispulse-2.3.4.dev2.dist-info → erispulse-2.3.4.dev114514.dist-info}/entry_points.txt +0 -0
  40. {erispulse-2.3.4.dev2.dist-info → erispulse-2.3.4.dev114514.dist-info}/licenses/LICENSE +0 -0
@@ -4,10 +4,6 @@ ErisPulse 模块基础模块
4
4
  提供模块基类定义和标准接口
5
5
  """
6
6
 
7
- from typing import Union, Dict, Any
8
- from ...loaders.strategy import ModuleLoadStrategy
9
-
10
-
11
7
  class BaseModule:
12
8
  """
13
9
  模块基类
@@ -15,63 +11,15 @@ class BaseModule:
15
11
  提供模块加载和卸载的标准接口
16
12
  """
17
13
 
18
- @staticmethod
19
- def get_load_strategy() -> Union[ModuleLoadStrategy, Dict[str, Any]]:
20
- """
21
- 获取模块加载策略
22
-
23
- 支持返回 ModuleLoadStrategy 对象或字典
24
- 所有属性统一处理,没有任何预定义字段
25
-
26
- :return: 加载策略对象或字典
27
-
28
- {!--< tips >!--}
29
- 常用配置项:
30
- - lazy_load: bool, 是否懒加载(默认 True)
31
- - priority: int, 加载优先级(默认 0,数值越大优先级越高)
32
-
33
- 使用方式:
34
- >>> class MyModule(BaseModule):
35
- ... @staticmethod
36
- ... def get_load_strategy() -> ModuleLoadStrategy:
37
- ... return ModuleLoadStrategy(
38
- ... lazy_load=False,
39
- ... priority=100
40
- ... )
41
-
42
- 或使用字典:
43
- >>> class MyModule(BaseModule):
44
- ... @staticmethod
45
- ... def get_load_strategy() -> dict:
46
- ... return {
47
- ... "lazy_load": False,
48
- ... "priority": 100
49
- ... }
50
- {!--< /tips >!--}
51
- """
52
- return ModuleLoadStrategy(
53
- lazy_load=True, # 默认懒加载
54
- priority=0 # 默认优先级
55
- )
56
-
57
14
  @staticmethod
58
15
  def should_eager_load() -> bool:
59
16
  """
60
17
  模块是否应该在启动时加载
61
18
  默认为False(即懒加载)
62
-
63
- 兼容方法,实际调用 get_load_strategy()
64
19
 
65
20
  :return: 是否应该在启动时加载
66
-
67
- {!--< tips >!--}
68
- 旧版方法,建议使用 get_load_strategy() 替代
69
- {!--< /tips >!--}
70
21
  """
71
- strategy = BaseModule.get_load_strategy()
72
- if isinstance(strategy, dict):
73
- return not strategy.get('lazy_load', True)
74
- return not (strategy.lazy_load if 'lazy_load' in strategy else True)
22
+ return False
75
23
 
76
24
  async def on_load(self, event: dict) -> bool:
77
25
  """
@@ -10,61 +10,18 @@ ErisPulse 模块基础模块
10
10
  提供模块基类定义和标准接口
11
11
  """
12
12
 
13
- from typing import Union, Dict, Any
14
- from ...loaders.strategy import ModuleLoadStrategy
15
-
16
13
  class BaseModule:
17
14
  """
18
15
  模块基类
19
16
 
20
17
  提供模块加载和卸载的标准接口
21
18
  """
22
- def get_load_strategy() -> Union[(ModuleLoadStrategy, Dict[(str, Any)])]:
23
- """
24
- 获取模块加载策略
25
-
26
- 支持返回 ModuleLoadStrategy 对象或字典
27
- 所有属性统一处理,没有任何预定义字段
28
-
29
- :return: 加载策略对象或字典
30
-
31
- {!--< tips >!--}
32
- 常用配置项:
33
- - lazy_load: bool, 是否懒加载(默认 True)
34
- - priority: int, 加载优先级(默认 0,数值越大优先级越高)
35
-
36
- 使用方式:
37
- >>> class MyModule(BaseModule):
38
- ... @staticmethod
39
- ... def get_load_strategy() -> ModuleLoadStrategy:
40
- ... return ModuleLoadStrategy(
41
- ... lazy_load=False,
42
- ... priority=100
43
- ... )
44
-
45
- 或使用字典:
46
- >>> class MyModule(BaseModule):
47
- ... @staticmethod
48
- ... def get_load_strategy() -> dict:
49
- ... return {
50
- ... "lazy_load": False,
51
- ... "priority": 100
52
- ... }
53
- {!--< /tips >!--}
54
- """
55
- ...
56
19
  def should_eager_load() -> bool:
57
20
  """
58
21
  模块是否应该在启动时加载
59
22
  默认为False(即懒加载)
60
23
 
61
- 兼容方法,实际调用 get_load_strategy()
62
-
63
24
  :return: 是否应该在启动时加载
64
-
65
- {!--< tips >!--}
66
- 旧版方法,建议使用 get_load_strategy() 替代
67
- {!--< /tips >!--}
68
25
  """
69
26
  ...
70
27
  async def on_load(self: object, event: dict) -> bool:
@@ -94,7 +94,7 @@ class CommandHandler:
94
94
  "main_name": main_name
95
95
  }
96
96
 
97
- # 注册别名映射(name列表中的额外名称)
97
+ # 注册别名映射
98
98
  if cmd_name != main_name:
99
99
  self.aliases[cmd_name] = main_name
100
100
 
@@ -102,11 +102,6 @@ class CommandHandler:
102
102
  if permission and cmd_name not in self.permissions:
103
103
  self.permissions[cmd_name] = permission
104
104
 
105
- # 注册aliases参数中的别名
106
- for alias in alias_list:
107
- if alias not in self.aliases:
108
- self.aliases[alias] = main_name
109
-
110
105
  # 添加到命令组
111
106
  if group:
112
107
  if group not in self.groups:
@@ -21,7 +21,7 @@ DEFAULT_ERISPULSE_CONFIG = {
21
21
  "memory_limit": 1000
22
22
  },
23
23
  "storage": {
24
- "use_global_db": False,
24
+ "max_snapshot": 20
25
25
  },
26
26
  "modules": {},
27
27
  "adapters": {},
ErisPulse/Core/adapter.py CHANGED
@@ -14,9 +14,8 @@ from .logger import logger
14
14
  from .Bases.adapter import BaseAdapter
15
15
  from .config import config
16
16
  from .lifecycle import lifecycle
17
- from .Bases.manager import ManagerBase
18
17
 
19
- class AdapterManager(ManagerBase):
18
+ class AdapterManager:
20
19
  """
21
20
  适配器管理器
22
21
 
@@ -270,9 +269,6 @@ class AdapterManager(ManagerBase):
270
269
  from .router import router
271
270
  await router.stop()
272
271
 
273
- # 清空已启动实例集合
274
- self._started_instances.clear()
275
-
276
272
  # 提交适配器关闭完成事件
277
273
  await lifecycle.submit_event(
278
274
  "adapter.stopped",
@@ -305,8 +301,9 @@ class AdapterManager(ManagerBase):
305
301
  :param platform: 平台名称
306
302
  :return: [bool] 平台是否存在
307
303
  """
308
- # 检查平台是否已注册(在 _adapters 中)
309
- return platform in self._adapters
304
+ # 检查平台是否在配置中注册
305
+ adapter_statuses = config.getConfig("ErisPulse.adapters.status", {})
306
+ return platform in adapter_statuses
310
307
 
311
308
  def is_enabled(self, platform: str) -> bool:
312
309
  """
@@ -335,11 +332,10 @@ class AdapterManager(ManagerBase):
335
332
  :param platform: 平台名称
336
333
  :return: [bool] 操作是否成功
337
334
  """
338
- # 启用平台时自动在配置中注册
339
- if platform not in self._adapters:
335
+ if not self.exists(platform):
340
336
  logger.error(f"平台 {platform} 不存在")
341
337
  return False
342
-
338
+
343
339
  config.setConfig(f"ErisPulse.adapters.status.{platform}", True)
344
340
  logger.info(f"平台 {platform} 已启用")
345
341
  return True
@@ -351,77 +347,21 @@ class AdapterManager(ManagerBase):
351
347
  :param platform: 平台名称
352
348
  :return: [bool] 操作是否成功
353
349
  """
354
- # 禁用平台时自动在配置中注册
355
- if platform not in self._adapters:
350
+ if not self.exists(platform):
356
351
  logger.error(f"平台 {platform} 不存在")
357
352
  return False
358
-
353
+
359
354
  config.setConfig(f"ErisPulse.adapters.status.{platform}", False)
360
355
  logger.info(f"平台 {platform} 已禁用")
361
356
  return True
362
357
 
363
- def unregister(self, platform: str) -> bool:
364
- """
365
- 取消注册适配器
366
-
367
- :param platform: 平台名称
368
- :return: 是否取消成功
369
-
370
- {!--< internal-use >!--}
371
- 注意:此方法仅取消注册,不关闭已启动的适配器
372
- {!--< /internal-use >!--}
373
- """
374
- if platform not in self._adapters:
375
- logger.warning(f"平台 {platform} 未注册")
376
- return False
377
-
378
- # 移除适配器实例
379
- adapter = self._adapters.pop(platform)
380
-
381
- # 移除平台属性
382
- if len(platform) <= 10:
383
- from itertools import product
384
- combinations = [''.join(c) for c in product(*[(ch.lower(), ch.upper()) for ch in platform])]
385
- for name in set(combinations):
386
- if hasattr(self, name):
387
- delattr(self, name)
388
- else:
389
- if hasattr(self, platform.lower()):
390
- delattr(self, platform.lower())
391
- if hasattr(self, platform.upper()):
392
- delattr(self, platform.upper())
393
- if hasattr(self, platform.capitalize()):
394
- delattr(self, platform.capitalize())
395
-
396
- logger.info(f"平台 {platform} 已取消注册")
397
- return True
398
-
399
- def list_registered(self) -> List[str]:
400
- """
401
- 列出所有已注册的平台
402
-
403
- :return: 平台名称列表
404
- """
405
- return list(self._adapters.keys())
406
-
407
- def list_items(self) -> Dict[str, bool]:
408
- """
409
- 列出所有平台适配器状态
410
-
411
- :return: {平台名: 是否启用} 字典
412
- """
413
- return config.getConfig("ErisPulse.adapters.status", {})
414
-
415
- # 兼容性方法 - 保持向后兼容
416
358
  def list_adapters(self) -> Dict[str, bool]:
417
359
  """
418
360
  列出所有平台适配器状态
419
-
420
- {!--< deprecated >!--} 请使用 list_items() 代替
421
-
361
+
422
362
  :return: [Dict[str, bool]] 平台适配器状态字典
423
363
  """
424
- return self.list_items()
364
+ return config.getConfig("ErisPulse.adapters.status", {})
425
365
 
426
366
  # ==================== 事件处理与消息发送 ====================
427
367
 
@@ -18,9 +18,8 @@ from .logger import logger
18
18
  from .Bases.adapter import BaseAdapter
19
19
  from .config import config
20
20
  from .lifecycle import lifecycle
21
- from .Bases.manager import ManagerBase
22
21
 
23
- class AdapterManager(ManagerBase):
22
+ class AdapterManager:
24
23
  """
25
24
  适配器管理器
26
25
 
@@ -119,26 +118,10 @@ class AdapterManager(ManagerBase):
119
118
  :return: [bool] 操作是否成功
120
119
  """
121
120
  ...
122
- def list_registered(self: object) -> List[str]:
123
- """
124
- 列出所有已注册的平台
125
-
126
- :return: 平台名称列表
127
- """
128
- ...
129
- def list_items(self: object) -> Dict[(str, bool)]:
130
- """
131
- 列出所有平台适配器状态
132
-
133
- :return: {平台名: 是否启用} 字典
134
- """
135
- ...
136
121
  def list_adapters(self: object) -> Dict[(str, bool)]:
137
122
  """
138
123
  列出所有平台适配器状态
139
124
 
140
- {!--< deprecated >!--} 请使用 list_items() 代替
141
-
142
125
  :return: [Dict[str, bool]] 平台适配器状态字典
143
126
  """
144
127
  ...
@@ -108,8 +108,6 @@ def setup_async_loop(loop: asyncio.AbstractEventLoop = None) -> None: # type:
108
108
 
109
109
  sys.excepthook = global_exception_handler
110
110
  try:
111
- loop = asyncio.get_running_loop()
112
- loop.set_exception_handler(async_exception_handler)
111
+ asyncio.get_event_loop().set_exception_handler(async_exception_handler)
113
112
  except RuntimeError:
114
- # 没有运行中的事件循环,这是正常的,在运行时再设置
115
- pass
113
+ pass
@@ -120,15 +120,6 @@ class LifecycleManager:
120
120
  :param event: 事件名称
121
121
  :param event_data: 事件数据字典
122
122
  """
123
- # 验证事件类型
124
- if event_type is None:
125
- logger.error("事件类型不能为None")
126
- return
127
-
128
- if not isinstance(event_type, str) or not event_type:
129
- logger.error(f"事件类型必须是非空字符串,收到: {event_type}")
130
- return
131
-
132
123
  # 构建完整事件数据
133
124
  event_data = {
134
125
  "event": event_type,
ErisPulse/Core/logger.py CHANGED
@@ -91,6 +91,11 @@ class Logger:
91
91
  :param level: 日志级别(DEBUG/INFO/WARNING/ERROR/CRITICAL)
92
92
  :return: bool 设置是否成功
93
93
  """
94
+ from .module import module
95
+
96
+ if not module.is_enabled(module_name):
97
+ self._logger.warning(f"模块 {module_name} 未启用,无法设置日志等级。")
98
+ return False
94
99
  level = level.upper()
95
100
  if hasattr(logging, level):
96
101
  self._module_levels[module_name] = getattr(logging, level)
@@ -110,21 +115,19 @@ class Logger:
110
115
  if self._file_handler:
111
116
  self._logger.removeHandler(self._file_handler)
112
117
  self._file_handler.close()
113
- self._file_handler = None
114
118
 
115
119
  if isinstance(path, str):
116
120
  path = [path]
117
121
 
118
122
  for p in path:
119
123
  try:
120
- self._file_handler = logging.FileHandler(p, encoding="utf-8")
124
+ file_handler = logging.FileHandler(p, encoding="utf-8")
121
125
  # 使用自定义格式化器去除rich markup标签
122
- self._file_handler.setFormatter(logging.Formatter("[%(name)s] %(message)s"))
123
- self._logger.addHandler(self._file_handler)
126
+ file_handler.setFormatter(logging.Formatter("[%(name)s] %(message)s"))
127
+ self._logger.addHandler(file_handler)
124
128
  return True
125
129
  except Exception as e:
126
130
  self._logger.error(f"无法设置日志文件 {p}: {e}")
127
- self._file_handler = None
128
131
  return False
129
132
 
130
133
  self._logger.warning("出现极端错误,无法设置日志文件。")
@@ -137,11 +140,9 @@ class Logger:
137
140
  :param path: 日志文件路径 Str/List
138
141
  :return: bool 设置是否成功
139
142
  """
140
- # 检查是否有日志记录
141
- if not self._logs or all(len(logs) == 0 for logs in self._logs.values()):
143
+ if self._logs is None:
142
144
  self._logger.warning("没有log记录可供保存。")
143
145
  return False
144
-
145
146
  if isinstance(path, str):
146
147
  path = [path]
147
148
 
@@ -161,18 +162,16 @@ class Logger:
161
162
  self._logger.warning("出现极端错误,无法保存日志。")
162
163
  return False
163
164
 
164
- def get_logs(self, module_name: str = None) -> dict:
165
+ def get_logs(self, module_name: str = "Unknown") -> dict:
165
166
  """
166
167
  获取日志内容
167
168
 
168
- :param module_name (可选): 模块名称,None表示获取所有日志
169
+ :param module_name (可选): 模块名称
169
170
  :return: dict 日志内容
170
171
  """
171
- if module_name is None:
172
- # 返回所有日志
173
- return {k: v.copy() for k, v in self._logs.items()}
174
- # 返回指定模块的日志
175
- return {module_name: self._logs.get(module_name, [])}
172
+ if module_name:
173
+ return {module_name: self._logs.get(module_name, [])}
174
+ return {k: v.copy() for k, v in self._logs.items()}
176
175
 
177
176
  def _save_in_memory(self, ModuleName, msg):
178
177
  if ModuleName not in self._logs:
@@ -227,18 +226,13 @@ class Logger:
227
226
  except Exception:
228
227
  return "Unknown"
229
228
 
230
- def get_child(self, child_name: str = "UnknownChild", *, relative: bool = True):
229
+ def get_child(self, child_name: str = "UnknownChild"):
231
230
  """
232
231
  获取子日志记录器
233
232
 
234
233
  :param child_name: 子模块名称(可选)
235
- :param relative: 是否相对于调用者模块(默认True),False表示使用完整名称
236
234
  :return: LoggerChild 子日志记录器实例
237
235
  """
238
- if child_name and not relative:
239
- # 使用完整的指定名称,不添加前缀
240
- return LoggerChild(self, child_name)
241
-
242
236
  caller_module = self._get_caller()
243
237
  if child_name:
244
238
  full_module_name = f"{caller_module}.{child_name}"
ErisPulse/Core/logger.pyi CHANGED
@@ -81,7 +81,7 @@ class Logger:
81
81
  """
82
82
  获取日志内容
83
83
 
84
- :param module_name (可选): 模块名称,None表示获取所有日志
84
+ :param module_name (可选): 模块名称
85
85
  :return: dict 日志内容
86
86
  """
87
87
  ...
@@ -98,7 +98,6 @@ class Logger:
98
98
  获取子日志记录器
99
99
 
100
100
  :param child_name: 子模块名称(可选)
101
- :param relative: 是否相对于调用者模块(默认True),False表示使用完整名称
102
101
  :return: LoggerChild 子日志记录器实例
103
102
  """
104
103
  ...
ErisPulse/Core/module.py CHANGED
@@ -5,15 +5,13 @@ ErisPulse 模块系统
5
5
  """
6
6
 
7
7
  import asyncio
8
- import warnings
9
8
  from typing import Any, Dict, List, Type, Optional
10
9
  from .logger import logger
11
10
  from .config import config
12
11
  from .Bases import BaseModule
13
12
  from .lifecycle import lifecycle
14
- from .Bases.manager import ManagerBase
15
13
 
16
- class ModuleManager(ManagerBase):
14
+ class ModuleManager:
17
15
  """
18
16
  模块管理器
19
17
 
@@ -50,16 +48,9 @@ class ModuleManager(ManagerBase):
50
48
  >>> module.register("MyModule", MyModuleClass)
51
49
  """
52
50
  # 严格验证模块类,确保继承自BaseModule
53
- # 先检查是否为类对象
54
- if not isinstance(module_class, type):
55
- error_msg = f"模块 {module_name} 的参数必须是类,而不是 {type(module_class).__name__}"
56
- logger.error(error_msg)
57
- raise TypeError(error_msg)
58
-
59
51
  if not issubclass(module_class, BaseModule):
60
52
  warn_msg = f"模块 {module_name} 的类 {module_class.__name__} 没有继承自BaseModule,但我们仍会继续尝试加载这个模块,但请注意这可能引发其他问题"
61
53
  logger.warning(warn_msg)
62
- warnings.warn(warn_msg, UserWarning)
63
54
  # error_msg = f"模块 {module_name} 的类 {module_class.__name__} 必须继承自BaseModule"
64
55
  # logger.error(error_msg)
65
56
  # raise TypeError(error_msg)
@@ -72,9 +63,7 @@ class ModuleManager(ManagerBase):
72
63
 
73
64
  # 检查模块名是否已存在
74
65
  if module_name in self._module_classes:
75
- warn_msg = f"模块 {module_name} 已存在,将覆盖原模块类"
76
- logger.warning(warn_msg)
77
- warnings.warn(warn_msg, UserWarning)
66
+ logger.warning(f"模块 {module_name} 已存在,将覆盖原模块类")
78
67
 
79
68
  self._module_classes[module_name] = module_class
80
69
  if module_info:
@@ -200,15 +189,14 @@ class ModuleManager(ManagerBase):
200
189
  :param module_name: 模块名称
201
190
  :return: 是否卸载成功
202
191
  """
203
- # 模块未加载,返回 True(表示没有需要卸载的模块,这不是错误)
204
192
  if module_name not in self._loaded_modules:
205
193
  logger.warning(f"模块 {module_name} 未加载")
206
- return True
194
+ return False
207
195
 
208
196
  try:
209
197
  # 调用模块的on_unload卸载方法
210
- instance = self._modules.get(module_name)
211
- if instance and hasattr(instance, 'on_unload'):
198
+ instance = self._modules[module_name]
199
+ if hasattr(instance, 'on_unload'):
212
200
  try:
213
201
  if asyncio.iscoroutinefunction(instance.on_unload):
214
202
  await instance.on_unload({"module_name": module_name})
@@ -216,9 +204,9 @@ class ModuleManager(ManagerBase):
216
204
  instance.on_unload({"module_name": module_name})
217
205
  except Exception as e:
218
206
  logger.error(f"模块 {module_name} on_unload 方法执行失败: {e}")
219
-
207
+
220
208
  # 清理缓存
221
- del self._modules[module_name]
209
+ del self._modules[module_name]
222
210
  self._loaded_modules.discard(module_name)
223
211
 
224
212
  logger.info(f"模块 {module_name} 卸载成功")
@@ -346,49 +334,13 @@ class ModuleManager(ManagerBase):
346
334
  self._loaded_modules.discard(module_name)
347
335
  return True
348
336
 
349
- def unregister(self, module_name: str) -> bool:
350
- """
351
- 取消注册模块
352
-
353
- :param module_name: 模块名称
354
- :return: 是否取消成功
355
-
356
- {!--< internal-use >!--}
357
- 注意:此方法仅取消注册,不卸载已加载的模块
358
- {!--< /internal-use >!--}
359
- """
360
- if module_name not in self._module_classes:
361
- logger.warning(f"模块 {module_name} 未注册")
362
- return False
363
-
364
- # 移除模块类
365
- self._module_classes.pop(module_name)
366
-
367
- # 移除模块信息
368
- if module_name in self._module_info:
369
- self._module_info.pop(module_name)
370
-
371
- logger.info(f"模块 {module_name} 已取消注册")
372
- return True
373
-
374
- def list_items(self) -> Dict[str, bool]:
375
- """
376
- 列出所有模块状态
377
-
378
- :return: {模块名: 是否启用} 字典
379
- """
380
- return config.getConfig("ErisPulse.modules.status", {})
381
-
382
- # 兼容性方法 - 保持向后兼容
383
337
  def list_modules(self) -> Dict[str, bool]:
384
338
  """
385
339
  列出所有模块状态
386
340
 
387
- {!--< deprecated >!--} 请使用 list_items() 代替
388
-
389
341
  :return: [Dict[str, bool]] 模块状态字典
390
342
  """
391
- return self.list_items()
343
+ return config.getConfig("ErisPulse.modules.status", {})
392
344
 
393
345
  # ==================== 工具方法 ====================
394
346
 
@@ -418,4 +370,4 @@ module = ModuleManager()
418
370
 
419
371
  __all__ = [
420
372
  "module"
421
- ]
373
+ ]
ErisPulse/Core/module.pyi CHANGED
@@ -11,15 +11,13 @@ ErisPulse 模块系统
11
11
  """
12
12
 
13
13
  import asyncio
14
- import warnings
15
14
  from typing import Any, Dict, List, Type, Optional
16
15
  from .logger import logger
17
16
  from .config import config
18
17
  from .Bases import BaseModule
19
18
  from .lifecycle import lifecycle
20
- from .Bases.manager import ManagerBase
21
19
 
22
- class ModuleManager(ManagerBase):
20
+ class ModuleManager:
23
21
  """
24
22
  模块管理器
25
23
 
@@ -154,19 +152,10 @@ class ModuleManager(ManagerBase):
154
152
  :return: [bool] 操作是否成功
155
153
  """
156
154
  ...
157
- def list_items(self: object) -> Dict[(str, bool)]:
158
- """
159
- 列出所有模块状态
160
-
161
- :return: {模块名: 是否启用} 字典
162
- """
163
- ...
164
155
  def list_modules(self: object) -> Dict[(str, bool)]:
165
156
  """
166
157
  列出所有模块状态
167
158
 
168
- {!--< deprecated >!--} 请使用 list_items() 代替
169
-
170
159
  :return: [Dict[str, bool]] 模块状态字典
171
160
  """
172
161
  ...
ErisPulse/Core/router.py CHANGED
@@ -235,20 +235,13 @@ class RouterManager:
235
235
  try:
236
236
  full_path = f"/{module_name}{path}"
237
237
 
238
- # 检查 WebSocket 路由是否存在于我们的内部记录中
239
- if full_path in self._websocket_routes.get(module_name, {}):
238
+ # 使用类型忽略注释
239
+ if full_path in self.app.websocket_routes: # type: ignore || 原因:实际上,FastAPI的API提供了websocket_routes属性
240
+ self.app.remove_api_websocket_route(full_path) # type: ignore || 原因:实际上,FastAPI的API提供了remove_api_websocket_route方法
240
241
  display_url = self._format_display_url(f"{self.base_url}{full_path}")
241
242
  logger.info(f"注销WebSocket: {display_url}")
242
243
  del self._websocket_routes[module_name][full_path]
243
-
244
- # 从 FastAPI 路由列表中移除对应的 WebSocket 路由
245
- # FastAPI 的 WebSocket 路由有 websocket_endpoint 属性
246
- self.app.router.routes = [
247
- route for route in self.app.router.routes
248
- if not (hasattr(route, 'path') and route.path == full_path)
249
- ]
250
244
  return True
251
-
252
245
  display_url = self._format_display_url(f"{self.base_url}{full_path}")
253
246
  logger.error(f"注销WebSocket失败: 路径 {display_url} 不存在")
254
247
  return False
@@ -346,9 +339,8 @@ class RouterManager:
346
339
  if "0.0.0.0" in url:
347
340
  display_url = url.replace("0.0.0.0", "127.0.0.1")
348
341
  return f"{url} (可访问: {display_url})"
349
- elif "[::]" in url:
350
- # IPv6 回环地址需要替换括号
351
- display_url = url.replace("[::]", "localhost")
342
+ elif "::" in url:
343
+ display_url = url.replace("::", "localhost")
352
344
  return f"{url} (可访问: {display_url})"
353
345
  return url
354
346