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:
32
apps/bot/src/command-gates.test.ts
Normal file
32
apps/bot/src/command-gates.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isChannelAllowed, isRoleAllowed } from './command-gate-rules.js';
|
||||
|
||||
describe('command-gates channel rules', () => {
|
||||
it('allows any channel when allow and deny are empty', () => {
|
||||
expect(isChannelAllowed('1', [], [])).toBeNull();
|
||||
});
|
||||
|
||||
it('blocks denied channels even when allow is empty', () => {
|
||||
expect(isChannelAllowed('1', [], ['1'])).toBe('channel_denied');
|
||||
});
|
||||
|
||||
it('requires membership when allow list is set', () => {
|
||||
expect(isChannelAllowed('1', ['2'], [])).toBe('channel_not_allowed');
|
||||
expect(isChannelAllowed('2', ['2'], [])).toBeNull();
|
||||
});
|
||||
|
||||
it('prefers deny over allow', () => {
|
||||
expect(isChannelAllowed('1', ['1'], ['1'])).toBe('channel_denied');
|
||||
});
|
||||
});
|
||||
|
||||
describe('command-gates role rules', () => {
|
||||
it('blocks when any denied role is present', () => {
|
||||
expect(isRoleAllowed(['a', 'b'], [], ['b'])).toBe('role_denied');
|
||||
});
|
||||
|
||||
it('requires an allowed role when allow list is set', () => {
|
||||
expect(isRoleAllowed(['a'], ['b'], [])).toBe('role_not_allowed');
|
||||
expect(isRoleAllowed(['a', 'b'], ['b'], [])).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user