ErisPulse-HelpModule 2.1.0__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.
@@ -1,26 +1,29 @@
1
+ from typing import Dict, List, Optional
2
+
1
3
  from ErisPulse import sdk
2
- from ErisPulse.Core.Event import command
3
4
  from ErisPulse.Core import config
4
5
  from ErisPulse.Core.Bases import BaseModule
5
- from typing import Dict, List, Optional
6
+ from ErisPulse.Core.Event import command
7
+
6
8
  from .templates import HelpTemplates
7
9
 
10
+
8
11
  class HelpModule(BaseModule):
9
12
  def __init__(self):
10
13
  self.sdk = sdk
11
14
  self.logger = sdk.logger.get_child("HelpModule")
12
15
  self.command_list = []
13
16
  self.command_map = {}
14
-
17
+
15
18
  @staticmethod
16
19
  def should_eager_load():
17
20
  return True
18
-
21
+
19
22
  async def on_load(self, event):
20
23
  self._register_commands()
21
24
  self.logger.info("HelpModule 已加载")
22
25
  return True
23
-
26
+
24
27
  async def on_unload(self, event):
25
28
  self._unregister_commands()
26
29
  self.logger.info("HelpModule 已卸载")
@@ -29,62 +32,63 @@ class HelpModule(BaseModule):
29
32
  def _get_config(self):
30
33
  module_config = config.getConfig("HelpModule")
31
34
  if not module_config:
32
- default_config = {
33
- "show_hidden_commands": False,
34
- "group_commands": True
35
- }
35
+ default_config = {"show_hidden_commands": False, "group_commands": True}
36
36
  config.setConfig("HelpModule", default_config)
37
37
  self.logger.warning("未找到HelpModule配置,已创建默认配置")
38
38
  return default_config
39
39
  return module_config
40
-
41
- def _get_command_prefix(self) -> str:
40
+
41
+ def _get_all_prefixes(self) -> list:
42
+ """获取所有命令前缀列表"""
42
43
  event_config = config.getConfig("ErisPulse.event", {})
43
44
  command_config = event_config.get("command", {})
44
- return command_config.get("prefix", "/")
45
-
45
+ prefix = command_config.get("prefix", "/")
46
+ if isinstance(prefix, list):
47
+ return [str(p) for p in prefix] if prefix else ["/"]
48
+ return [str(prefix)]
49
+
50
+ def _get_command_prefix(self) -> str:
51
+ """获取主显示前缀(第一个)"""
52
+ prefixes = self._get_all_prefixes()
53
+ return prefixes[0] if prefixes else "/"
54
+
46
55
  def _register_commands(self):
47
56
  self.help_command_func = self._create_help_command()
48
57
  command(
49
- "help",
50
- aliases=["h", "帮助"],
58
+ "help",
59
+ aliases=["h", "帮助"],
51
60
  help="显示帮助信息",
52
- usage="help [序号] - 显示命令列表或查看指定序号的命令详情"
61
+ usage="help [序号] - 显示命令列表或查看指定序号的命令详情",
53
62
  )(self.help_command_func)
54
63
 
55
64
  def _unregister_commands(self):
56
- if hasattr(self, 'help_command_func'):
65
+ if hasattr(self, "help_command_func"):
57
66
  command.unregister(self.help_command_func)
58
-
67
+
59
68
  def _create_help_command(self):
60
69
  async def help_command(event):
61
70
  await self._handle_help_command(event)
71
+
62
72
  return help_command
63
73
 
64
74
  def _build_command_list(self) -> List[Dict]:
65
75
  self.command_list = []
66
76
  module_config = self._get_config()
67
77
  show_hidden = module_config.get("show_hidden_commands", False)
68
-
78
+
69
79
  if show_hidden:
70
80
  all_commands = command.get_commands()
71
81
  for cmd_name in all_commands:
72
82
  cmd_info = command.get_command(cmd_name)
73
83
  if cmd_info and cmd_name == cmd_info.get("main_name"):
74
- self.command_list.append({
75
- "name": cmd_name,
76
- "info": cmd_info
77
- })
84
+ self.command_list.append({"name": cmd_name, "info": cmd_info})
78
85
  else:
79
86
  visible_commands = command.get_visible_commands()
80
87
  for cmd_name in visible_commands:
81
88
  cmd_info = command.get_command(cmd_name)
82
89
  if cmd_info and cmd_name == cmd_info.get("main_name"):
83
- self.command_list.append({
84
- "name": cmd_name,
85
- "info": cmd_info
86
- })
87
-
90
+ self.command_list.append({"name": cmd_name, "info": cmd_info})
91
+
88
92
  return self.command_list
89
93
 
90
94
  def _group_commands_by_category(self, commands: List[Dict]) -> Dict[str, List]:
@@ -96,25 +100,16 @@ class HelpModule(BaseModule):
96
100
  grouped[group].append(cmd)
97
101
  return grouped
98
102
 
99
- async def _handle_help_command(self, event: Dict) -> None:
103
+ async def _handle_help_command(self, event) -> None:
100
104
  try:
101
- platform = event["platform"]
102
- if event.get("detail_type") == "group":
103
- target_type = "group"
104
- target_id = event["group_id"]
105
- elif event.get("detail_type") == "private" or event.get("detail_type") == "user":
106
- target_type = "user"
107
- target_id = event["user_id"]
108
- else:
109
- target_type = event.get("detail_type")
110
- target_id = event.get("target_id")
111
-
112
- args = event.get("command", {}).get("args", [])
113
- adapter = getattr(sdk.adapter, platform)
114
-
105
+ platform = event.get_platform()
106
+ args = event.get_command_args()
107
+
115
108
  commands = self._build_command_list()
116
109
  module_config = self._get_config()
117
-
110
+
111
+ prefixes = self._get_all_prefixes()
112
+
118
113
  if args:
119
114
  # 显示命令详情
120
115
  try:
@@ -123,48 +118,46 @@ class HelpModule(BaseModule):
123
118
  # 使用模板构建命令详情
124
119
  templates = HelpTemplates.build_command_detail(
125
120
  self.command_map[index],
126
- self._get_command_prefix()
121
+ self._get_command_prefix(),
122
+ prefixes,
127
123
  )
128
- help_content = self._select_best_format(platform, templates)
129
124
  else:
130
125
  # 使用错误模板
131
126
  templates = HelpTemplates.build_error(
132
- "序号超出范围",
133
- f"请输入 1-{len(commands)} 之间的序号"
127
+ "序号超出范围", f"请输入 1-{len(commands)} 之间的序号"
134
128
  )
135
- help_content = self._select_best_format(platform, templates)
136
129
  except ValueError:
137
130
  templates = HelpTemplates.build_error(
138
- "参数错误",
139
- "请输入有效的序号"
131
+ "参数错误", "请输入有效的序号"
140
132
  )
141
- help_content = self._select_best_format(platform, templates)
142
133
  else:
143
134
  # 显示命令列表
144
135
  templates = HelpTemplates.build_help_list(
145
136
  commands,
146
137
  self.command_map,
147
138
  self._get_command_prefix(),
148
- module_config.get("group_commands", True)
139
+ module_config.get("group_commands", True),
140
+ prefixes,
149
141
  )
150
- help_content = self._select_best_format(platform, templates)
151
-
152
- # 发送消息
153
- await self._send_with_format(adapter, target_type, target_id, help_content)
142
+
143
+ # 根据平台能力选择最佳格式,通过 event.reply 发送
144
+ # event.reply 内部自动解析会话类型(含 channel/guild/thread 等)
145
+ format_name, content = self._select_best_format(platform, templates)
146
+ await event.reply(content, method=format_name)
154
147
  except Exception as e:
155
148
  self.logger.error(f"处理帮助命令时出错: {e}", exc_info=True)
156
-
149
+
157
150
  def _select_best_format(self, platform: str, templates: Dict[str, str]) -> tuple:
158
151
  """
159
152
  根据平台支持的发送方法选择最佳格式
160
153
  优先使用 list_sends,不支持时使用 hasattr 兜底
161
-
154
+
162
155
  返回: (format_name, content)
163
156
  """
164
157
  # 首先尝试使用 list_sends(推荐方式)
165
158
  try:
166
159
  supported_methods = sdk.adapter.list_sends(platform)
167
-
160
+
168
161
  # 优先级: Html > Markdown > Text
169
162
  if "Html" in supported_methods:
170
163
  return ("Html", templates["html"])
@@ -174,15 +167,15 @@ class HelpModule(BaseModule):
174
167
  return ("Text", templates["text"])
175
168
  except Exception as e:
176
169
  self.logger.warning(f"list_sends 检测失败: {e},尝试使用 hasattr 兜底")
177
-
170
+
178
171
  # 使用 hasattr 作为兜底方案
179
172
  adapter = getattr(sdk.adapter, platform)
180
173
  send_obj = adapter.Send if hasattr(adapter, "Send") else None
181
-
174
+
182
175
  if send_obj is None:
183
176
  self.logger.warning(f"平台 {platform} 不支持 Send 接口,使用纯文本格式")
184
177
  return ("Text", templates["text"])
185
-
178
+
186
179
  # 检查支持的方法
187
180
  if hasattr(send_obj, "Html"):
188
181
  return ("Html", templates["html"])
@@ -190,15 +183,3 @@ class HelpModule(BaseModule):
190
183
  return ("Markdown", templates["markdown"])
191
184
  else:
192
185
  return ("Text", templates["text"])
193
-
194
- async def _send_with_format(self, adapter, target_type: str, target_id: str,
195
- format_content: tuple) -> None:
196
- format_name, content = format_content
197
-
198
- # 根据格式调用对应的发送方法
199
- if format_name == "Html":
200
- await adapter.Send.To(target_type, target_id).Html(content)
201
- elif format_name == "Markdown":
202
- await adapter.Send.To(target_type, target_id).Markdown(content)
203
- else: # Text
204
- await adapter.Send.To(target_type, target_id).Text(content)
@@ -2,50 +2,95 @@
2
2
  帮助模块模板系统
3
3
  提供多平台支持的消息模板
4
4
  """
5
+
5
6
  from typing import Dict, List, Optional
7
+
6
8
  from ErisPulse.Core.Event import command
7
9
 
8
10
 
9
11
  class HelpTemplates:
10
12
  """帮助模块模板类"""
11
-
13
+
12
14
  # 配色方案
13
15
  PRIMARY_COLOR = "#1565c0" # 蓝色 - 主标题
14
16
  SUCCESS_COLOR = "#2e7d32" # 绿色 - 成功信息
15
17
  WARNING_COLOR = "#e65100" # 橙色 - 警告信息
16
- ERROR_COLOR = "#b71c1c" # 红色 - 错误信息
17
-
18
+ ERROR_COLOR = "#b71c1c" # 红色 - 错误信息
19
+
18
20
  # 半透明背景色
19
21
  PRIMARY_BG = "rgba(21, 101, 192, 0.05)"
20
22
  SUCCESS_BG = "rgba(76, 175, 80, 0.1)"
21
23
  WARNING_BG = "rgba(255, 167, 38, 0.15)"
22
24
  ERROR_BG = "rgba(183, 28, 28, 0.1)"
23
-
25
+
24
26
  @classmethod
25
27
  def _get_group_name(cls, group: str) -> str:
26
28
  if group == "default":
27
29
  return "通用命令"
28
30
  return f"{group}命令" if group else "其他"
29
-
31
+
32
+ @classmethod
33
+ def _other_prefixes(cls, prefixes: list, display_prefix: str) -> list:
34
+ """获取除主前缀外的其他前缀"""
35
+ if not prefixes or len(prefixes) <= 1:
36
+ return []
37
+ return [p for p in prefixes if p != display_prefix]
38
+
39
+ @classmethod
40
+ def _prefix_note_html(cls, other_prefixes: list) -> str:
41
+ if not other_prefixes:
42
+ return ""
43
+ note = "、".join(
44
+ f"<code style='font-size:11px;'>{p}</code>" for p in other_prefixes
45
+ )
46
+ return f'<div style="font-size: 11px; color: #999; margin-top: 4px;">其他触发前缀: {note}</div>'
47
+
48
+ @classmethod
49
+ def _prefix_note_text(cls, other_prefixes: list) -> str:
50
+ if not other_prefixes:
51
+ return ""
52
+ note = "、".join(other_prefixes)
53
+ return f"\n其他触发前缀: {note}"
54
+
30
55
  # ==================== 帮助列表模板 ====================
31
-
56
+
32
57
  @classmethod
33
- def build_help_list(cls, commands: List[Dict], command_map: Dict[int, Dict],
34
- prefix: str, group_commands: bool = True) -> Dict[str, str]:
58
+ def build_help_list(
59
+ cls,
60
+ commands: List[Dict],
61
+ command_map: Dict[int, Dict],
62
+ prefix: str,
63
+ group_commands: bool = True,
64
+ prefixes: Optional[list] = None,
65
+ ) -> Dict[str, str]:
66
+ other_prefixes = cls._other_prefixes(prefixes or [prefix], prefix)
67
+
35
68
  # 构建 HTML
36
- html = cls._build_help_list_html(commands, command_map, prefix, group_commands)
37
-
69
+ html = cls._build_help_list_html(
70
+ commands, command_map, prefix, group_commands, other_prefixes
71
+ )
72
+
38
73
  # 构建 Markdown
39
- markdown = cls._build_help_list_markdown(commands, command_map, prefix, group_commands)
40
-
74
+ markdown = cls._build_help_list_markdown(
75
+ commands, command_map, prefix, group_commands, other_prefixes
76
+ )
77
+
41
78
  # 构建 Text
42
- text = cls._build_help_list_text(commands, command_map, prefix, group_commands)
43
-
79
+ text = cls._build_help_list_text(
80
+ commands, command_map, prefix, group_commands, other_prefixes
81
+ )
82
+
44
83
  return {"html": html, "markdown": markdown, "text": text}
45
-
84
+
46
85
  @classmethod
47
- def _build_help_list_html(cls, commands: List[Dict], command_map: Dict[int, Dict],
48
- prefix: str, group_commands: bool) -> str:
86
+ def _build_help_list_html(
87
+ cls,
88
+ commands: List[Dict],
89
+ command_map: Dict[int, Dict],
90
+ prefix: str,
91
+ group_commands: bool,
92
+ other_prefixes: Optional[list] = None,
93
+ ) -> str:
49
94
  # 重置命令映射
50
95
  grouped = {}
51
96
  if group_commands:
@@ -56,27 +101,27 @@ class HelpTemplates:
56
101
  grouped[group].append(cmd)
57
102
  else:
58
103
  grouped["default"] = commands
59
-
104
+
60
105
  # 构建命令列表 HTML(带展开/折叠功能)
61
106
  commands_html = ""
62
107
  global_idx = 1
63
-
108
+
64
109
  for group, cmds in grouped.items():
65
110
  group_name = cls._get_group_name(group)
66
-
111
+
67
112
  commands_html += f"""
68
113
  <div style="font-size:13px; margin-bottom: 8px; font-weight: bold; color: {cls.PRIMARY_COLOR};">{group_name}</div>
69
114
  """
70
-
115
+
71
116
  for cmd in cmds:
72
117
  name = cmd["name"]
73
118
  info = cmd["info"]
74
119
  help_text = info.get("help", "暂无描述")
75
120
  command_map[global_idx] = cmd
76
-
121
+
77
122
  # 构建命令详情内容
78
123
  detail_content = cls._build_command_detail_inline(name, info, prefix)
79
-
124
+
80
125
  commands_html += f"""<details style="margin-bottom: 8px;">
81
126
  <summary style="cursor: pointer; font-size: 13px; padding: 4px; background: rgba(0, 0, 0, 0.02); border-radius: 4px; display: flex; align-items: center;">
82
127
  <span style="font-weight: bold; margin-right: 8px;">{global_idx}.</span>
@@ -87,43 +132,45 @@ class HelpTemplates:
87
132
  {detail_content}
88
133
  </div>
89
134
  </details>"""
90
- global_idx +=1
91
-
135
+ global_idx += 1
136
+
92
137
  commands_html += "\n"
93
-
138
+
94
139
  # 构建完整 HTML
95
140
  html = f"""<div style="padding: 12px; border-radius: 8px;">
96
141
  <div style="color: {cls.PRIMARY_COLOR}; font-size: 16px; font-weight: bold; margin-bottom: 12px;">
97
142
  命令帮助
98
143
  </div>
99
-
144
+
100
145
  <div style="padding: 8px; background: {cls.PRIMARY_BG}; border-radius: 6px; margin-bottom: 12px;">
101
146
  <div style="font-size: 13px;">
102
147
  使用 '{prefix}help <序号>' 查看命令详情
103
148
  </div>
104
149
  </div>
105
-
150
+
106
151
  {commands_html}
107
-
152
+
108
153
  <div style="font-size: 12px; color: #666; margin-top: 8px;">
109
154
  共 {len(commands)} 个可用命令
110
155
  </div>
156
+ {cls._prefix_note_html(other_prefixes or [])}
111
157
  </div>"""
112
-
158
+
113
159
  return html
114
-
160
+
115
161
  @classmethod
116
- def _build_help_list_markdown(cls, commands: List[Dict], command_map: Dict[int, Dict],
117
- prefix: str, group_commands: bool) -> str:
118
- lines = [
119
- "**命令帮助**",
120
- "",
121
- f"使用 `{prefix}help <序号>` 查看命令详情",
122
- ""
123
- ]
124
-
162
+ def _build_help_list_markdown(
163
+ cls,
164
+ commands: List[Dict],
165
+ command_map: Dict[int, Dict],
166
+ prefix: str,
167
+ group_commands: bool,
168
+ other_prefixes: Optional[list] = None,
169
+ ) -> str:
170
+ lines = ["**命令帮助**", "", f"使用 `{prefix}help <序号>` 查看命令详情", ""]
171
+
125
172
  global_idx = 1
126
-
173
+
127
174
  if group_commands:
128
175
  grouped = {}
129
176
  for cmd in commands:
@@ -131,19 +178,19 @@ class HelpTemplates:
131
178
  if group not in grouped:
132
179
  grouped[group] = []
133
180
  grouped[group].append(cmd)
134
-
181
+
135
182
  for group, cmds in grouped.items():
136
183
  group_name = cls._get_group_name(group)
137
184
  lines.append(f"**{group_name}**")
138
185
  lines.append("")
139
-
186
+
140
187
  for cmd in cmds:
141
188
  name = cmd["name"]
142
189
  help_text = cmd["info"].get("help", "暂无描述")
143
190
  command_map[global_idx] = cmd
144
191
  lines.append(f"{global_idx}. `{prefix}{name}` - {help_text}")
145
192
  global_idx += 1
146
-
193
+
147
194
  lines.append("")
148
195
  else:
149
196
  lines.append("**所有命令**")
@@ -155,24 +202,33 @@ class HelpTemplates:
155
202
  lines.append(f"{global_idx}. `{prefix}{name}` - {help_text}")
156
203
  global_idx += 1
157
204
  lines.append("")
158
-
205
+
159
206
  lines.append("---")
160
207
  lines.append(f"共 {len(commands)} 个可用命令")
161
-
208
+ if other_prefixes:
209
+ lines.append("")
210
+ lines.append(f"其他触发前缀: {'、'.join(other_prefixes)}")
211
+
162
212
  return "\n".join(lines)
163
-
213
+
164
214
  @classmethod
165
- def _build_help_list_text(cls, commands: List[Dict], command_map: Dict[int, Dict],
166
- prefix: str, group_commands: bool) -> str:
215
+ def _build_help_list_text(
216
+ cls,
217
+ commands: List[Dict],
218
+ command_map: Dict[int, Dict],
219
+ prefix: str,
220
+ group_commands: bool,
221
+ other_prefixes: Optional[list] = None,
222
+ ) -> str:
167
223
  lines = [
168
224
  "命令帮助",
169
225
  "----------",
170
226
  f"使用 '{prefix}help <序号>' 查看命令详情",
171
- ""
227
+ "",
172
228
  ]
173
-
229
+
174
230
  global_idx = 1
175
-
231
+
176
232
  if group_commands:
177
233
  grouped = {}
178
234
  for cmd in commands:
@@ -180,19 +236,19 @@ class HelpTemplates:
180
236
  if group not in grouped:
181
237
  grouped[group] = []
182
238
  grouped[group].append(cmd)
183
-
239
+
184
240
  for group, cmds in grouped.items():
185
241
  group_name = cls._get_group_name(group)
186
242
  lines.append(f"[{group_name}]")
187
243
  lines.append("")
188
-
244
+
189
245
  for cmd in cmds:
190
246
  name = cmd["name"]
191
247
  help_text = cmd["info"].get("help", "暂无描述")
192
248
  command_map[global_idx] = cmd
193
249
  lines.append(f"{global_idx}. {prefix}{name} - {help_text}")
194
250
  global_idx += 1
195
-
251
+
196
252
  lines.append("")
197
253
  else:
198
254
  lines.append("[所有命令]")
@@ -204,53 +260,58 @@ class HelpTemplates:
204
260
  lines.append(f"{global_idx}. {prefix}{name} - {help_text}")
205
261
  global_idx += 1
206
262
  lines.append("")
207
-
263
+
208
264
  lines.append("----------")
209
265
  lines.append(f"共 {len(commands)} 个可用命令")
210
-
266
+ if other_prefixes:
267
+ lines.append("")
268
+ lines.append(f"其他触发前缀: {'、'.join(other_prefixes)}")
269
+
211
270
  return "\n".join(lines)
212
-
271
+
213
272
  @classmethod
214
273
  def _build_command_detail_inline(cls, name: str, info: Dict, prefix: str) -> str:
215
274
  """
216
275
  构建内联命令详情(用于展开区域)
217
276
  """
218
277
  parts = []
219
-
278
+
220
279
  # 描述
221
280
  parts.append(f"""<div style="margin-bottom: 8px;">
222
281
  <strong style="font-size: 12px; color: {cls.PRIMARY_COLOR};">描述:</strong>
223
- <span style="font-size: 12px; margin-left: 8px;">{info.get('help', '暂无描述')}</span>
282
+ <span style="font-size: 12px; margin-left: 8px;">{info.get("help", "暂无描述")}</span>
224
283
  </div>""")
225
-
284
+
226
285
  # 别名 - 从全局 command.aliases 获取
227
- main_name = info.get('main_name', name)
286
+ main_name = info.get("main_name", name)
228
287
  aliases = []
229
288
  for alias, mapped_name in command.aliases.items():
230
289
  if mapped_name == main_name and alias != main_name:
231
290
  aliases.append(alias)
232
-
291
+
233
292
  if aliases:
234
- aliases_text = ", ".join(f"<code style='font-size: 11px;'>{prefix}{a}</code>" for a in aliases)
293
+ aliases_text = ", ".join(
294
+ f"<code style='font-size: 11px;'>{prefix}{a}</code>" for a in aliases
295
+ )
235
296
  parts.append(f"""<div style="margin-bottom: 8px;">
236
297
  <strong style="font-size: 12px; color: {cls.PRIMARY_COLOR};">别名:</strong>
237
298
  <span style="font-size: 12px; margin-left: 8px;">{aliases_text}</span>
238
299
  </div>""")
239
-
300
+
240
301
  # 用法
241
302
  if info.get("usage"):
242
303
  parts.append(f"""<div style="margin-bottom: 8px;">
243
304
  <strong style="font-size: 12px; color: {cls.PRIMARY_COLOR};">用法:</strong>
244
- <span style="font-size: 12px; margin-left: 8px; font-family: monospace; background: rgba(0, 0, 0, 0.03); padding: 2px 6px; border-radius: 3px;">{info['usage'].replace('/', prefix)}</span>
305
+ <span style="font-size: 12px; margin-left: 8px; font-family: monospace; background: rgba(0, 0, 0, 0.03); padding: 2px 6px; border-radius: 3px;">{info["usage"].replace("/", prefix)}</span>
245
306
  </div>""")
246
-
307
+
247
308
  # 权限
248
309
  if info.get("permission"):
249
310
  parts.append(f"""<div style="margin-bottom: 8px;">
250
311
  <strong style="font-size: 12px; color: {cls.PRIMARY_COLOR};">权限:</strong>
251
312
  <span style="font-size: 12px; margin-left: 8px; color: {cls.WARNING_COLOR};">需要特殊权限</span>
252
313
  </div>""")
253
-
314
+
254
315
  # 分组
255
316
  if info.get("group"):
256
317
  group_name = cls._get_group_name(info["group"])
@@ -258,36 +319,42 @@ class HelpTemplates:
258
319
  <strong style="font-size: 12px; color: {cls.PRIMARY_COLOR};">分组:</strong>
259
320
  <span style="font-size: 12px; margin-left: 8px;">{group_name}</span>
260
321
  </div>""")
261
-
322
+
262
323
  return "\n".join(parts)
263
-
324
+
264
325
  # ==================== 命令详情模板 ====================
265
-
326
+
266
327
  @classmethod
267
- def build_command_detail(cls, cmd: Dict, prefix: str) -> Dict[str, str]:
328
+ def build_command_detail(
329
+ cls, cmd: Dict, prefix: str, prefixes: Optional[list] = None
330
+ ) -> Dict[str, str]:
331
+ other_prefixes = cls._other_prefixes(prefixes or [prefix], prefix)
332
+
268
333
  # 构建 HTML
269
- html = cls._build_command_detail_html(cmd, prefix)
270
-
334
+ html = cls._build_command_detail_html(cmd, prefix, other_prefixes)
335
+
271
336
  # 构建 Markdown
272
- markdown = cls._build_command_detail_markdown(cmd, prefix)
273
-
337
+ markdown = cls._build_command_detail_markdown(cmd, prefix, other_prefixes)
338
+
274
339
  # 构建 Text
275
- text = cls._build_command_detail_text(cmd, prefix)
276
-
340
+ text = cls._build_command_detail_text(cmd, prefix, other_prefixes)
341
+
277
342
  return {"html": html, "markdown": markdown, "text": text}
278
-
343
+
279
344
  @classmethod
280
- def _build_command_detail_html(cls, cmd: Dict, prefix: str) -> str:
345
+ def _build_command_detail_html(
346
+ cls, cmd: Dict, prefix: str, other_prefixes: Optional[list] = None
347
+ ) -> str:
281
348
  name = cmd["name"]
282
349
  info = cmd["info"]
283
-
350
+
284
351
  html_parts = [
285
352
  f"""<div style="padding: 12px; border-radius: 8px;">
286
353
  <div style="color: {cls.PRIMARY_COLOR}; font-size: 16px; font-weight: bold; margin-bottom: 12px;">
287
354
  命令详情: {prefix}{name}
288
355
  </div>"""
289
356
  ]
290
-
357
+
291
358
  # 描述
292
359
  html_parts.append(f"""
293
360
  <div style="margin-bottom: 12px; border: 1px solid #e0e0e0; padding: 12px; border-radius: 6px;">
@@ -295,17 +362,17 @@ class HelpTemplates:
295
362
  <strong style="font-size: 14px;">描述:</strong>
296
363
  </div>
297
364
  <div style="font-size: 13px;">
298
- {info.get('help', '暂无描述')}
365
+ {info.get("help", "暂无描述")}
299
366
  </div>
300
367
  </div>""")
301
-
368
+
302
369
  # 别名 - 从全局 command.aliases 获取
303
- main_name = info.get('main_name', name)
370
+ main_name = info.get("main_name", name)
304
371
  aliases = []
305
372
  for alias, mapped_name in command.aliases.items():
306
373
  if mapped_name == main_name and alias != main_name:
307
374
  aliases.append(alias)
308
-
375
+
309
376
  if aliases:
310
377
  aliases_text = ", ".join(f"{prefix}{a}" for a in aliases)
311
378
  html_parts.append(f"""
@@ -317,7 +384,7 @@ class HelpTemplates:
317
384
  {aliases_text}
318
385
  </div>
319
386
  </div>""")
320
-
387
+
321
388
  # 用法
322
389
  if info.get("usage"):
323
390
  html_parts.append(f"""
@@ -326,10 +393,10 @@ class HelpTemplates:
326
393
  <strong>用法:</strong>
327
394
  </div>
328
395
  <div style="font-size: 13px; font-family: monospace; background: rgba(0, 0, 0, 0.03); padding: 6px; border-radius: 4px;">
329
- {info['usage'].replace('/', prefix)}
396
+ {info["usage"].replace("/", prefix)}
330
397
  </div>
331
398
  </div>""")
332
-
399
+
333
400
  # 权限
334
401
  if info.get("permission"):
335
402
  html_parts.append(f"""
@@ -341,7 +408,7 @@ class HelpTemplates:
341
408
  需要特殊权限
342
409
  </div>
343
410
  </div>""")
344
-
411
+
345
412
  # 分组
346
413
  if info.get("group"):
347
414
  group_name = cls._get_group_name(info["group"])
@@ -354,97 +421,111 @@ class HelpTemplates:
354
421
  {group_name}
355
422
  </div>
356
423
  </div>""")
357
-
424
+
425
+ if other_prefixes:
426
+ html_parts.append(f"""
427
+ {cls._prefix_note_html(other_prefixes)}""")
428
+
358
429
  html_parts.append("</div>")
359
-
430
+
360
431
  return "\n".join(html_parts)
361
-
432
+
362
433
  @classmethod
363
- def _build_command_detail_markdown(cls, cmd: Dict, prefix: str) -> str:
434
+ def _build_command_detail_markdown(
435
+ cls, cmd: Dict, prefix: str, other_prefixes: Optional[list] = None
436
+ ) -> str:
364
437
  name = cmd["name"]
365
438
  info = cmd["info"]
366
-
439
+
367
440
  lines = [
368
441
  f"**命令详情:** `{prefix}{name}`",
369
442
  "",
370
443
  f"**描述:** {info.get('help', '暂无描述')}",
371
- ""
444
+ "",
372
445
  ]
373
-
446
+
374
447
  # 别名 - 从全局 command.aliases 获取
375
- main_name = info.get('main_name', name)
448
+ main_name = info.get("main_name", name)
376
449
  aliases = []
377
450
  for alias, mapped_name in command.aliases.items():
378
451
  if mapped_name == main_name and alias != main_name:
379
452
  aliases.append(alias)
380
-
453
+
381
454
  if aliases:
382
455
  aliases_text = ", ".join(f"`{prefix}{a}`" for a in aliases)
383
456
  lines.append(f"**别名:** {aliases_text}")
384
457
  lines.append("")
385
-
458
+
386
459
  # 用法
387
460
  if info.get("usage"):
388
461
  lines.append(f"**用法:** `{info['usage'].replace('/', prefix)}`")
389
462
  lines.append("")
390
-
463
+
391
464
  # 权限
392
465
  if info.get("permission"):
393
466
  lines.append("**权限:** 需要特殊权限")
394
467
  lines.append("")
395
-
468
+
396
469
  # 分组
397
470
  if info.get("group"):
398
471
  group_name = cls._get_group_name(info["group"])
399
472
  lines.append(f"**分组:** {group_name}")
400
473
  lines.append("")
401
-
474
+ if other_prefixes:
475
+ lines.append(f"其他触发前缀: {'、'.join(other_prefixes)}")
476
+ lines.append("")
477
+
402
478
  return "\n".join(lines)
403
-
479
+
404
480
  @classmethod
405
- def _build_command_detail_text(cls, cmd: Dict, prefix: str) -> str:
481
+ def _build_command_detail_text(
482
+ cls, cmd: Dict, prefix: str, other_prefixes: Optional[list] = None
483
+ ) -> str:
406
484
  name = cmd["name"]
407
485
  info = cmd["info"]
408
-
486
+
409
487
  lines = [
410
488
  f"命令详情: {prefix}{name}",
411
489
  "----------",
412
490
  f"描述: {info.get('help', '暂无描述')}",
413
- ""
491
+ "",
414
492
  ]
415
-
493
+
416
494
  # 别名 - 从全局 command.aliases 获取
417
- main_name = info.get('main_name', name)
495
+ main_name = info.get("main_name", name)
418
496
  aliases = []
419
497
  for alias, mapped_name in command.aliases.items():
420
498
  if mapped_name == main_name and alias != main_name:
421
499
  aliases.append(alias)
422
-
500
+
423
501
  if aliases:
424
502
  aliases_text = ", ".join(f"{prefix}{a}" for a in aliases)
425
503
  lines.append(f"别名: {aliases_text}")
426
504
  lines.append("")
427
-
505
+
428
506
  # 用法
429
507
  if info.get("usage"):
430
508
  lines.append(f"用法: {info['usage'].replace('/', prefix)}")
431
509
  lines.append("")
432
-
510
+
433
511
  # 权限
434
512
  if info.get("permission"):
435
513
  lines.append("权限: 需要特殊权限")
436
514
  lines.append("")
437
-
515
+
438
516
  # 分组
439
517
  if info.get("group"):
440
518
  group_name = cls._get_group_name(info["group"])
441
519
  lines.append(f"分组: {group_name}")
442
520
  lines.append("")
443
-
521
+ if other_prefixes:
522
+ lines.append(f"其他触发前缀: {'、'.join(other_prefixes)}")
523
+ lines.append("")
524
+
444
525
  return "\n".join(lines)
445
-
526
+
446
527
  # ==================== 错误消息模板 ====================
447
-
528
+
448
529
  @classmethod
449
530
  def build_error(cls, title: str, message: str) -> Dict[str, str]:
450
531
  html = f"""
@@ -452,9 +533,9 @@ class HelpTemplates:
452
533
  <div style="color: {cls.ERROR_COLOR}; font-size: 14px; font-weight: bold; margin-bottom: 8px;">{title}</div>
453
534
  <div style="font-size: 13px;">{message}</div>
454
535
  </div>"""
455
-
536
+
456
537
  markdown = f"**{title}**\n\n{message}"
457
-
538
+
458
539
  text = f"{title}\n\n{message}"
459
-
460
- return {"html": html, "markdown": markdown, "text": text}
540
+
541
+ return {"html": html, "markdown": markdown, "text": text}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-HelpModule
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: ErisPulse 帮助命令模块,提供自动化的命令帮助系统,支持查看所有可用命令及其用法说明
5
5
  Author-email: wsu2059q <wsu2059@qq.com>
6
6
  License-Expression: MIT
@@ -0,0 +1,9 @@
1
+ ErisPulse_HelpModule/Core.py,sha256=dV6W1G5RaP3zE-a8TfzK2WCDAe3eTTmnmdaWUNxgOYg,7119
2
+ ErisPulse_HelpModule/__init__.py,sha256=ybEvf416FykwVwiKcGdeQZvrsHWkLkMAlNjqZbhY38k,28
3
+ ErisPulse_HelpModule/templates.py,sha256=NmDx-RgT-9xNn8LfRUGCxShs8v6eq8vryR2Ok_zeum0,18427
4
+ erispulse_helpmodule-2.1.2.dist-info/licenses/LICENSE,sha256=7BKmRD_5YpTGfc12w9L3TIskHF3A_AWDU4xuDQKE92w,1055
5
+ erispulse_helpmodule-2.1.2.dist-info/METADATA,sha256=Ui3oInUYdn-sW6siljmgH9-WCrQsxms_cl3hpwX1g4w,1621
6
+ erispulse_helpmodule-2.1.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ erispulse_helpmodule-2.1.2.dist-info/entry_points.txt,sha256=EBPR47ANi5DAbba7E2r558vfeD2AeR7lYXSt2_NNCwY,64
8
+ erispulse_helpmodule-2.1.2.dist-info/top_level.txt,sha256=BFgAL-qs-KTqA4wuD6XaQhQzPZOmJ0IOqK9vq7Kqdos,21
9
+ erispulse_helpmodule-2.1.2.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- ErisPulse_HelpModule/Core.py,sha256=BEqYIeNyuO-FUu-e5Y5L8EDnuxCDwiSKfXmAhzD_oO4,8250
2
- ErisPulse_HelpModule/__init__.py,sha256=ybEvf416FykwVwiKcGdeQZvrsHWkLkMAlNjqZbhY38k,28
3
- ErisPulse_HelpModule/templates.py,sha256=rbkK_lTKMlACz3zgPFVh9cpqljOwoRo4mPsOQ7pk1zc,16762
4
- erispulse_helpmodule-2.1.0.dist-info/licenses/LICENSE,sha256=7BKmRD_5YpTGfc12w9L3TIskHF3A_AWDU4xuDQKE92w,1055
5
- erispulse_helpmodule-2.1.0.dist-info/METADATA,sha256=IPW5As1nivchB6LfFZqvzeuZ4YFNj-ACwRWUfN-vxog,1621
6
- erispulse_helpmodule-2.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
- erispulse_helpmodule-2.1.0.dist-info/entry_points.txt,sha256=EBPR47ANi5DAbba7E2r558vfeD2AeR7lYXSt2_NNCwY,64
8
- erispulse_helpmodule-2.1.0.dist-info/top_level.txt,sha256=BFgAL-qs-KTqA4wuD6XaQhQzPZOmJ0IOqK9vq7Kqdos,21
9
- erispulse_helpmodule-2.1.0.dist-info/RECORD,,