-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
test-alconna.py
67 lines (52 loc) · 1.91 KB
/
test-alconna.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from arclet.alconna import Alconna, Args, CommandMeta, Option, Subcommand, count
from avilla.console.protocol import ConsoleProtocol
from avilla.core import Avilla, Context, Notice
from avilla.core.builtins.command import AvillaCommands, Match
from typing import Union
alc = Alconna(
"pip",
Subcommand(
"install",
Args["package", str],
Option("-r|--requirement", Args["file", str]),
Option("-i|--index-url", Args["url", str])
),
Option("--version", help_text="显示版本号"),
Option("-v|--verbose", action=count),
meta=CommandMeta(
"模拟 pip 命令",
"pip install [package] [-r|--requirement <file>] [-i|--index-url <url>]",
"pip install -r requirements.txt",
)
)
avilla = Avilla()
avilla.apply_protocols(ConsoleProtocol())
cmd = AvillaCommands(need_tome=False, remove_tome=True)
@cmd.on("ping")
async def ping(ctx: Context):
await ctx.scene.send_message("pong")
@cmd.on("转账 {target} {mount}")
async def ping(ctx: Context, target: Union[str, Notice], mount: int):
await ctx.scene.send_message(f"转账给 {target} {mount} 元")
@(
cmd.command("help [name:str]", "菜单命令")
.example("help help")
)
async def help_(ctx: Context, name: Match[str]):
if name.available:
try:
await ctx.scene.send_message(cmd.get_help(name.result))
except ValueError:
await ctx.scene.send_message("没有这个命令")
else:
await ctx.scene.send_message(cmd.all_helps)
@cmd.on(alc)
async def test(package: Match[str], ctx: Context):
await ctx.scene.send_message(f"installing {package.result}")
@cmd.on("add test {a:int} {b:int}")
async def add_test(ctx: Context, a: int, b: int):
await ctx.scene.send_message(f"test {a} + {b} = {a + b}")
@cmd.on("add {a:int} {b:int}")
async def add(ctx: Context, a: int, b: int):
await ctx.scene.send_message(f"{a} + {b} = {a + b}")
avilla.launch()