-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcommand.py
More file actions
59 lines (49 loc) · 1.88 KB
/
command.py
File metadata and controls
59 lines (49 loc) · 1.88 KB
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
from nonebot_plugin_alconna import Alconna, Args, Subcommand, on_alconna, Option
from nonebot_plugin_alconna.uniseg import Target
from nonebot_plugin_larkutils.superuser import is_user_superuser
from nonebot_plugin_larkutils import get_user_id, get_group_id
from . import __main__ as main
lang_cmd = on_alconna(
Alconna(
"lang",
Subcommand(
"set",
Args["language", str],
Option("--group|-g"),
),
Subcommand("view", Args["language", str]),
Subcommand("reload"),
)
)
lang = main.LangHelper()
@lang_cmd.assign("reload")
async def _(user_id: str = get_user_id(), superuser: bool = is_user_superuser()) -> None:
if superuser:
await main.load_languages()
await lang.finish("reload.success", user_id)
await lang.finish("reload.no_permission", user_id)
@lang_cmd.assign("set")
async def _(
language: str,
group: bool,
user_id: str = get_user_id(),
group_id: str = get_group_id(),
) -> None:
if language not in main.get_languages():
await lang.send("global.not_found", user_id, language)
if group:
await main.set_group_language(group_id, language)
await lang.send("set.group.success", user_id, language)
else:
await main.set_user_language(user_id, language)
await lang.send("set.success", user_id, language)
await lang_cmd.finish()
@lang_cmd.assign("view")
async def _(language: str, user_id: str = get_user_id()) -> None:
if language not in main.get_languages():
await lang.send("global.not_found", user_id, language)
data = main.get_languages()[language]
await lang.reply("view.info", user_id, language, data.author, data.version, data.display.description)
@lang_cmd.assign("$main")
async def _(user_id: str = get_user_id()) -> None:
await lang.reply("lang.list", user_id, "\n".join(list(main.get_languages().keys())))