AeThex-Bot-Master/aethex-bot/commands/federation.js
sirpiglr c2a34f398e Add server mode configuration and dynamic status updates
Introduces a new server mode configuration system (Federation/Standalone) with associated command changes, dynamic status rotation for the bot, and adds new commands and features.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: b08e6ba5-7498-4b9f-b1c9-7dc11b362ddd
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/R9PkDi8
Replit-Helium-Checkpoint-Created: true
2025-12-09 23:26:33 +00:00

132 lines
4.4 KiB
JavaScript

const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
const { getServerMode, EMBED_COLORS } = require('../utils/modeHelper');
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 mode = await getServerMode(supabase, interaction.guildId);
if (mode === 'standalone') {
const embed = new EmbedBuilder()
.setColor(EMBED_COLORS.standalone)
.setTitle('🏠 Standalone Mode')
.setDescription('Federation features are disabled in standalone mode.\n\nThis server operates independently and does not sync roles across the AeThex network.\n\nUse `/config mode` to switch to federated mode.');
return interaction.reply({ embeds: [embed], ephemeral: true });
}
const subcommand = interaction.options.getSubcommand();
if (subcommand === 'link') {
const role = interaction.options.getRole('role');
const mappingData = {
name: role.name,
guildId: interaction.guildId,
guildName: interaction.guild.name,
linkedAt: Date.now(),
};
client.federationMappings.set(role.id, mappingData);
if (client.saveFederationMapping) {
await client.saveFederationMapping(role.id, mappingData);
}
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);
if (client.deleteFederationMapping) {
await client.deleteFederationMapping(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] });
}
},
};