AeThex-Bot-Master/aethex-bot/commands/refresh-roles.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

87 lines
3.1 KiB
JavaScript

const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
const { assignRoleByArm, getUserArm } = require("../utils/roleManager");
const { getServerMode, EMBED_COLORS } = require("../utils/modeHelper");
module.exports = {
data: new SlashCommandBuilder()
.setName("refresh-roles")
.setDescription(
"Refresh your Discord roles based on your current AeThex settings",
),
async execute(interaction, supabase, client) {
if (!supabase) {
return interaction.reply({ content: "This feature requires Supabase to be configured.", ephemeral: true });
}
const mode = await getServerMode(supabase, interaction.guildId);
if (mode === 'standalone') {
const embed = new EmbedBuilder()
.setColor(EMBED_COLORS.standalone)
.setTitle('🏠 Standalone Mode')
.setDescription('Role syncing is disabled in standalone mode.\n\nThis server operates independently without AeThex role federation.\n\nUse `/config mode` to switch to federated mode.');
return interaction.reply({ embeds: [embed], ephemeral: true });
}
await interaction.deferReply({ ephemeral: true });
try {
// Check if user is linked
const { data: link } = await supabase
.from("discord_links")
.select("primary_arm")
.eq("discord_id", interaction.user.id)
.maybeSingle();
if (!link) {
const embed = new EmbedBuilder()
.setColor(0xff6b6b)
.setTitle("❌ Not Linked")
.setDescription(
"You must link your Discord account to AeThex first.\nUse `/verify` to get started.",
);
return await interaction.editReply({ embeds: [embed] });
}
if (!link.primary_arm) {
const embed = new EmbedBuilder()
.setColor(0xffaa00)
.setTitle("⚠️ No Realm Set")
.setDescription(
"You haven't set your primary realm yet.\nUse `/set-realm` to choose one.",
);
return await interaction.editReply({ embeds: [embed] });
}
// Assign role based on current primary arm
const roleAssigned = await assignRoleByArm(
interaction.guild,
interaction.user.id,
link.primary_arm,
supabase,
);
const embed = new EmbedBuilder()
.setColor(roleAssigned ? 0x00ff00 : 0xffaa00)
.setTitle("✅ Roles Refreshed")
.setDescription(
roleAssigned
? `Your Discord roles have been synced with your AeThex account.\n\nPrimary Realm: **${link.primary_arm}**`
: `Your roles could not be automatically assigned.\n\nPrimary Realm: **${link.primary_arm}**\n\n⚠️ Please contact an admin to set up the role mapping for this server.`,
);
await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error("Refresh-roles command error:", error);
const embed = new EmbedBuilder()
.setColor(0xff0000)
.setTitle("❌ Error")
.setDescription("Failed to refresh roles. Please try again.");
await interaction.editReply({ embeds: [embed] });
}
},
};