Skip to content

Commit

Permalink
config(command): support setting permission requirement to the root `…
Browse files Browse the repository at this point in the history
…!!pb` command
  • Loading branch information
Fallen-Breath committed Mar 3, 2024
1 parent 405be59 commit 7317fb4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ A value of `0` means using 50% of the CPU
{
"prefix": "!!pb",
"permission": {
"root": 0,
"abort": 1,
"back": 2,
"confirm": 1,
Expand Down Expand Up @@ -107,6 +108,8 @@ If a subcommand is not in the mapping, it will use level 1 as the default permis
For example, in the default config, `"back"` is mapped to `2`,
which means that the `!!pb back` command requires permission level >= 2 to execute

Specially, `"root"` refers to the root command, which is usually `!!pb`

- Type: `Dict[str, int]`

#### confirm_time_wait
Expand Down
5 changes: 4 additions & 1 deletion docs/config.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Prime Backup 储存各种数据文件所用的根目录
{
"prefix": "!!pb",
"permission": {
"root": 0,
"abort": 1,
"back": 2,
"confirm": 1,
Expand Down Expand Up @@ -104,7 +105,9 @@ MCDR 中,Prime Backup 所有命令的前缀。通常你不需要更改它
如果子命令不在映射表中,将使用 `1` 作为默认的权限等级要求

例如,在默认配置中,`"back"` 被映射到 `2`
这意味着 `!!pb back` 命令需要权限级别 >=2 才能执行。
这意味着 `!!pb back` 命令需要权限级别 >=2 才能执行

特别地,`"root"` 指的是根命令,通常即 `!!pb` 指令

- 类型:`Dict[str, int]`

Expand Down
2 changes: 2 additions & 0 deletions prime_backup/config/command_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


class CommandPermissions(Serializable):
root: int = 0

abort: int = 1
back: int = 2
confirm: int = 1
Expand Down
1 change: 1 addition & 0 deletions prime_backup/mcdr/command/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def create_backup_id(arg_name: str = 'backup_id', clazz: Type[Integer] = Integer
root = (
Literal(self.config.command.prefix).
requires(lambda: not self.plugin_disabled, lambda: tr('error.disabled').set_color(RColor.red)).
requires(get_permission_checker('root'), get_permission_denied_text).
runs(self.cmd_welcome)
)
builder.add_children_for(root)
Expand Down

0 comments on commit 7317fb4

Please sign in to comment.