MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / isCommandEnabledInConfig

Function isCommandEnabledInConfig

src/services/commandAccessService.js:111–142  ·  view source on GitHub ↗
(config, commandName, category)

Source from the content-addressed store, hash-verified

109}
110
111export function isCommandEnabledInConfig(config, commandName, category) {
112 const normalizedName = String(commandName || '').toLowerCase();
113
114 // Check if it's a subcommand (contains space)
115 const isSubcommand = normalizedName.includes(' ');
116 const baseCommand = isSubcommand ? normalizedName.split(' ')[0] : normalizedName;
117
118 // Protected commands (only applies to base commands, not subcommands)
119 if (!isSubcommand && isProtectedCommand(baseCommand)) {
120 return true;
121 }
122
123 const disabledCommands = normalizeToggleRecord(config?.disabledCommands);
124 const disabledCategories = normalizeToggleRecord(config?.disabledCategories);
125
126 // Check if the specific command/subcommand is disabled
127 if (disabledCommands[normalizedName]) {
128 return false;
129 }
130
131 // For subcommands, also check if the base command is disabled
132 if (isSubcommand && disabledCommands[baseCommand]) {
133 return false;
134 }
135
136 // Check if the category is disabled
137 if (disabledCategories[normalizeCategoryKey(category)]) {
138 return false;
139 }
140
141 return true;
142}
143
144export async function isCommandEnabled(client, guildId, commandName, category = null) {
145 const config = await getGuildConfig(client, guildId);

Callers 3

isCommandEnabledFunction · 0.85
getCommandAccessSnapshotFunction · 0.85

Calls 3

normalizeCategoryKeyFunction · 0.90
isProtectedCommandFunction · 0.85
normalizeToggleRecordFunction · 0.85

Tested by

no test coverage detected