-
Notifications
You must be signed in to change notification settings - Fork 6
/
exam1.py
55 lines (50 loc) · 1.95 KB
/
exam1.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
from tarina import lang
from arclet.alconna import Alconna, Arg, Args, Metadata, CompSession, Option, OptionResult
lang.set("completion", "node", "")
lang.set("completion", "prompt_select", "")
api_list = ["saucenao", "ascii2d", "ehentai", "iqdb", "tracemoe"]
alc = Alconna(
"setu",
Args.content(str),
Option("use", Args.api(api_list), help_text="选择搜图使用的 API"),
Option("count", Arg("num", int), help_text="设置每次搜图展示的最多数量"),
Option("--similarity|-s", Args.val(float), help_text="设置相似度过滤的值", default=OptionResult(args={"val": 0.5})),
Option("--timeout|-t", Args.sec(int), help_text="设置超时时间", default=OptionResult(args={"sec": 60})),
Metadata(
"依据输入的图片寻找可能的原始图片来源",
usage="可以传入图片, 也可以是图片的网络链接",
example="setu搜索 [图片]",
),
)
interface = CompSession(alc)
with interface:
res = alc.parse(input(">>> "))
while interface.available:
print("---------------------------------------------------")
print(interface)
print("---------------------------------------------------")
print(".enter to confirm, .tab to switch, ctrl+c to cancel")
print("---------------------------------------------------")
while True:
cmd = input(">>> ")
if cmd in (".exit", ".quit", ".q"):
print("exit.")
exit(0)
if cmd == ".tab":
print(interface.tab())
elif cmd.startswith(".enter"):
_res = interface.enter(None)
if _res.result:
res = _res.result
elif _res.exception:
print(_res.exception)
break
else:
_res = interface.enter([cmd])
if _res.result:
res = _res.result
elif _res.exception:
print(_res.exception)
break
print(res.matched)
print(res.all_matched_args)