Skip to content

Commit

Permalink
change: 发送 /help 默认显示 /help -l 的内容 (#48)
Browse files Browse the repository at this point in the history
这样也不再需要 --list 参数

close #47
  • Loading branch information
he0119 authored Apr 16, 2023
1 parent 53dc45a commit 05eb891
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 367 deletions.
7 changes: 5 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"type": "python",
"request": "launch",
"module": "nb_cli",
"args": ["run"],
"args": [
"run",
"--reload"
],
"justMyCode": false
},
{
Expand All @@ -19,4 +22,4 @@
"module": "pytest"
}
]
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/

## [Unreleased]

### Changed

- 发送 /help 默认显示 /help -l 的内容

## [0.0.5] - 2023-03-06

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _✨ NoneBot 树形帮助插件 ✨_

## 使用方式

加载插件后发送 `/help``/help --help` 获取具体用法。
加载插件后发送 `/help help``/help --help` 获取具体用法。

插件与子插件写法可参考 [示例插件](./tests/plugins/tree/)

Expand Down
6 changes: 1 addition & 5 deletions nonebot_plugin_treehelp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

parser = ArgumentParser("帮助", description="获取插件帮助信息")
parser.add_argument("plugin_name", nargs="?", type=str, help="插件名", metavar="插件名")
parser.add_argument("-l", "--list", action="store_true", help="获取插件列表")
parser.add_argument("-t", "--tree", action="store_true", help="获取插件树")
help_cmd = on_shell_command("help", aliases={"帮助"}, parser=parser)

Expand All @@ -39,10 +38,7 @@ async def help_handle(bot: Bot, args: Namespace = ShellCommandArgs()):
plugin_name = args.plugin_name

if plugin_name is None:
if args.list or args.tree:
await help_cmd.finish(get_plugin_list(bot, args.tree))
else:
plugin_name = "帮助"
await help_cmd.finish(get_plugin_list(bot, args.tree))

plugin_help = get_plugin_help(bot, plugin_name, args.tree)
if plugin_help:
Expand Down
625 changes: 289 additions & 336 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/test_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def test_adapters(app: App):

async with app.test_matcher(help_cmd) as ctx:
bot = ctx.create_bot()
message = message = make_fake_message()("/help --list")
message = message = make_fake_message()("/help")
event = make_fake_event(_message=message)()

ctx.receive_event(bot, event)
Expand Down
22 changes: 2 additions & 20 deletions tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,7 @@ async def test_help(app: App):
event = make_fake_event(_message=message)()

ctx.receive_event(bot, event)
ctx.should_call_send(
event,
f"帮助\n\n{__plugin_meta__.usage}",
True,
)
ctx.should_finished()


async def test_help_list(app: App):
"""测试查看所有插件"""
from nonebot_plugin_treehelp import help_cmd

async with app.test_matcher(help_cmd) as ctx:
bot = ctx.create_bot()
message = message = make_fake_message()("/help --list")
event = make_fake_event(_message=message)()

ctx.receive_event(bot, event)
ctx.should_call_send(event, "插件:\n帮助 # 获取插件帮助信息", True)
ctx.should_call_send(event, f"插件:\n帮助 # 获取插件帮助信息", True)
ctx.should_finished()


Expand Down Expand Up @@ -79,7 +61,7 @@ async def test_help_command_error(app: App):
ctx.receive_event(bot, event)
ctx.should_call_send(
event,
"usage: 帮助 [-h] [-l] [-t] [插件名]\n帮助: error: unrecognized arguments: --test\n",
"usage: 帮助 [-h] [-t] [插件名]\n帮助: error: unrecognized arguments: --test\n",
True,
)
ctx.should_finished()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def test_parent(app: App):

async with app.test_matcher(help_cmd) as ctx:
bot = ctx.create_bot()
message = message = make_fake_message()("/help --list")
message = message = make_fake_message()("/help")
event = make_fake_event(_message=message)()

ctx.receive_event(bot, event)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def test_root(app: App):

async with app.test_matcher(help_cmd) as ctx:
bot = ctx.create_bot()
message = message = make_fake_message()("/help --list")
message = message = make_fake_message()("/help")
event = make_fake_event(_message=message)()

ctx.receive_event(bot, event)
Expand Down

0 comments on commit 05eb891

Please sign in to comment.