Skip to content

Commit

Permalink
✨ version 0.16.0
Browse files Browse the repository at this point in the history
add `Command` which looks like koishi's command
  • Loading branch information
RF-Tar-Railt committed Aug 15, 2023
1 parent 35e788f commit ef78018
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
16 changes: 8 additions & 8 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = [
]
dependencies = [
"nonebot2>=2.0.0rc4",
"arclet-alconna<2.0.0, >=1.7.17",
"arclet-alconna-tools<0.7.0, >=0.6.5",
"arclet-alconna<2.0.0, >=1.7.18",
"arclet-alconna-tools<0.7.0, >=0.6.6",
"nepattern<0.6.0, >=0.5.13",
]
dynamic = ["version"]
Expand Down
3 changes: 2 additions & 1 deletion src/nonebot_plugin_alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from .params import SegMsg as SegMsg
from .params import assign as assign
from .rule import alconna as alconna
from .matcher import Command as Command
from .adapters import Segment as Segment
from .rule import seg_match as seg_match
from .params import AlcResult as AlcResult
Expand Down Expand Up @@ -73,7 +74,7 @@
from .consts import ALCONNA_EXEC_RESULT as ALCONNA_EXEC_RESULT
from .rule import set_output_converter as set_output_converter

__version__ = "0.15.0"
__version__ = "0.16.0"

_meta_source = {
"name": "Alconna 插件",
Expand Down
29 changes: 28 additions & 1 deletion src/nonebot_plugin_alconna/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from nepattern import AnyOne, AnyString
from nonebot.permission import Permission
from nonebot.dependencies import Dependent
from arclet.alconna.tools import AlconnaFormat
from tarina import is_awaitable, run_always_await
from arclet.alconna.tools import AlconnaFormat, AlconnaString
from arclet.alconna.tools.construct import FuncMounter, MountConfig
from arclet.alconna import Arg, Args, Alconna, ShortcutArgs, command_manager
from nonebot.typing import T_State, T_Handler, T_RuleChecker, T_PermissionChecker
Expand Down Expand Up @@ -293,3 +293,30 @@ async def handle(bot: Bot, event: Event, results: AlcExecResult):
return matcher

return wrapper


class Command(AlconnaString):
def build(
self,
rule: Rule | T_RuleChecker | None = None,
skip_for_unmatch: bool = True,
auto_send_output: bool = False,
output_converter: TConvert | None = None,
aliases: set[str] | tuple[str, ...] | None = None,
comp_config: CompConfig | None = None,
use_origin: bool = False,
permission: Permission | T_PermissionChecker | None = None,
*,
handlers: list[T_Handler | Dependent] | None = None,
temp: bool = False,
expire_time: datetime | timedelta | None = None,
priority: int = 1,
block: bool = False,
state: T_State | None = None,
_depth: int = 0,
):
params = locals()
params.pop("self")
params.pop("__class__")
alc = super().build()
return on_alconna(alc, **params)
21 changes: 20 additions & 1 deletion src/test/plugins/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Match,
Query,
Reply,
Command,
AlconnaArg,
AlconnaMatch,
AlconnaQuery,
Expand Down Expand Up @@ -192,7 +193,11 @@ async def bind_handle(reply: Reply = SegMatchResult(Reply)):


mask_cmd = on_alconna(
Alconna("设置词云形状", Args["img?", Image], Option("--default", action=store_true))
Alconna(
"设置词云形状",
Args["img?", Image],
Option("--default", action=store_true, default=False),
),
)

mask_cmd.shortcut(
Expand All @@ -217,3 +222,17 @@ async def mask_g(
await mask_cmd.send(f"img: {img[:10]}")
else:
await mask_cmd.send("ok")


book = (
Command("book", "测试")
.option("writer", "-w <id:int>")
.option("writer", "--anonymous", {"id": 0})
.usage("book [-w <id:int> | --anonymous]")
.build()
)


@book.handle()
async def test1_h(arp: Arparma = AlconnaMatches()):
await book.send(str(arp.options))

0 comments on commit ef78018

Please sign in to comment.