AeThex-Bot-Master/aethex-bot/commands/federation.js
sirpiglr 42c24762b0 Add optional Supabase integration and improve command reliability
Implement guards for Supabase-dependent commands, refine error handling, and introduce feed synchronization capabilities.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e72fc1b7-94bd-4d6c-801f-cbac2fae245c
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 48ccfc2d-e27b-4e3b-b0d2-25bdb3ece9c8
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/e72fc1b7-94bd-4d6c-801f-cbac2fae245c/NXjYRWJ
Replit-Helium-Checkpoint-Created: true
2025-12-07 23:19:50 +00:00

112 lines
3.5 KiB
JavaScript

const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('federation')
.setDescription('Manage cross-server role synchronization')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.addSubcommand(subcommand =>
subcommand
.setName('link')
.setDescription('Link a role for cross-server sync')
.addRoleOption(option =>
option.setName('role')
.setDescription('Role to sync across servers')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('unlink')
.setDescription('Remove a role from sync')
.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');
client.federationMappings.set(role.id, {
name: role.name,
guildId: interaction.guildId,
guildName: interaction.guild.name,
linkedAt: Date.now(),
});
const embed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Role Linked')
.setDescription(`${role} is now linked for federation sync.`)
.addFields(
{ name: 'Role ID', value: role.id, inline: true },
{ name: 'Server', value: interaction.guild.name, inline: true }
)
.setTimestamp();
await interaction.reply({ embeds: [embed] });
}
if (subcommand === 'unlink') {
const role = interaction.options.getRole('role');
if (client.federationMappings.has(role.id)) {
client.federationMappings.delete(role.id);
const embed = new EmbedBuilder()
.setColor(0xff6600)
.setTitle('Role Unlinked')
.setDescription(`${role} has been removed from federation sync.`)
.setTimestamp();
await interaction.reply({ embeds: [embed] });
} else {
const embed = new EmbedBuilder()
.setColor(0xff0000)
.setTitle('Not Found')
.setDescription(`${role} is not currently linked.`)
.setTimestamp();
await interaction.reply({ embeds: [embed], ephemeral: true });
}
}
if (subcommand === 'list') {
const mappings = [...client.federationMappings.entries()];
if (mappings.length === 0) {
const embed = new EmbedBuilder()
.setColor(0x7c3aed)
.setTitle('Federation Roles')
.setDescription('No roles are currently linked for federation sync.\nUse `/federation link` to add roles.')
.setTimestamp();
await interaction.reply({ embeds: [embed] });
return;
}
const roleList = mappings.map(([roleId, data]) =>
`<@&${roleId}> - ${data.guildName}`
).join('\n');
const embed = new EmbedBuilder()
.setColor(0x7c3aed)
.setTitle('Federation Roles')
.setDescription(roleList)
.setFooter({ text: `${mappings.length} role(s) linked` })
.setTimestamp();
await interaction.reply({ embeds: [embed] });
}
},
};