Open
Description
Pretty much what it says on the tin. One possible way to implement them is to combine all configurable checks into one decorator like this.
def config_checks():
config_checks = [
user_config_check
role_config_check
channel_config_check
perm_level_config_check
]
def wrapper(ctx: commands.Context[Tux]) -> bool:
permissions = get_permissions(ctx)
return all(map(lambda check: check(permissions, ctx), config_checks))
return commands.check(wrapper)
def get_permissions(ctx: commands.Context[Tux]):
# return list of permissions relevant to context
...
def user_config_check(perms, ctx: commands.Context[Tux]) -> bool:
...
def role_config_check(perms, ctx: commands.Context[Tux]) -> bool:
...
def channel_config_check(perms, ctx: commands.Context[Tux]) -> bool:
...
def perm_level_config_check(perms, ctx: commands.Context[Tux]) -> bool:
...
Here's a Prisma schema that can handle the 4 (technically 5) different permission types.
model CommandPermission {
id Int @id @default(autoincrement())
name String @unique
guild_id BigInt
group_id Int?
guild GuildConfig @relation(fields: [guild_id], references: [guild_id])
group CommandPermissionGroup? @relation(fields: [group_id], references: [id])
permissions CommandPermissionEntry[]
}
model CommandPermissionGroup {
id Int @id @default(autoincrement())
name String @unique
guild_id BigInt
guild GuildConfig @relation(fields: [guild_id], references: [guild_id])
commands CommandPermission[]
permissions CommandPermissionEntry[]
}
model CommandPermissionEntry {
id Int @id @default(autoincrement())
type PermissionTargetType
target_id BigInt
mode PermissionMode
command_id Int?
group_id Int?
commandPermission CommandPermission? @relation(fields: [command_id], references: [id])
group CommandPermissionGroup? @relation(fields: [group_id], references: [id])
}
enum PermissionTargetType {
USER
ROLE
CHANNEL
PERM_LEVEL_EXACT
PERM_LEVEL_AT_LEAST
}
enum PermissionMode {
WHITELIST
BLACKLIST
}