ErisPulse 1.1.8__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.
@@ -47,7 +47,7 @@ class BaseAdapter:
47
47
  # 绑定当前适配器的 Send 实例
48
48
  self.Send = self.__class__.Send(self)
49
49
 
50
- def on(self, event_type: str):
50
+ def on(self, event_type: str = "*"):
51
51
  def decorator(func: Callable):
52
52
  @functools.wraps(func)
53
53
  async def wrapper(*args, **kwargs):
@@ -69,11 +69,32 @@ class BaseAdapter:
69
69
  async def shutdown(self):
70
70
  raise NotImplementedError
71
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)
72
86
  async def emit(self, event_type: str, data: Any):
87
+ # 先执行中间件
73
88
  for middleware in self._middlewares:
74
89
  data = await middleware(data)
75
90
 
76
- 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("*", []):
77
98
  await handler(data)
78
99
 
79
100
  async def send(self, target_type: str, target_id: str, message: Any, **kwargs):
@@ -107,6 +128,17 @@ class AdapterManager:
107
128
  self._adapters[platform] = instance
108
129
  self._platform_to_instance[platform] = instance
109
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
+
110
142
  return True
111
143
 
112
144
  async def startup(self, platforms: List[str] = None):
@@ -166,12 +198,18 @@ class AdapterManager:
166
198
  await adapter.shutdown()
167
199
 
168
200
  def get(self, platform: str) -> BaseAdapter:
169
- 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
170
206
 
171
207
  def __getattr__(self, platform: str) -> BaseAdapter:
172
- if platform not in self._adapters:
173
- raise AttributeError(f"平台 {platform} 的适配器未注册")
174
- 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} 的适配器未注册")
175
213
 
176
214
  @property
177
215
  def platforms(self) -> list:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse
3
- Version: 1.1.8
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.8
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.8"
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
File without changes