ErisPulse 1.1.7__tar.gz → 1.1.10__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.
@@ -22,8 +22,6 @@ setattr(sdk, "adapter", adapter)
22
22
  setattr(sdk, "SendDSL", SendDSL)
23
23
  setattr(sdk, "BaseAdapter", BaseAdapter)
24
24
 
25
- env.load_env_file()
26
-
27
25
  # 注册 ErrorHook 并预注册常用错误类型
28
26
  raiserr.register("CaughtExternalError" , doc="捕获的非SDK抛出的异常")
29
27
  raiserr.register("InitError" , doc="SDK初始化错误")
@@ -34,6 +32,10 @@ raiserr.register("ModuleLoadError" , doc="模块加载错误")
34
32
 
35
33
  def init():
36
34
  try:
35
+ logger.info("[Init] SDK 正在初始化...")
36
+ env.create_env_file_if_not_exists()
37
+ env.load_env_file()
38
+
37
39
  sdkModulePath = os.path.join(os.path.dirname(__file__), "modules")
38
40
 
39
41
  if not os.path.exists(sdkModulePath):
@@ -10,8 +10,13 @@ class SendDSLBase:
10
10
  self._adapter = adapter
11
11
  self._target_type = target_type
12
12
  self._target_id = target_id
13
+ self._target_to = target_id
14
+
15
+ def To(self, target_type: str = None, target_id: str = None) -> 'SendDSL':
16
+ if target_id is None and target_type is not None:
17
+ target_id = target_type
18
+ target_type = None
13
19
 
14
- def To(self, target_type: str, target_id: str) -> 'SendDSL':
15
20
  return self.__class__(self._adapter, target_type, target_id)
16
21
 
17
22
  def __getattr__(self, name: str):
@@ -42,7 +47,7 @@ class BaseAdapter:
42
47
  # 绑定当前适配器的 Send 实例
43
48
  self.Send = self.__class__.Send(self)
44
49
 
45
- def on(self, event_type: str):
50
+ def on(self, event_type: str = "*"):
46
51
  def decorator(func: Callable):
47
52
  @functools.wraps(func)
48
53
  async def wrapper(*args, **kwargs):
@@ -64,11 +69,32 @@ class BaseAdapter:
64
69
  async def shutdown(self):
65
70
  raise NotImplementedError
66
71
 
72
+ def add_handler(self, *args):
73
+ if len(args) == 1:
74
+ event_type = "*"
75
+ handler = args[0]
76
+ elif len(args) == 2:
77
+ event_type, handler = args
78
+ else:
79
+ raise TypeError("add_handler() 接受 1 个(监听所有事件)或 2 个参数(指定事件类型)")
80
+
81
+ @functools.wraps(handler)
82
+ async def wrapper(*handler_args, **handler_kwargs):
83
+ return await handler(*handler_args, **handler_kwargs)
84
+
85
+ self._handlers[event_type].append(wrapper)
67
86
  async def emit(self, event_type: str, data: Any):
87
+ # 先执行中间件
68
88
  for middleware in self._middlewares:
69
89
  data = await middleware(data)
70
90
 
71
- for handler in self._handlers.get(event_type, []):
91
+ # 触发具体事件类型的处理器
92
+ if event_type in self._handlers:
93
+ for handler in self._handlers[event_type]:
94
+ await handler(data)
95
+
96
+ # 触发通配符 "*" 的处理器
97
+ for handler in self._handlers.get("*", []):
72
98
  await handler(data)
73
99
 
74
100
  async def send(self, target_type: str, target_id: str, message: Any, **kwargs):
@@ -102,6 +128,17 @@ class AdapterManager:
102
128
  self._adapters[platform] = instance
103
129
  self._platform_to_instance[platform] = instance
104
130
 
131
+ if len(platform) <= 10:
132
+ from itertools import product
133
+ combinations = [''.join(c) for c in product(*[(ch.lower(), ch.upper()) for ch in platform])]
134
+ for name in set(combinations):
135
+ setattr(self, name, instance)
136
+ else:
137
+ self.logger.warning(f"平台名 {platform} 过长,如果您是开发者,请考虑使用更短的名称")
138
+ setattr(self, platform.lower(), instance)
139
+ setattr(self, platform.upper(), instance)
140
+ setattr(self, platform.capitalize(), instance)
141
+
105
142
  return True
106
143
 
107
144
  async def startup(self, platforms: List[str] = None):
@@ -161,12 +198,18 @@ class AdapterManager:
161
198
  await adapter.shutdown()
162
199
 
163
200
  def get(self, platform: str) -> BaseAdapter:
164
- return self._adapters.get(platform)
201
+ platform_lower = platform.lower()
202
+ for registered, instance in self._adapters.items():
203
+ if registered.lower() == platform_lower:
204
+ return instance
205
+ return None
165
206
 
166
207
  def __getattr__(self, platform: str) -> BaseAdapter:
167
- if platform not in self._adapters:
168
- raise AttributeError(f"平台 {platform} 的适配器未注册")
169
- return self._adapters[platform]
208
+ platform_lower = platform.lower()
209
+ for registered, instance in self._adapters.items():
210
+ if registered.lower() == platform_lower:
211
+ return instance
212
+ raise AttributeError(f"平台 {platform} 的适配器未注册")
170
213
 
171
214
  @property
172
215
  def platforms(self) -> list:
@@ -16,7 +16,6 @@ class EnvManager:
16
16
  def __init__(self):
17
17
  if not hasattr(self, "_initialized"):
18
18
  self._init_db()
19
- self._create_env_file_if_not_exists()
20
19
  self._initialized = True
21
20
 
22
21
  def _init_db(self):
@@ -90,7 +89,7 @@ class EnvManager:
90
89
  if not key.startswith("__") and isinstance(value, (dict, list, str, int, float, bool)):
91
90
  self.set(key, value)
92
91
 
93
- def _create_env_file_if_not_exists(self):
92
+ def create_env_file_if_not_exists(self):
94
93
  env_file = Path("env.py")
95
94
  if not env_file.exists():
96
95
  content = '''# env.py
@@ -122,7 +121,7 @@ from ErisPulse import sdk
122
121
  try:
123
122
  return self.get(key)
124
123
  except KeyError:
125
- from . import sdk
126
- sdk.logger.error(f"配置项 {key} 不存在")
124
+ from .logger import logger
125
+ logger.error(f"配置项 {key} 不存在")
127
126
 
128
127
  env = EnvManager()
@@ -148,5 +148,8 @@ class Logger:
148
148
  if self._get_effective_level(caller_module) <= logging.CRITICAL:
149
149
  self._save_in_memory(caller_module, msg)
150
150
  self._logger.critical(f"[{caller_module}] {msg}", *args, **kwargs)
151
+ from .raiserr import raiserr
152
+ raiserr.register("CriticalError", doc="发生致命错误")
153
+ raiserr.CriticalError(f"程序发生致命错误:{msg}", exit=True)
151
154
 
152
155
  logger = Logger()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse
3
- Version: 1.1.7
3
+ Version: 1.1.10
4
4
  Summary: ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。
5
5
  Author-email: "艾莉丝·格雷拉特(WSu2059)" <wsu2059@qq.com>, runoneall <runoobsteve@gmail.com>
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -18,7 +18,9 @@ Classifier: Operating System :: OS Independent
18
18
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
19
  Requires-Python: >=3.7
20
20
  Description-Content-Type: text/markdown
21
+ License-File: LICENSE
21
22
  Requires-Dist: aiohttp
23
+ Dynamic: license-file
22
24
 
23
25
  ![](./.github/assets/erispulse_logo.png)
24
26
 
@@ -1,3 +1,4 @@
1
+ LICENSE
1
2
  README.md
2
3
  pyproject.toml
3
4
  ErisPulse/__init__.py
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ErisPulse
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse
3
- Version: 1.1.7
3
+ Version: 1.1.10
4
4
  Summary: ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。
5
5
  Author-email: "艾莉丝·格雷拉特(WSu2059)" <wsu2059@qq.com>, runoneall <runoobsteve@gmail.com>
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -18,7 +18,9 @@ Classifier: Operating System :: OS Independent
18
18
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
19
  Requires-Python: >=3.7
20
20
  Description-Content-Type: text/markdown
21
+ License-File: LICENSE
21
22
  Requires-Dist: aiohttp
23
+ Dynamic: license-file
22
24
 
23
25
  ![](./.github/assets/erispulse_logo.png)
24
26
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ErisPulse"
3
- version = "1.1.7"
3
+ version = "1.1.10"
4
4
  authors = [
5
5
  { name = "艾莉丝·格雷拉特(WSu2059)", email = "wsu2059@qq.com" },
6
6
  { name = "runoneall", email = "runoobsteve@gmail.com" }
File without changes
File without changes
File without changes
File without changes