"""/drb — server-level DRB setup. Today: /drb link (server-26#213 item 1).""" import discord from discord import app_commands from discord.ext import commands from app.internal import guild_gate from app.internal.c2_client import c2 class DRBCommands(commands.Cog): drb = app_commands.Group( name="drb", description="Set up DRB in this server.", guild_only=True, default_permissions=discord.Permissions(manage_guild=True), ) def __init__(self, bot: commands.Bot): self.bot = bot @drb.command(name="link", description="Link this server to your DRB organization.") @app_commands.describe(code="The code from DRB → Settings → Organization → Discord servers.") async def link(self, interaction: discord.Interaction, code: str): await interaction.response.defer(ephemeral=True) # default_permissions is only the default — a server admin can grant # the command to anyone under Integrations. Linking decides which # organization's radio this whole server gets, so hold the line here. perms = getattr(interaction.user, "guild_permissions", None) if not perms or not perms.manage_guild: await interaction.followup.send("Only members with **Manage Server** can link this server.", ephemeral=True) return ok, body = await c2.redeem_guild_link( interaction.guild_id, code, str(interaction.user.id), interaction.guild.name if interaction.guild else None, ) guild_gate.forget(interaction.guild_id) radio = self.bot.get_cog("RadioCommands") if radio is not None: radio._overview.pop(interaction.guild_id, None) if not ok: await interaction.followup.send(body.get("detail") or "DRB could not link this server.", ephemeral=True) return org = body.get("org_name") or "your DRB organization" if body.get("already_linked"): text = f"This server was already linked to **{org}**. Nothing changed." else: text = (f"This server is now linked to **{org}**.\n" "`/join`, `/leave` and `/status` now act for that organization only.") await interaction.followup.send(text, ephemeral=True) async def setup(bot: commands.Bot): await bot.add_cog(DRBCommands(bot))