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

Function buildCommandRegistry

src/services/commandAccessService.js:29–95  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

27}
28
29export function buildCommandRegistry(client) {
30 const categories = new Map();
31
32 for (const command of client.commands.values()) {
33 if (!command?.data?.name) {
34 continue;
35 }
36
37 const category = command.category || 'Core';
38 const categoryKey = normalizeCategoryKey(category);
39
40 if (!categories.has(categoryKey)) {
41 categories.set(categoryKey, {
42 key: categoryKey,
43 folder: category,
44 displayName: formatCategoryName(category),
45 icon: getCategoryIcon(category),
46 commands: [],
47 });
48 }
49
50 // Add the main command
51 categories.get(categoryKey).commands.push({
52 name: command.data.name,
53 description: command.data.description || 'No description',
54 protected: PROTECTED_COMMANDS.has(command.data.name.toLowerCase()),
55 isSubcommand: false,
56 });
57
58 // Add subcommands if they exist
59 const commandJson = command.data.toJSON?.() || {};
60
61 for (const option of commandJson.options || []) {
62 if (option.type === 1) {
63 const subcommandName = `${command.data.name} ${option.name}`;
64 categories.get(categoryKey).commands.push({
65 name: subcommandName,
66 description: option.description || 'No description',
67 protected: false,
68 isSubcommand: true,
69 parentCommand: command.data.name,
70 });
71 }
72
73 if (option.type === 2) {
74 for (const sub of option.options || []) {
75 if (sub.type === 1) {
76 const subcommandName = `${command.data.name} ${option.name} ${sub.name}`;
77 categories.get(categoryKey).commands.push({
78 name: subcommandName,
79 description: sub.description || 'No description',
80 protected: false,
81 isSubcommand: true,
82 parentCommand: command.data.name,
83 });
84 }
85 }
86 }

Callers 7

buildCategoryChoicesFunction · 0.90
autocompleteFunction · 0.90
getCategoryRegistryFunction · 0.85
getCommandAccessSnapshotFunction · 0.85
resolveCommandTargetFunction · 0.85
resolveCategoryChoiceFunction · 0.85

Calls 5

normalizeCategoryKeyFunction · 0.90
formatCategoryNameFunction · 0.90
getCategoryIconFunction · 0.90
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected