ErisPulse 2.1.1__py3-none-any.whl → 2.1.2__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.
@@ -17,3 +17,17 @@ __all__ = [
17
17
  'util',
18
18
  'adapter_server'
19
19
  ]
20
+
21
+ _config = env.getConfig("ErisPulse")
22
+
23
+ if _config is None:
24
+ defaultConfig = {
25
+ "server": {
26
+ "host": "0.0.0.0",
27
+ "port": 8000,
28
+ "ssl_certfile": None,
29
+ "ssl_keyfile": None
30
+ }
31
+ }
32
+ env.setConfig("ErisPulse", defaultConfig)
33
+ _config = defaultConfig
ErisPulse/Core/adapter.py CHANGED
@@ -34,20 +34,22 @@ class SendDSLBase:
34
34
  {!--< /tips >!--}
35
35
  """
36
36
 
37
- def __init__(self, adapter: 'BaseAdapter', target_type: Optional[str] = None, target_id: Optional[str] = None):
37
+ def __init__(self, adapter: 'BaseAdapter', target_type: Optional[str] = None, target_id: Optional[str] = None, account_id: Optional[str] = None):
38
38
  """
39
39
  初始化DSL发送器
40
40
 
41
41
  :param adapter: 所属适配器实例
42
42
  :param target_type: 目标类型(可选)
43
43
  :param target_id: 目标ID(可选)
44
+ :param _account_id: 发送账号(可选)
44
45
  """
45
46
  self._adapter = adapter
46
47
  self._target_type = target_type
47
48
  self._target_id = target_id
48
49
  self._target_to = target_id
50
+ self._account = account_id
49
51
 
50
- def To(self, target_type: str = None, target_id: str = None) -> 'SendDSL':
52
+ def To(self, target_type: str = None, target_id: Union[str, int] = None) -> 'SendDSL':
51
53
  """
52
54
  设置消息目标
53
55
 
@@ -63,7 +65,20 @@ class SendDSLBase:
63
65
  target_id = target_type
64
66
  target_type = None
65
67
 
66
- return self.__class__(self._adapter, target_type, target_id)
68
+ return self.__class__(self._adapter, target_type, target_id, self._account_id)
69
+
70
+ def Using(self, account_id: Union[str, int]) -> 'SendDSL':
71
+ """
72
+ 设置发送账号
73
+
74
+ :param _account_id: 发送账号
75
+ :return: SendDSL实例
76
+
77
+ :example:
78
+ >>> adapter.Send.Using("bot1").To("123").Text("Hello")
79
+ >>> adapter.Send.To("123").Using("bot1").Text("Hello") # 支持乱序
80
+ """
81
+ return self.__class__(self._adapter, self._target_type, self._target_id, account_id)
67
82
 
68
83
 
69
84
  class BaseAdapter:
@@ -90,23 +105,18 @@ class BaseAdapter:
90
105
  {!--< /tips >!--}
91
106
  """
92
107
 
93
- def Text(self, text: str) -> Awaitable[Any]:
108
+ def Example(self, text: str) -> Awaitable[Any]:
94
109
  """
95
- 基础文本消息发送方法
110
+ 示例消息发送方法
96
111
 
97
112
  :param text: 文本内容
98
113
  :return: 异步任务
99
114
  :example:
100
- >>> await adapter.Send.To("123").Text("Hello")
115
+ >>> await adapter.Send.To("123").Example("Hello")
101
116
  """
102
- return asyncio.create_task(
103
- self._adapter.call_api(
104
- endpoint="/send",
105
- content=text,
106
- recvId=self._target_id,
107
- recvType=self._target_type
108
- )
109
- )
117
+ from .logger import logger
118
+ logger.debug(f"适配器 {self._adapter.__class__.__name__} 发送了实例类型的消息: {text}")
119
+
110
120
 
111
121
  def __init__(self):
112
122
  """
@@ -396,18 +406,8 @@ class AdapterManager:
396
406
  from .logger import logger
397
407
  from .server import adapter_server
398
408
 
399
- server_config = env.getConfig("Server")
400
-
401
- if server_config is None:
402
- server_config = {
403
- "host": "0.0.0.0",
404
- "port": 8000,
405
- "ssl_certfile": None,
406
- "ssl_keyfile": None
407
- }
408
- env.setConfig("Server", server_config)
409
- logger.info("已创建服务器配置")
410
-
409
+ from . import _config
410
+ server_config = _config.get("server", {})
411
411
  host = server_config["host"]
412
412
  port = server_config["port"]
413
413
  ssl_cert = server_config.get("ssl_certfile", None)
@@ -494,7 +494,7 @@ class AdapterManager:
494
494
  await adapter.shutdown()
495
495
 
496
496
  from .server import adapter_server
497
- adapter_server.stop()
497
+ await adapter_server.stop()
498
498
 
499
499
  def get(self, platform: str) -> Optional[BaseAdapter]:
500
500
  """
@@ -545,4 +545,4 @@ class AdapterManager:
545
545
 
546
546
  AdapterFather = BaseAdapter
547
547
  adapter = AdapterManager()
548
- SendDSL = SendDSLBase
548
+ SendDSL = SendDSLBase
ErisPulse/Core/server.py CHANGED
@@ -245,7 +245,7 @@ class AdapterServer:
245
245
 
246
246
  config = Config()
247
247
  config.bind = [f"{host}:{port}"]
248
- # config.loglevel = "debug"
248
+ config.loglevel = "warning"
249
249
 
250
250
  if ssl_certfile and ssl_keyfile:
251
251
  config.certfile = ssl_certfile
ErisPulse/__init__.py CHANGED
@@ -490,7 +490,8 @@ class ModuleInitializer:
490
490
  module_objs, enabled_modules, disabled_modules = ModuleLoader.load()
491
491
  logger.info(f"[Init] 加载了 {len(enabled_modules)} 个模块, {len(disabled_modules)} 个模块被禁用")
492
492
 
493
- if os.path.join(os.path.dirname(__file__), "modules"):
493
+ modules_dir = os.path.join(os.path.dirname(__file__), "modules")
494
+ if os.path.exists(modules_dir) and os.listdir(modules_dir):
494
495
  logger.warning("[Warning] 你的项目使用了已经弃用的模块加载方式, 请尽快使用 PyPI 模块加载方式代替")
495
496
 
496
497
  if not enabled_modules and not enabled_adapters:
@@ -514,7 +515,7 @@ class ModuleInitializer:
514
515
  return False
515
516
 
516
517
  @staticmethod
517
- def _initialize_modules(modules: List[str], module_objs: Dict[str, Any]) -> None:
518
+ def _initialize_modules(modules: List[str], module_objs: Dict[str, Any]) -> bool:
518
519
  """
519
520
  {!--< internal-use >!--}
520
521
  初始化模块
@@ -524,13 +525,14 @@ class ModuleInitializer:
524
525
 
525
526
  :return: bool 模块初始化是否成功
526
527
  """
528
+ # 第一阶段:将所有模块挂载到LazyModule代理上
527
529
  for module_name in modules:
528
530
  module_obj = module_objs[module_name]
529
531
  meta_name = module_obj.moduleInfo["meta"]["name"]
530
532
 
531
533
  if hasattr(sdk, meta_name):
532
534
  continue
533
-
535
+
534
536
  try:
535
537
  entry_points = importlib.metadata.entry_points()
536
538
  if hasattr(entry_points, 'select'):
@@ -543,29 +545,51 @@ class ModuleInitializer:
543
545
  entry_point = module_entry_map.get(meta_name)
544
546
  if entry_point:
545
547
  module_class = entry_point.load()
546
- lazy_load = ModuleLoader._should_lazy_load(module_class)
547
548
 
548
- if lazy_load:
549
- lazy_module = LazyModule(meta_name, module_class, sdk, module_obj.moduleInfo)
550
- setattr(sdk, meta_name, lazy_module)
551
- else:
552
- init_signature = inspect.signature(module_class.__init__)
553
- if 'sdk' in init_signature.parameters:
554
- instance = module_class(sdk)
555
- else:
556
- instance = module_class()
557
-
558
- setattr(instance, "moduleInfo", module_obj.moduleInfo)
559
- setattr(sdk, meta_name, instance)
549
+ # 创建LazyModule代理
550
+ lazy_module = LazyModule(meta_name, module_class, sdk, module_obj.moduleInfo)
551
+ setattr(sdk, meta_name, lazy_module)
560
552
 
561
553
  logger.debug(f"预注册模块: {meta_name}")
562
-
563
- return True
564
554
 
565
555
  except Exception as e:
566
556
  logger.error(f"预注册模块 {meta_name} 失败: {e}")
567
557
  setattr(sdk, meta_name, None)
568
558
  return False
559
+
560
+ # 第二阶段:检查并初始化需要立即加载的模块
561
+ for module_name in modules:
562
+ module_obj = module_objs[module_name]
563
+ meta_name = module_obj.moduleInfo["meta"]["name"]
564
+
565
+ if not hasattr(sdk, meta_name):
566
+ continue
567
+
568
+ try:
569
+ entry_points = importlib.metadata.entry_points()
570
+ if hasattr(entry_points, 'select'):
571
+ module_entries = entry_points.select(group='erispulse.module')
572
+ module_entry_map = {entry.name: entry for entry in module_entries}
573
+ else:
574
+ module_entries = entry_points.get('erispulse.module', [])
575
+ module_entry_map = {entry.name: entry for entry in module_entries}
576
+
577
+ entry_point = module_entry_map.get(meta_name)
578
+ if entry_point:
579
+ module_class = entry_point.load()
580
+
581
+ # 检查是否需要立即加载
582
+ lazy_load = ModuleLoader._should_lazy_load(module_class)
583
+ if not lazy_load:
584
+ # 触发LazyModule的初始化
585
+ getattr(sdk, meta_name)._initialize()
586
+ logger.debug(f"立即初始化模块: {meta_name}")
587
+
588
+ except Exception as e:
589
+ logger.error(f"初始化模块 {meta_name} 失败: {e}")
590
+ return False
591
+
592
+ return True
569
593
 
570
594
  @staticmethod
571
595
  def _register_adapters(adapters: List[str], adapter_objs: Dict[str, Any]) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse
3
- Version: 2.1.1
3
+ Version: 2.1.2
4
4
  Summary: ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。
5
5
  Author-email: "艾莉丝·格雷拉特(WSu2059)" <wsu2059@qq.com>, runoneall <runoobsteve@gmail.com>
6
6
  License: MIT License
@@ -1,16 +1,16 @@
1
- ErisPulse/__init__.py,sha256=JLcJpPdgwBzPVEurGM6hLGxok4wajh9PF8wp6VAeKGo,26329
1
+ ErisPulse/__init__.py,sha256=kQr2n1oeThlJVy7NY_ZMXgDsgZuhsBC5V6ysl2I59PQ,27471
2
2
  ErisPulse/__main__.py,sha256=yxlB-rCQKy7D5XMWqP5id1sOQbzLuPx048NNpLaCDf8,19851
3
- ErisPulse/Core/__init__.py,sha256=CIxWFdB6-0D8YJz7IdW052A4YllDsklEONCRj7mOpkQ,362
4
- ErisPulse/Core/adapter.py,sha256=2tHaN2wvPeOHN4o3BroHqeA0T-u097-HFlY8qxHvyLs,17943
3
+ ErisPulse/Core/__init__.py,sha256=Wnkb4rI5kZhg8cdJE1sBfNRch55Aqp56npQ0DGXyHMA,675
4
+ ErisPulse/Core/adapter.py,sha256=zeil2mhlZoUg8Wg6GlEMVnQ7f5rJWZNxc0c1g3c4W0w,18146
5
5
  ErisPulse/Core/env.py,sha256=9WYNadD9h2jP_2wxOVBJEhH1uDzbctW7eB4Ba9RSjA4,20409
6
6
  ErisPulse/Core/logger.py,sha256=40vDe_D3L6ople-RZX8eGXntrZpFGHHzSl3pYxK-FLI,7196
7
7
  ErisPulse/Core/mods.py,sha256=5SPutuzbMrA-VZwiXeNxYWfrdbpLRdYfQ0RvEkFuQgg,7308
8
8
  ErisPulse/Core/raiserr.py,sha256=QLQ3r7p4iFP86XBLq9mtf1wv1xSlgny35i8t5-l4DXo,4620
9
- ErisPulse/Core/server.py,sha256=H8dUUj8mxBLEd3ick7btbWEE_m58Y6277Zo5FY7Ild4,9217
9
+ ErisPulse/Core/server.py,sha256=FkDTeLuHD5IBnWVxvYU8pHb6yCt8GzyvC1bpOiJ7G7I,9217
10
10
  ErisPulse/Core/shellprint.py,sha256=-BFoyFho_D3XEhxIoKt6x5gO4C62LKwmJWKDUGiPjNY,5908
11
11
  ErisPulse/Core/util.py,sha256=kyydBAJHHG9I7rMRzKWtLAQMZoJyBqHiBAweqcraFkU,4001
12
- erispulse-2.1.1.dist-info/METADATA,sha256=QYngGAOCd2sYXMr-Ezfeift5FyZPqBEWKBI8Kf76S_0,6161
13
- erispulse-2.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- erispulse-2.1.1.dist-info/entry_points.txt,sha256=Jss71M6nEha0TA-DyVZugPYdcL14s9QpiOeIlgWxzOc,182
15
- erispulse-2.1.1.dist-info/licenses/LICENSE,sha256=lBYj7Nk4urLvByj4HvQFxu8j9hThhFF6OGfyxAZBP9Q,1451
16
- erispulse-2.1.1.dist-info/RECORD,,
12
+ erispulse-2.1.2.dist-info/METADATA,sha256=weSMmPWTDHy4mx36qhkHle7Wj9dC7dKv7qO_IX19vOI,6161
13
+ erispulse-2.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ erispulse-2.1.2.dist-info/entry_points.txt,sha256=Jss71M6nEha0TA-DyVZugPYdcL14s9QpiOeIlgWxzOc,182
15
+ erispulse-2.1.2.dist-info/licenses/LICENSE,sha256=lBYj7Nk4urLvByj4HvQFxu8j9hThhFF6OGfyxAZBP9Q,1451
16
+ erispulse-2.1.2.dist-info/RECORD,,