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:
38
apps/bot/src/command-gate-rules.ts
Normal file
38
apps/bot/src/command-gate-rules.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user