const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('federation') .setDescription('Manage cross-server role sync') .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) .addSubcommand(subcommand => subcommand .setName('link') .setDescription('Link a role for cross-server syncing') .addRoleOption(option => option.setName('role') .setDescription('Role to sync across realms') .setRequired(true) ) ) .addSubcommand(subcommand => subcommand .setName('unlink') .setDescription('Remove a role from cross-server syncing') .addRoleOption(option => option.setName('role') .setDescription('Role to remove from sync') .setRequired(true) ) ) .addSubcommand(subcommand => subcommand .setName('list') .setDescription('List all linked roles') ), async execute(interaction, supabase, client) { const subcommand = interaction.options.getSubcommand(); if (subcommand === 'link') { const role = interaction.options.getRole('role'); if (client.federationMappings.has(role.id)) { return interaction.reply({ content: `${role} is already linked for federation sync.`, ephemeral: true, }); } client.federationMappings.set(role.id, { name: role.name, guildId: interaction.guild.id, createdAt: Date.now(), }); const embed = new EmbedBuilder() .setColor(0x00ff00) .setTitle('Role Linked') .setDescription(`${role} will now sync across all realm servers.`) .addFields( { name: 'Role Name', value: role.name, inline: true }, { name: 'Source Guild', value: interaction.guild.name, inline: true } ) .setFooter({ text: 'Users with this role will receive it in all connected realms.' }) .setTimestamp(); await interaction.reply({ embeds: [embed] }); client.sendAlert(`Federation: Role ${role.name} linked by ${interaction.user.tag}`); } if (subcommand === 'unlink') { const role = interaction.options.getRole('role'); if (!client.federationMappings.has(role.id)) { return interaction.reply({ content: `${role} is not linked for federation sync.`, ephemeral: true, }); } client.federationMappings.delete(role.id); const embed = new EmbedBuilder() .setColor(0xff0000) .setTitle('Role Unlinked') .setDescription(`${role} will no longer sync across realm servers.`) .setTimestamp(); await interaction.reply({ embeds: [embed] }); client.sendAlert(`Federation: Role ${role.name} unlinked by ${interaction.user.tag}`); } if (subcommand === 'list') { const mappings = [...client.federationMappings.entries()]; if (mappings.length === 0) { return interaction.reply({ content: 'No roles are currently linked for federation sync.', ephemeral: true, }); } const roleList = mappings.map(([roleId, data]) => `<@&${roleId}> - Added `).join('\n'); const embed = new EmbedBuilder() .setColor(0x7c3aed) .setTitle('Federation Linked Roles') .setDescription(roleList) .setFooter({ text: `${mappings.length} role(s) linked` }) .setTimestamp(); await interaction.reply({ embeds: [embed], ephemeral: true }); } }, };