Add global command channel rules and enhance command handling

- Introduced global command channel whitelist and blacklist in the GuildSettings model for improved command access control.
- Implemented command gate logic in the command routing to handle channel and role restrictions, providing user feedback for denied commands.
- Enhanced the CommandsManager component to support global rules and channel/role selection, improving the user interface for managing command permissions.
- Updated localization files to include new keys for global command rules and related messages, ensuring clarity in user interactions.
This commit is contained in:
TheOnlyMace
2026-07-22 20:26:40 +02:00
parent 0fb8195236
commit d31660f813
24 changed files with 963 additions and 185 deletions

View File

@@ -601,10 +601,10 @@ export type GuildBackupCreateDashboard = z.infer<typeof GuildBackupCreateDashboa
export const CommandOverrideDashboardSchema = z.object({
commandName: z.string().min(1).max(100),
enabled: z.boolean(),
allowedRoleIds: z.array(z.string()),
deniedRoleIds: z.array(z.string()),
allowedChannelIds: z.array(z.string()),
deniedChannelIds: z.array(z.string()),
allowedRoleIds: z.array(SnowflakeSchema),
deniedRoleIds: z.array(SnowflakeSchema),
allowedChannelIds: z.array(SnowflakeSchema),
deniedChannelIds: z.array(SnowflakeSchema),
cooldownSeconds: z.number().int().nonnegative().nullable()
});
export type CommandOverrideDashboard = z.infer<typeof CommandOverrideDashboardSchema>;
@@ -612,14 +612,42 @@ export type CommandOverrideDashboard = z.infer<typeof CommandOverrideDashboardSc
export const CommandOverrideDashboardUpsertSchema = z.object({
commandName: z.string().min(1).max(100),
enabled: z.boolean().default(true),
allowedRoleIds: z.array(z.string()).default([]),
deniedRoleIds: z.array(z.string()).default([]),
allowedChannelIds: z.array(z.string()).default([]),
deniedChannelIds: z.array(z.string()).default([]),
allowedRoleIds: z.array(SnowflakeSchema).default([]),
deniedRoleIds: z.array(SnowflakeSchema).default([]),
allowedChannelIds: z.array(SnowflakeSchema).default([]),
deniedChannelIds: z.array(SnowflakeSchema).default([]),
cooldownSeconds: z.number().int().nonnegative().nullable().optional()
});
export type CommandOverrideDashboardUpsert = z.infer<typeof CommandOverrideDashboardUpsertSchema>;
export const CommandGlobalRulesSchema = z.object({
allowedChannelIds: z.array(SnowflakeSchema),
deniedChannelIds: z.array(SnowflakeSchema)
});
export type CommandGlobalRules = z.infer<typeof CommandGlobalRulesSchema>;
export const CommandGlobalRulesPatchSchema = CommandGlobalRulesSchema.partial().refine(
(value) => Object.keys(value).length > 0,
{ message: 'At least one field is required' }
);
export type CommandGlobalRulesPatch = z.infer<typeof CommandGlobalRulesPatchSchema>;
export const DiscordChannelOptionSchema = z.object({
id: SnowflakeSchema,
name: z.string(),
type: z.number().int(),
parentId: SnowflakeSchema.nullable().optional()
});
export type DiscordChannelOption = z.infer<typeof DiscordChannelOptionSchema>;
export const DiscordRoleOptionSchema = z.object({
id: SnowflakeSchema,
name: z.string(),
color: z.number().int(),
position: z.number().int()
});
export type DiscordRoleOption = z.infer<typeof DiscordRoleOptionSchema>;
/**
* Known slash command names, aggregated from every module's
* `command-definitions.ts` (`SlashCommandBuilder#setName`). Used by the