forked from sass/tipibot
28 lines
882 B
Python
28 lines
882 B
Python
from __future__ import annotations
|
|
|
|
import discord
|
|
from discord import app_commands
|
|
|
|
import config
|
|
|
|
|
|
def is_bot_admin(member: discord.Member) -> bool:
|
|
"""Return True if the member has the configured bot-admin role for their guild."""
|
|
role_id = config.BOT_ADMIN_ROLES.get(member.guild.id)
|
|
if role_id is None:
|
|
return False
|
|
return any(r.id == role_id for r in member.roles)
|
|
|
|
|
|
def bot_admin_check():
|
|
"""Slash-command check decorator: raises MissingPermissions if not a bot admin."""
|
|
def predicate(interaction: discord.Interaction) -> bool:
|
|
member = interaction.user
|
|
if not isinstance(member, discord.Member):
|
|
raise app_commands.MissingPermissions(["bot_admin"])
|
|
if not is_bot_admin(member):
|
|
raise app_commands.MissingPermissions(["bot_admin"])
|
|
return True
|
|
|
|
return app_commands.check(predicate)
|