ErisPulse-HelpModule 1.0.0__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.
@@ -0,0 +1,316 @@
1
+ from ErisPulse import sdk
2
+ from ErisPulse.Core.Event import command, message
3
+ from ErisPulse.Core import config
4
+ from typing import Dict, List, Optional
5
+
6
+ class HelpModule:
7
+ def __init__(self):
8
+ self.sdk = sdk
9
+ self.logger = sdk.logger.get_child("HelpModule")
10
+ self._register_commands()
11
+
12
+ @staticmethod
13
+ def should_eager_load():
14
+ return True
15
+
16
+ def _get_config(self):
17
+ """获取模块配置,如果不存在则创建默认配置"""
18
+ module_config = config.getConfig("HelpModule")
19
+ if not module_config:
20
+ default_config = {
21
+ "show_hidden_commands": False,
22
+ "style": "simple",
23
+ "group_commands": True
24
+ }
25
+ config.setConfig("HelpModule", default_config)
26
+ self.logger.warning("未找到HelpModule配置,已创建默认配置")
27
+ return default_config
28
+ return module_config
29
+
30
+ def _get_command_prefix(self) -> str:
31
+ event_config = config.getConfig("ErisPulse.event", {})
32
+ command_config = event_config.get("command", {})
33
+ return command_config.get("prefix", "/")
34
+
35
+ def _register_commands(self):
36
+ prefix = self._get_command_prefix()
37
+
38
+ @command(
39
+ "help",
40
+ aliases=["h", "帮助", "命令帮助"],
41
+ help="显示帮助信息",
42
+ usage="help [命令名] - 显示所有命令或指定命令的详细信息"
43
+ )
44
+ async def help_command(event):
45
+ await self._handle_help_command(event)
46
+
47
+ async def _handle_help_command(self, event: Dict) -> None:
48
+ try:
49
+ platform = event["platform"]
50
+ if event.get("detail_type") == "group":
51
+ target_type = "group"
52
+ target_id = event["group_id"]
53
+ else:
54
+ target_type = "user"
55
+ target_id = event["user_id"]
56
+
57
+ # 获取命令参数
58
+ args = event.get("command", {}).get("args", [])
59
+
60
+ # 获取适配器实例
61
+ adapter = getattr(sdk.adapter, platform)
62
+
63
+ if args:
64
+ # 查看特定命令的详细帮助
65
+ cmd_name = args[0].lower()
66
+ help_text = self._get_command_detail(cmd_name)
67
+ else:
68
+ # 显示所有命令的简要帮助
69
+ # 根据配置决定是否显示隐藏命令
70
+ module_config = self._get_config()
71
+ show_hidden = module_config.get("show_hidden_commands", False)
72
+
73
+ if show_hidden:
74
+ # 显示所有命令(包括隐藏命令)
75
+ commands_info = {}
76
+ all_commands = command.get_commands()
77
+ for cmd_name in all_commands:
78
+ # 只获取主命令,避免重复显示别名
79
+ cmd_info = command.get_command(cmd_name)
80
+ if cmd_info and cmd_name == cmd_info.get("main_name"):
81
+ commands_info[cmd_name] = cmd_info
82
+ else:
83
+ # 只显示可见命令
84
+ commands_info = {}
85
+ visible_commands = command.get_visible_commands()
86
+ for cmd_name in visible_commands:
87
+ cmd_info = command.get_command(cmd_name)
88
+ if cmd_info:
89
+ commands_info[cmd_name] = cmd_info
90
+
91
+ help_text = self._format_help_text(commands_info, show_hidden)
92
+
93
+ # 发送帮助信息
94
+ await adapter.Send.To(target_type, target_id).Text(help_text)
95
+ except Exception as e:
96
+ self.logger.error(f"处理帮助命令时出错: {e}")
97
+ if 'adapter' in locals():
98
+ error_msg = "处理帮助命令时发生错误,请稍后再试"
99
+ await adapter.Send.To(target_type, target_id).Text(error_msg)
100
+
101
+ def _format_help_text(self, commands_info: Dict[str, Dict], show_hidden: bool = False) -> str:
102
+ prefix = self._get_command_prefix()
103
+ module_config = self._get_config()
104
+ style = module_config.get("style", "simple")
105
+
106
+ if style == "detailed":
107
+ return self._format_detailed_help_text(commands_info, show_hidden)
108
+ else:
109
+ return self._format_simple_help_text(commands_info, show_hidden)
110
+
111
+ def _format_simple_help_text(self, commands_info: Dict[str, Dict], show_hidden: bool = False) -> str:
112
+ prefix = self._get_command_prefix()
113
+ module_config = self._get_config()
114
+
115
+ help_lines = [
116
+ "=" * 50,
117
+ "命令帮助",
118
+ "=" * 50,
119
+ ]
120
+
121
+ if show_hidden:
122
+ help_lines.append("[注意] 当前显示所有命令(包括隐藏命令)")
123
+
124
+ help_lines.append(f"使用 '{prefix}help <命令名>' 查看具体命令的详细用法")
125
+ help_lines.append("")
126
+
127
+ # 根据配置决定是否按组显示命令
128
+ if module_config.get("group_commands", True):
129
+ # 按命令组分组
130
+ grouped_commands = self._group_commands_by_category(commands_info)
131
+
132
+ # 添加默认组的命令
133
+ if "default" in grouped_commands:
134
+ help_lines.append("[通用命令]")
135
+ for cmd_name, cmd_info in grouped_commands["default"]:
136
+ help_lines.append(self._format_command_brief(cmd_name, cmd_info, prefix))
137
+ help_lines.append("")
138
+
139
+ # 添加其他组的命令
140
+ for group, cmds in grouped_commands.items():
141
+ if group == "default":
142
+ continue
143
+ # 安全处理组名
144
+ group_name = str(group) if group else "其他"
145
+ help_lines.append(f"[{group_name}命令]")
146
+ for cmd_name, cmd_info in cmds:
147
+ help_lines.append(self._format_command_brief(cmd_name, cmd_info, prefix))
148
+ help_lines.append("")
149
+ else:
150
+ # 不分组显示所有命令
151
+ help_lines.append("[所有命令]")
152
+ for cmd_name, cmd_info in commands_info.items():
153
+ help_lines.append(self._format_command_brief(cmd_name, cmd_info, prefix))
154
+ help_lines.append("")
155
+
156
+ # 添加页脚信息
157
+ help_lines.append("-" * 50)
158
+ help_lines.append(f"共 {len(commands_info)} 个可用命令")
159
+ help_lines.append("=" * 50)
160
+
161
+ return "\n".join(help_lines)
162
+
163
+ def _format_detailed_help_text(self, commands_info: Dict[str, Dict], show_hidden: bool = False) -> str:
164
+ prefix = self._get_command_prefix()
165
+ module_config = self._get_config()
166
+
167
+ help_lines = [
168
+ "=" * 50,
169
+ "命令帮助",
170
+ "=" * 50,
171
+ ]
172
+
173
+ if show_hidden:
174
+ help_lines.append("[注意] 当前显示所有命令(包括隐藏命令)")
175
+
176
+ help_lines.append(f"使用 '{prefix}help <命令名>' 查看具体命令的详细用法")
177
+ help_lines.append("")
178
+
179
+ # 根据配置决定是否按组显示命令
180
+ if module_config.get("group_commands", True):
181
+ # 按命令组分组
182
+ grouped_commands = self._group_commands_by_category(commands_info)
183
+
184
+ # 添加默认组的命令
185
+ if "default" in grouped_commands:
186
+ help_lines.append("[通用命令]")
187
+ for cmd_name, cmd_info in grouped_commands["default"]:
188
+ help_lines.append(self._format_command_detailed(cmd_name, cmd_info, prefix))
189
+ help_lines.append("")
190
+
191
+ # 添加其他组的命令
192
+ for group, cmds in grouped_commands.items():
193
+ if group == "default":
194
+ continue
195
+ # 安全处理组名
196
+ group_name = str(group) if group else "其他"
197
+ help_lines.append(f"[{group_name}命令]")
198
+ for cmd_name, cmd_info in cmds:
199
+ help_lines.append(self._format_command_detailed(cmd_name, cmd_info, prefix))
200
+ help_lines.append("")
201
+ else:
202
+ # 不分组显示所有命令
203
+ help_lines.append("[所有命令]")
204
+ for cmd_name, cmd_info in commands_info.items():
205
+ help_lines.append(self._format_command_detailed(cmd_name, cmd_info, prefix))
206
+ help_lines.append("")
207
+
208
+ # 添加页脚信息
209
+ help_lines.append("-" * 50)
210
+ help_lines.append(f"共 {len(commands_info)} 个可用命令")
211
+ help_lines.append("=" * 50)
212
+
213
+ return "\n".join(help_lines)
214
+
215
+ def _group_commands_by_category(self, commands_info: Dict[str, Dict]) -> Dict[str, List]:
216
+ grouped_commands = {}
217
+ for cmd_name, cmd_info in commands_info.items():
218
+ group = cmd_info.get("group")
219
+ group = "default" if group is None else group
220
+ if group not in grouped_commands:
221
+ grouped_commands[group] = []
222
+ grouped_commands[group].append((cmd_name, cmd_info))
223
+ return grouped_commands
224
+
225
+ def _format_command_brief(self, cmd_name: str, cmd_info: Dict, prefix: str) -> str:
226
+ # 主命令名
227
+ formatted = f" {prefix}{cmd_name}"
228
+
229
+ # 帮助文本
230
+ help_text = cmd_info.get("help", "暂无描述")
231
+ formatted += f" - {help_text}"
232
+
233
+ return formatted
234
+
235
+ def _format_command_detailed(self, cmd_name: str, cmd_info: Dict, prefix: str) -> str:
236
+ # 主命令名
237
+ formatted = f" {prefix}{cmd_name}"
238
+
239
+ # 帮助文本
240
+ help_text = cmd_info.get("help", "暂无描述")
241
+ formatted += f"\n 描述: {help_text}"
242
+
243
+ # 别名信息
244
+ aliases = []
245
+ for alias, main_name in command.aliases.items():
246
+ if main_name == cmd_info['main_name'] and alias != cmd_info['main_name']:
247
+ aliases.append(alias)
248
+
249
+ if aliases:
250
+ formatted += f"\n 别名: {', '.join(f'{prefix}{a}' for a in aliases)}"
251
+
252
+ # 使用示例
253
+ if cmd_info.get("usage"):
254
+ usage = cmd_info['usage'].replace("/", prefix)
255
+ formatted += f"\n 用法: {usage}"
256
+
257
+ # 权限信息
258
+ if cmd_info.get("permission"):
259
+ formatted += f"\n 权限: 需要特殊权限"
260
+
261
+ # 隐藏状态
262
+ if cmd_info.get("hidden"):
263
+ formatted += f"\n 状态: 隐藏命令"
264
+
265
+ return formatted
266
+
267
+ def _get_command_detail(self, cmd_name: str) -> str:
268
+ prefix = self._get_command_prefix()
269
+
270
+ # 查找命令(支持别名) 使用安全访问方式
271
+ cmd_info = command.get_command(cmd_name)
272
+
273
+ if not cmd_info:
274
+ return f"错误: 未找到命令 '{cmd_name}'"
275
+
276
+ # 构建详细帮助
277
+ lines = [
278
+ "=" * 50,
279
+ f"命令详情: {prefix}{cmd_info['main_name']}",
280
+ "=" * 50,
281
+ f"描述: {cmd_info.get('help', '暂无描述')}"
282
+ ]
283
+
284
+ # 别名信息
285
+ aliases = []
286
+ for alias, main_name in command.aliases.items():
287
+ if main_name == cmd_info['main_name'] and alias != cmd_info['main_name']:
288
+ aliases.append(alias)
289
+
290
+ if aliases:
291
+ lines.append(f"别名: {', '.join(f'{prefix}{a}' for a in aliases)}")
292
+
293
+ # 使用示例
294
+ if cmd_info.get("usage"):
295
+ lines.append("")
296
+ lines.append("使用示例:")
297
+ usage = cmd_info['usage'].replace("/", prefix)
298
+ lines.append(f" {usage}")
299
+
300
+ # 权限信息
301
+ if cmd_info.get("permission"):
302
+ lines.append("")
303
+ lines.append("权限: 需要特殊权限才能使用此命令")
304
+
305
+ # 隐藏状态
306
+ if cmd_info.get("hidden"):
307
+ lines.append("")
308
+ lines.append("注意: 这是一个隐藏命令,不会在常规帮助中显示")
309
+
310
+ # 显示命令组信息
311
+ if cmd_info.get("group"):
312
+ lines.append("")
313
+ lines.append(f"分组: {cmd_info['group']}")
314
+
315
+ lines.append("=" * 50)
316
+ return "\n".join(lines)
@@ -0,0 +1 @@
1
+ from .Core import HelpModule
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: ErisPulse-HelpModule
3
+ Version: 1.0.0
4
+ Summary: ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查看所有可用命令及其用法说明
5
+ Author-email: wsu2059q <wsu2059@qq.com>
6
+ License: Copyright 2025 wsu2059q
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ Project-URL: homepage, https://github.com/wsu2059q/ErisPulse-HelpModule
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: license-file
18
+
19
+ # ErisPulse-HelpModule
20
+ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查看所有可用命令及其用法说明
21
+
22
+ ## 功能特性
23
+ 提供 Event 子模块中 command 模块中统一的命令帮助功能
24
+ - 自动收集并显示所有已注册的命令
25
+ - 支持查看特定命令的详细帮助信息
26
+ - 支持命令分组显示
27
+ - 可配置是否显示隐藏命令
28
+ - 提供简洁和详细两种显示样式
29
+ - 支持命令别名显示
30
+
31
+ ## 使用方法
32
+
33
+ ### 基本命令
34
+
35
+ ```
36
+ /help # 显示所有可用命令的简要帮助
37
+ /help <命令名> # 显示指定命令的详细帮助信息
38
+ ```
39
+
40
+ ### 命令别名
41
+
42
+ ```
43
+ /h # 等同于 /help
44
+ /帮助 # 等同于 /help
45
+ /命令帮助 # 等同于 /help
46
+ ```
47
+
48
+ ## 配置选项
49
+
50
+ 模块支持以下配置选项,可以在 config.toml 中进行自定义:
51
+
52
+ ```toml
53
+ [HelpModule]
54
+ show_hidden_commands = false # 是否显示隐藏命令
55
+ style = "simple" # 显示样式: "simple" 或 "detailed"
56
+ group_commands = true # 是否按组显示命令
57
+ ```
58
+
59
+ ### 配置说明
60
+
61
+ - `show_hidden_commands`: 设置为 `true` 时,帮助命令会显示被标记为隐藏的命令
62
+ - `style`:
63
+ - `"simple"`: 简洁显示模式,只显示命令名称和简要描述
64
+ - `"detailed"`: 详细显示模式,显示命令的更多详细信息
65
+ - `group_commands`: 设置为 `false` 时,不按组显示命令,所有命令将在同一列表中显示
66
+
67
+ ## 依赖
68
+
69
+ - ErisPulse SDK 2.2.0+
@@ -0,0 +1,8 @@
1
+ ErisPulse_HelpModule/Core.py,sha256=3huphEXBRevvANY9IWBlJifGKf8m1wqO6eD-yai2IoY,12542
2
+ ErisPulse_HelpModule/__init__.py,sha256=ybEvf416FykwVwiKcGdeQZvrsHWkLkMAlNjqZbhY38k,28
3
+ erispulse_helpmodule-1.0.0.dist-info/licenses/LICENSE,sha256=7BKmRD_5YpTGfc12w9L3TIskHF3A_AWDU4xuDQKE92w,1055
4
+ erispulse_helpmodule-1.0.0.dist-info/METADATA,sha256=Ec_pMKNIC8TWJa4qKmkBsZ6OKTZcQD5X0FkKJ7drUq0,3009
5
+ erispulse_helpmodule-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ erispulse_helpmodule-1.0.0.dist-info/entry_points.txt,sha256=EBPR47ANi5DAbba7E2r558vfeD2AeR7lYXSt2_NNCwY,64
7
+ erispulse_helpmodule-1.0.0.dist-info/top_level.txt,sha256=BFgAL-qs-KTqA4wuD6XaQhQzPZOmJ0IOqK9vq7Kqdos,21
8
+ erispulse_helpmodule-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [erispulse.module]
2
+ HelpModule = ErisPulse_HelpModule:HelpModule
@@ -0,0 +1,7 @@
1
+ Copyright 2025 wsu2059q
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ ErisPulse_HelpModule