MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / validateCommands

Function validateCommands

src/handlers/commandLoader.js:154–221  ·  view source on GitHub ↗
(commands)

Source from the content-addressed store, hash-verified

152}
153
154function validateCommands(commands) {
155 const validationErrors = [];
156
157 for (const cmd of commands) {
158 if (cmd.name && cmd.name.length > 32) {
159 validationErrors.push(`Command ${cmd.name} has name longer than 32 chars: "${cmd.name}" (${cmd.name.length} chars)`);
160 }
161 if (cmd.description && cmd.description.length > 110) {
162 validationErrors.push(`Command ${cmd.name} has description longer than 110 chars: "${cmd.description}" (${cmd.description.length} chars)`);
163 }
164
165 if (!cmd.options) {
166 continue;
167 }
168
169 for (const option of cmd.options) {
170 if (option.name && option.name.length > 32) {
171 validationErrors.push(`Command ${cmd.name} option ${option.name} has name longer than 32 chars: "${option.name}" (${option.name.length} chars)`);
172 }
173 if (option.description && option.description.length > 110) {
174 validationErrors.push(`Command ${cmd.name} option ${option.name} has description longer than 110 chars: "${option.description}" (${option.description.length} chars)`);
175 }
176
177 if (option.choices) {
178 for (const choice of option.choices) {
179 if (choice.name && choice.name.length > 110) {
180 validationErrors.push(`Command ${cmd.name} option ${option.name} choice ${choice.name} has name longer than 110 chars: "${choice.name}" (${choice.name.length} chars)`);
181 }
182 if (choice.value && choice.value.length > 100) {
183 validationErrors.push(`Command ${cmd.name} option ${option.name} choice ${choice.name} has value longer than 100 chars: "${choice.value}" (${choice.value.length} chars)`);
184 }
185 }
186 }
187
188 if (!option.options) {
189 continue;
190 }
191
192 for (const subOption of option.options) {
193 if (subOption.name && subOption.name.length > 32) {
194 validationErrors.push(`Command ${cmd.name} subcommand ${option.name} option ${subOption.name} has name longer than 32 chars: "${subOption.name}" (${subOption.name.length} chars)`);
195 }
196 if (subOption.description && subOption.description.length > 110) {
197 validationErrors.push(`Command ${cmd.name} subcommand ${option.name} option ${subOption.name} has description longer than 110 chars: "${subOption.description}" (${subOption.description.length} chars)`);
198 }
199
200 if (!subOption.choices) {
201 continue;
202 }
203
204 for (const choice of subOption.choices) {
205 if (choice.name && choice.name.length > 110) {
206 validationErrors.push(`Command ${cmd.name} subcommand ${option.name} option ${subOption.name} choice ${choice.name} has name longer than 110 chars: "${choice.name}" (${choice.name.length} chars)`);
207 }
208 if (choice.value && choice.value.length > 100) {
209 validationErrors.push(`Command ${cmd.name} subcommand ${option.name} option ${subOption.name} choice ${choice.name} has value longer than 100 chars: "${choice.value}" (${choice.value.length} chars)`);
210 }
211 }

Callers 2

registerGlobalCommandsFunction · 0.85
registerGuildCommandsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected