ErisPulse-HelpModule 1.0.0__tar.gz → 2.0.0__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.
@@ -0,0 +1,213 @@
1
+ from ErisPulse import sdk
2
+ from ErisPulse.Core.Event import command
3
+ from ErisPulse.Core import config
4
+ from ErisPulse.Core.Bases import BaseModule
5
+ from typing import Dict, List
6
+
7
+ class HelpModule(BaseModule):
8
+ def __init__(self):
9
+ self.sdk = sdk
10
+ self.logger = sdk.logger.get_child("HelpModule")
11
+ self.command_list = []
12
+
13
+ @staticmethod
14
+ def should_eager_load():
15
+ return True
16
+
17
+ async def on_load(self, event):
18
+ self._register_commands()
19
+ self.logger.info("HelpModule 已加载")
20
+ return True
21
+
22
+ async def on_unload(self, event):
23
+ self._unregister_commands()
24
+ self.logger.info("HelpModule 已卸载")
25
+ return True
26
+
27
+ def _get_config(self):
28
+ module_config = config.getConfig("HelpModule")
29
+ if not module_config:
30
+ default_config = {
31
+ "show_hidden_commands": False,
32
+ "group_commands": True
33
+ }
34
+ config.setConfig("HelpModule", default_config)
35
+ self.logger.warning("未找到HelpModule配置,已创建默认配置")
36
+ return default_config
37
+ return module_config
38
+
39
+ def _get_command_prefix(self) -> str:
40
+ event_config = config.getConfig("ErisPulse.event", {})
41
+ command_config = event_config.get("command", {})
42
+ return command_config.get("prefix", "/")
43
+
44
+ def _register_commands(self):
45
+ self.help_command_func = self._create_help_command()
46
+ command(
47
+ "help",
48
+ aliases=["h", "帮助"],
49
+ help="显示帮助信息",
50
+ usage="help [序号] - 显示命令列表或查看指定序号的命令详情"
51
+ )(self.help_command_func)
52
+
53
+ def _unregister_commands(self):
54
+ if hasattr(self, 'help_command_func'):
55
+ command.unregister(self.help_command_func)
56
+
57
+ def _create_help_command(self):
58
+ async def help_command(event):
59
+ await self._handle_help_command(event)
60
+ return help_command
61
+
62
+ def _build_command_list(self) -> List[Dict]:
63
+ self.command_list = []
64
+ module_config = self._get_config()
65
+ show_hidden = module_config.get("show_hidden_commands", False)
66
+
67
+ if show_hidden:
68
+ all_commands = command.get_commands()
69
+ for cmd_name in all_commands:
70
+ cmd_info = command.get_command(cmd_name)
71
+ if cmd_info and cmd_name == cmd_info.get("main_name"):
72
+ self.command_list.append({
73
+ "name": cmd_name,
74
+ "info": cmd_info
75
+ })
76
+ else:
77
+ visible_commands = command.get_visible_commands()
78
+ for cmd_name in visible_commands:
79
+ cmd_info = command.get_command(cmd_name)
80
+ if cmd_info and cmd_name == cmd_info.get("main_name"):
81
+ self.command_list.append({
82
+ "name": cmd_name,
83
+ "info": cmd_info
84
+ })
85
+
86
+ return self.command_list
87
+
88
+ def _group_commands_by_category(self, commands: List[Dict]) -> Dict[str, List]:
89
+ grouped = {}
90
+ for cmd in commands:
91
+ group = cmd["info"].get("group") or "default"
92
+ if group not in grouped:
93
+ grouped[group] = []
94
+ grouped[group].append(cmd)
95
+ return grouped
96
+
97
+ async def _handle_help_command(self, event: Dict) -> None:
98
+ try:
99
+ platform = event["platform"]
100
+ if event.get("detail_type") == "group":
101
+ target_type = "group"
102
+ target_id = event["group_id"]
103
+ else:
104
+ target_type = "user"
105
+ target_id = event["user_id"]
106
+
107
+ args = event.get("command", {}).get("args", [])
108
+ adapter = getattr(sdk.adapter, platform)
109
+
110
+ commands = self._build_command_list()
111
+
112
+ if args:
113
+ try:
114
+ index = int(args[0]) - 1
115
+ if 0 <= index < len(commands):
116
+ help_text = self._format_command_detail(commands[index])
117
+ else:
118
+ help_text = f"错误: 序号超出范围,请输入 1-{len(commands)} 之间的序号"
119
+ except ValueError:
120
+ help_text = "错误: 请输入有效的序号"
121
+ else:
122
+ help_text = self._format_command_list(commands)
123
+
124
+ await adapter.Send.To(target_type, target_id).Text(help_text)
125
+ except Exception as e:
126
+ self.logger.error(f"处理帮助命令时出错: {e}")
127
+
128
+ def _format_command_list(self, commands: List[Dict]) -> str:
129
+ prefix = self._get_command_prefix()
130
+ module_config = self._get_config()
131
+
132
+ lines = [
133
+ "命令帮助",
134
+ "-" * 10,
135
+ f"使用 '{prefix}help <序号>' 查看命令详情",
136
+ ""
137
+ ]
138
+
139
+ if module_config.get("group_commands", True):
140
+ grouped = self._group_commands_by_category(commands)
141
+
142
+ # 默认组
143
+ if "default" in grouped:
144
+ lines.append("[通用命令]")
145
+ for idx, cmd in enumerate(grouped["default"], 1):
146
+ name = cmd["name"]
147
+ help_text = cmd["info"].get("help", "暂无描述")
148
+ lines.append(f"{idx}. {prefix}{name} - {help_text}")
149
+ lines.append("")
150
+
151
+ # 其他组
152
+ for group, cmds in grouped.items():
153
+ if group == "default":
154
+ continue
155
+ group_name = str(group) if group else "其他"
156
+ lines.append(f"[{group_name}命令]")
157
+ for idx, cmd in enumerate(cmds, 1):
158
+ name = cmd["name"]
159
+ help_text = cmd["info"].get("help", "暂无描述")
160
+ lines.append(f"{idx}. {prefix}{name} - {help_text}")
161
+ lines.append("")
162
+ else:
163
+ lines.append("[所有命令]")
164
+ for idx, cmd in enumerate(commands, 1):
165
+ name = cmd["name"]
166
+ help_text = cmd["info"].get("help", "暂无描述")
167
+ lines.append(f"{idx}. {prefix}{name} - {help_text}")
168
+ lines.append("")
169
+
170
+ lines.append("-" * 10)
171
+ lines.append(f"共 {len(commands)} 个可用命令")
172
+
173
+ return "\n".join(lines)
174
+
175
+ def _format_command_detail(self, cmd: Dict) -> str:
176
+ prefix = self._get_command_prefix()
177
+ name = cmd["name"]
178
+ info = cmd["info"]
179
+
180
+ lines = [
181
+ f"命令详情: {prefix}{name}",
182
+ "-" * 10,
183
+ f"描述: {info.get('help', '暂无描述')}"
184
+ ]
185
+
186
+ # 别名
187
+ aliases = []
188
+ for alias, main_name in command.aliases.items():
189
+ if main_name == info['main_name'] and alias != info['main_name']:
190
+ aliases.append(alias)
191
+
192
+ if aliases:
193
+ lines.append(f"别名: {', '.join(f'{prefix}{a}' for a in aliases)}")
194
+
195
+ # 用法
196
+ if info.get("usage"):
197
+ lines.append(f"用法: {info['usage'].replace('/', prefix)}")
198
+
199
+ # 权限
200
+ if info.get("permission"):
201
+ lines.append("权限: 需要特殊权限")
202
+
203
+ # 隐藏状态
204
+ if info.get("hidden"):
205
+ lines.append("状态: 隐藏命令")
206
+
207
+ # 分组
208
+ if info.get("group"):
209
+ lines.append(f"分组: {info['group']}")
210
+
211
+ lines.append("-" * 10)
212
+
213
+ return "\n".join(lines)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-HelpModule
3
- Version: 1.0.0
3
+ Version: 2.0.0
4
4
  Summary: ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查看所有可用命令及其用法说明
5
5
  Author-email: wsu2059q <wsu2059@qq.com>
6
6
  License: Copyright 2025 wsu2059q
@@ -11,7 +11,7 @@ License: Copyright 2025 wsu2059q
11
11
 
12
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
13
  Project-URL: homepage, https://github.com/wsu2059q/ErisPulse-HelpModule
14
- Requires-Python: >=3.9
14
+ Requires-Python: >=3.10
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
17
  Dynamic: license-file
@@ -22,10 +22,9 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
22
22
  ## 功能特性
23
23
  提供 Event 子模块中 command 模块中统一的命令帮助功能
24
24
  - 自动收集并显示所有已注册的命令
25
- - 支持查看特定命令的详细帮助信息
25
+ - 支持通过序号查看特定命令的详细帮助信息
26
26
  - 支持命令分组显示
27
27
  - 可配置是否显示隐藏命令
28
- - 提供简洁和详细两种显示样式
29
28
  - 支持命令别名显示
30
29
 
31
30
  ## 使用方法
@@ -33,8 +32,8 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
33
32
  ### 基本命令
34
33
 
35
34
  ```
36
- /help # 显示所有可用命令的简要帮助
37
- /help <命令名> # 显示指定命令的详细帮助信息
35
+ /help # 显示所有可用命令的列表
36
+ /help <序号> # 显示指定序号命令的详细帮助信息
38
37
  ```
39
38
 
40
39
  ### 命令别名
@@ -42,7 +41,6 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
42
41
  ```
43
42
  /h # 等同于 /help
44
43
  /帮助 # 等同于 /help
45
- /命令帮助 # 等同于 /help
46
44
  ```
47
45
 
48
46
  ## 配置选项
@@ -52,16 +50,12 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
52
50
  ```toml
53
51
  [HelpModule]
54
52
  show_hidden_commands = false # 是否显示隐藏命令
55
- style = "simple" # 显示样式: "simple" 或 "detailed"
56
53
  group_commands = true # 是否按组显示命令
57
54
  ```
58
55
 
59
56
  ### 配置说明
60
57
 
61
58
  - `show_hidden_commands`: 设置为 `true` 时,帮助命令会显示被标记为隐藏的命令
62
- - `style`:
63
- - `"simple"`: 简洁显示模式,只显示命令名称和简要描述
64
- - `"detailed"`: 详细显示模式,显示命令的更多详细信息
65
59
  - `group_commands`: 设置为 `false` 时,不按组显示命令,所有命令将在同一列表中显示
66
60
 
67
61
  ## 依赖
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-HelpModule
3
- Version: 1.0.0
3
+ Version: 2.0.0
4
4
  Summary: ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查看所有可用命令及其用法说明
5
5
  Author-email: wsu2059q <wsu2059@qq.com>
6
6
  License: Copyright 2025 wsu2059q
@@ -11,7 +11,7 @@ License: Copyright 2025 wsu2059q
11
11
 
12
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
13
  Project-URL: homepage, https://github.com/wsu2059q/ErisPulse-HelpModule
14
- Requires-Python: >=3.9
14
+ Requires-Python: >=3.10
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
17
  Dynamic: license-file
@@ -22,10 +22,9 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
22
22
  ## 功能特性
23
23
  提供 Event 子模块中 command 模块中统一的命令帮助功能
24
24
  - 自动收集并显示所有已注册的命令
25
- - 支持查看特定命令的详细帮助信息
25
+ - 支持通过序号查看特定命令的详细帮助信息
26
26
  - 支持命令分组显示
27
27
  - 可配置是否显示隐藏命令
28
- - 提供简洁和详细两种显示样式
29
28
  - 支持命令别名显示
30
29
 
31
30
  ## 使用方法
@@ -33,8 +32,8 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
33
32
  ### 基本命令
34
33
 
35
34
  ```
36
- /help # 显示所有可用命令的简要帮助
37
- /help <命令名> # 显示指定命令的详细帮助信息
35
+ /help # 显示所有可用命令的列表
36
+ /help <序号> # 显示指定序号命令的详细帮助信息
38
37
  ```
39
38
 
40
39
  ### 命令别名
@@ -42,7 +41,6 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
42
41
  ```
43
42
  /h # 等同于 /help
44
43
  /帮助 # 等同于 /help
45
- /命令帮助 # 等同于 /help
46
44
  ```
47
45
 
48
46
  ## 配置选项
@@ -52,16 +50,12 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
52
50
  ```toml
53
51
  [HelpModule]
54
52
  show_hidden_commands = false # 是否显示隐藏命令
55
- style = "simple" # 显示样式: "simple" 或 "detailed"
56
53
  group_commands = true # 是否按组显示命令
57
54
  ```
58
55
 
59
56
  ### 配置说明
60
57
 
61
58
  - `show_hidden_commands`: 设置为 `true` 时,帮助命令会显示被标记为隐藏的命令
62
- - `style`:
63
- - `"simple"`: 简洁显示模式,只显示命令名称和简要描述
64
- - `"detailed"`: 详细显示模式,显示命令的更多详细信息
65
59
  - `group_commands`: 设置为 `false` 时,不按组显示命令,所有命令将在同一列表中显示
66
60
 
67
61
  ## 依赖
@@ -4,10 +4,9 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
4
4
  ## 功能特性
5
5
  提供 Event 子模块中 command 模块中统一的命令帮助功能
6
6
  - 自动收集并显示所有已注册的命令
7
- - 支持查看特定命令的详细帮助信息
7
+ - 支持通过序号查看特定命令的详细帮助信息
8
8
  - 支持命令分组显示
9
9
  - 可配置是否显示隐藏命令
10
- - 提供简洁和详细两种显示样式
11
10
  - 支持命令别名显示
12
11
 
13
12
  ## 使用方法
@@ -15,8 +14,8 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
15
14
  ### 基本命令
16
15
 
17
16
  ```
18
- /help # 显示所有可用命令的简要帮助
19
- /help <命令名> # 显示指定命令的详细帮助信息
17
+ /help # 显示所有可用命令的列表
18
+ /help <序号> # 显示指定序号命令的详细帮助信息
20
19
  ```
21
20
 
22
21
  ### 命令别名
@@ -24,7 +23,6 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
24
23
  ```
25
24
  /h # 等同于 /help
26
25
  /帮助 # 等同于 /help
27
- /命令帮助 # 等同于 /help
28
26
  ```
29
27
 
30
28
  ## 配置选项
@@ -34,16 +32,12 @@ ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查
34
32
  ```toml
35
33
  [HelpModule]
36
34
  show_hidden_commands = false # 是否显示隐藏命令
37
- style = "simple" # 显示样式: "simple" 或 "detailed"
38
35
  group_commands = true # 是否按组显示命令
39
36
  ```
40
37
 
41
38
  ### 配置说明
42
39
 
43
40
  - `show_hidden_commands`: 设置为 `true` 时,帮助命令会显示被标记为隐藏的命令
44
- - `style`:
45
- - `"simple"`: 简洁显示模式,只显示命令名称和简要描述
46
- - `"detailed"`: 详细显示模式,显示命令的更多详细信息
47
41
  - `group_commands`: 设置为 `false` 时,不按组显示命令,所有命令将在同一列表中显示
48
42
 
49
43
  ## 依赖
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "ErisPulse-HelpModule"
3
- version = "1.0.0"
3
+ version = "2.0.0"
4
4
  description = "ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查看所有可用命令及其用法说明"
5
5
  readme = "README.md"
6
- requires-python = ">=3.9"
6
+ requires-python = ">=3.10"
7
7
  license = { file = "LICENSE" }
8
8
  authors = [ { name = "wsu2059q", email = "wsu2059@qq.com" } ]
9
9
 
@@ -1,316 +0,0 @@
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)