(command: string)
| 33 | * Load a command into memory. |
| 34 | */ |
| 35 | export async function load(command: string): Promise< |
| 36 | | { |
| 37 | props: ExtCommand; |
| 38 | name: string; |
| 39 | } |
| 40 | | undefined |
| 41 | > { |
| 42 | log("main", `Loading command from ${command}...`); |
| 43 | const { default: props } = (await import(`${command}?v=${queryValue}`)) as { default: ExtCommand }; |
| 44 | queryValue++; |
| 45 | |
| 46 | const relPath = relative(cmdPath, command); |
| 47 | const commandArray = relPath.split("/"); |
| 48 | let commandName = commandArray.at(-1)!.split(".")[0]; |
| 49 | const category = commandArray[0]; |
| 50 | const subPath = commandArray.slice(1, -1); |
| 51 | |
| 52 | if (!(props?.prototype instanceof Command)) { |
| 53 | log("warn", `Command ${command} is invalid, skipping...`); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | if (category === "message" || category === "user") { |
| 58 | const nameStringArray = commandName.split("-"); |
| 59 | for (const index of nameStringArray.keys()) { |
| 60 | nameStringArray[index] = nameStringArray[index].charAt(0).toUpperCase() + nameStringArray[index].slice(1); |
| 61 | } |
| 62 | commandName = nameStringArray.join(" "); |
| 63 | } |
| 64 | |
| 65 | let fullCommandName = commandName; |
| 66 | if (subPath.length > 0) fullCommandName = `${subPath.join(" ")} ${commandName}`; |
| 67 | |
| 68 | if (blacklist.includes(subPath[0]) || blacklist.includes(fullCommandName)) { |
| 69 | log("warn", `Skipped loading blacklisted command ${command}...`); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | props.init(); |
| 74 | props.baseCommand = false; |
| 75 | props.category = category; |
| 76 | props.type = Constants.ApplicationCommandTypes.CHAT_INPUT; |
| 77 | props.params = parseFlags(props.flags); |
| 78 | props.flags = extendFlags(props.flags, fullCommandName); |
| 79 | |
| 80 | paths.set(fullCommandName, command); |
| 81 | |
| 82 | if (category === "message") { |
| 83 | messageCommands.set(fullCommandName, props); |
| 84 | props.type = Constants.ApplicationCommandTypes.MESSAGE; |
| 85 | } else if (category === "user") { |
| 86 | userCommands.set(fullCommandName, props); |
| 87 | props.type = Constants.ApplicationCommandTypes.USER; |
| 88 | } else { |
| 89 | const subdir = relPath.split(".")[0]; |
| 90 | const resolved = resolve(cmdPath, subdir); |
| 91 | |
| 92 | let files; |
no test coverage detected