diff --git a/bot/lib/handlers/CommandHandler.ts b/bot/lib/handlers/CommandHandler.ts index eeb4b08..79c3e44 100644 --- a/bot/lib/handlers/CommandHandler.ts +++ b/bot/lib/handlers/CommandHandler.ts @@ -1,6 +1,7 @@ import { ChatInputCommandInteraction, MessageFlags } from "discord.js"; import { AuroraClient } from "@/lib/BotClient"; import { userService } from "@shared/modules/user/user.service"; +import { featureFlagsService } from "@shared/modules/feature-flags/feature-flags.service"; import { createErrorEmbed } from "@lib/embeds"; import { logger } from "@shared/lib/logger"; @@ -25,6 +26,37 @@ export class CommandHandler { return; } + // Check beta feature access + if (command.beta) { + const flagName = command.featureFlag || interaction.commandName; + let memberRoles: string[] = []; + + if (interaction.member && 'roles' in interaction.member) { + const roles = interaction.member.roles; + if (typeof roles === 'object' && 'cache' in roles) { + memberRoles = [...roles.cache.keys()]; + } else if (Array.isArray(roles)) { + memberRoles = roles; + } + } + + const hasAccess = await featureFlagsService.hasAccess(flagName, { + guildId: interaction.guildId!, + userId: interaction.user.id, + memberRoles, + }); + + if (!hasAccess) { + const errorEmbed = createErrorEmbed( + "This feature is currently in beta testing and not available to all users. " + + "Stay tuned for the official release!", + "Beta Feature" + ); + await interaction.reply({ embeds: [errorEmbed], flags: MessageFlags.Ephemeral }); + return; + } + } + // Ensure user exists in database try { await userService.getOrCreateUser(interaction.user.id, interaction.user.username); diff --git a/shared/lib/types.ts b/shared/lib/types.ts index 41dfaf5..00bca0b 100644 --- a/shared/lib/types.ts +++ b/shared/lib/types.ts @@ -7,6 +7,8 @@ export interface Command { execute: (interaction: ChatInputCommandInteraction) => Promise | void; autocomplete?: (interaction: AutocompleteInteraction) => Promise | void; category?: string; + beta?: boolean; + featureFlag?: string; } export interface Event {