(client, config)
| 154 | } |
| 155 | |
| 156 | export function getCommandAccessSnapshot(client, config) { |
| 157 | const registry = buildCommandRegistry(client); |
| 158 | const disabledCommands = normalizeToggleRecord(config?.disabledCommands); |
| 159 | const disabledCategories = normalizeToggleRecord(config?.disabledCategories); |
| 160 | |
| 161 | const categories = []; |
| 162 | |
| 163 | for (const category of registry.values()) { |
| 164 | const categoryDisabled = Boolean(disabledCategories[category.key]); |
| 165 | const enabledCommands = []; |
| 166 | const disabledCommandNames = []; |
| 167 | |
| 168 | for (const command of category.commands) { |
| 169 | const enabled = isCommandEnabledInConfig(config, command.name, category.folder); |
| 170 | if (enabled) { |
| 171 | enabledCommands.push(command.name); |
| 172 | } else { |
| 173 | disabledCommandNames.push(command.name); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | categories.push({ |
| 178 | ...category, |
| 179 | categoryDisabled, |
| 180 | enabledCount: enabledCommands.length, |
| 181 | disabledCount: disabledCommandNames.length, |
| 182 | totalCount: category.commands.length, |
| 183 | enabledCommands, |
| 184 | disabledCommandNames, |
| 185 | }); |
| 186 | } |
| 187 | |
| 188 | categories.sort((a, b) => a.displayName.localeCompare(b.displayName)); |
| 189 | |
| 190 | const totalCommands = categories.reduce((sum, category) => sum + category.totalCount, 0); |
| 191 | const enabledTotal = categories.reduce((sum, category) => sum + category.enabledCount, 0); |
| 192 | |
| 193 | return { |
| 194 | categories, |
| 195 | disabledCommands, |
| 196 | disabledCategories, |
| 197 | totalCommands, |
| 198 | enabledTotal, |
| 199 | disabledTotal: totalCommands - enabledTotal, |
| 200 | }; |
| 201 | } |
| 202 | |
| 203 | async function persistAccessConfig(client, guildId, updates, context = {}) { |
| 204 | return updateGuildConfig(client, guildId, updates, context); |
no test coverage detected