jarvis-bot/jarvis/utils/permissions.py

30 lines
910 B
Python

"""Permissions wrappers."""
from naff import InteractionContext, Permissions
from jarvis.config import JarvisConfig
def user_is_bot_admin() -> bool:
"""Check if a user is a JARVIS admin."""
async def predicate(ctx: InteractionContext) -> bool:
"""Command check predicate."""
cfg = JarvisConfig.from_yaml()
if getattr(cfg, "admins", None):
return ctx.author.id in cfg.admins
else:
return False
return predicate
def admin_or_permissions(*perms: list) -> bool:
"""Check if a user is an admin or has other perms."""
async def predicate(ctx: InteractionContext) -> bool:
"""Extended check predicate.""" # noqa: D401
is_admin = ctx.author.has_permission(Permissions.ADMINISTRATOR)
has_other = any(ctx.author.has_permission(perm) for perm in perms)
return is_admin or has_other
return predicate