- 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.
39 lines
840 B
TypeScript
39 lines
840 B
TypeScript
export type CommandGateReason =
|
|
| 'disabled'
|
|
| 'channel_denied'
|
|
| 'channel_not_allowed'
|
|
| 'role_denied'
|
|
| 'role_not_allowed'
|
|
| 'cooldown';
|
|
|
|
export function isChannelAllowed(
|
|
channelId: string | null,
|
|
allowed: string[],
|
|
denied: string[]
|
|
): CommandGateReason | null {
|
|
if (!channelId) {
|
|
return null;
|
|
}
|
|
if (denied.includes(channelId)) {
|
|
return 'channel_denied';
|
|
}
|
|
if (allowed.length > 0 && !allowed.includes(channelId)) {
|
|
return 'channel_not_allowed';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function isRoleAllowed(
|
|
roleIds: string[],
|
|
allowed: string[],
|
|
denied: string[]
|
|
): CommandGateReason | null {
|
|
if (denied.some((id) => roleIds.includes(id))) {
|
|
return 'role_denied';
|
|
}
|
|
if (allowed.length > 0 && !allowed.some((id) => roleIds.includes(id))) {
|
|
return 'role_not_allowed';
|
|
}
|
|
return null;
|
|
}
|