forked from SokoraDesu/Sokora
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
49 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,14 @@ | ||
import { file } from "bun"; | ||
import type { AutocompleteInteraction, CommandInteraction } from "discord.js"; | ||
import { join } from "path"; | ||
import { pathToFileURL } from "url"; | ||
import { capitalize } from "../utils/capitalize"; | ||
import { Event } from "../utils/types"; | ||
import { Commands } from "../handlers/commands"; | ||
import { Event } from "../utils/types"; | ||
|
||
async function getCommand( | ||
interaction: CommandInteraction | AutocompleteInteraction, | ||
options: any | ||
): Promise<any> { | ||
const commandName = capitalize(interaction.commandName)!; | ||
const subcommandName = capitalize(options.getSubcommand(false)); | ||
const commandGroupName = capitalize(options.getSubcommandGroup(false)); | ||
let commandImportPath = join( | ||
join(process.cwd(), "src", "commands"), | ||
`${ | ||
subcommandName | ||
? `${commandName.toLowerCase()}/${ | ||
commandGroupName ? `${commandGroupName}/${subcommandName}` : subcommandName | ||
}` | ||
: commandName | ||
}.ts` | ||
export default (async function run(interaction) { | ||
if (!interaction.isChatInputCommand() && !interaction.isAutocomplete()) return; | ||
const command = await new Commands(interaction.client).getCommand( | ||
interaction.commandName, | ||
interaction.options | ||
); | ||
if (!command) return; | ||
|
||
if (!(await file(commandImportPath).exists())) | ||
commandImportPath = join(join(process.cwd(), "src", "commands", `${commandName}.ts`)); | ||
|
||
return new (await import(pathToFileURL(commandImportPath).toString())).default(); | ||
} | ||
|
||
export default (async function run(interaction) { | ||
if (interaction.isChatInputCommand()) { | ||
console.log( | ||
new Commands(interaction.client).getCommand(interaction.commandName, interaction.options) | ||
); | ||
console.log(await getCommand(interaction, interaction.options)); | ||
const command = await getCommand(interaction, interaction.options); | ||
if (!command) return; | ||
if (command.deferred) await interaction.deferReply(); | ||
command.run(interaction); | ||
} else if (interaction.isAutocomplete()) { | ||
const command = await getCommand(interaction, interaction.options); | ||
if (!command) return; | ||
if (!command.autocomplete) return; | ||
command.autocomplete(interaction); | ||
} | ||
if (interaction.isChatInputCommand()) command.run(interaction); | ||
if (command.autocomplete) command.autocomplete(interaction); | ||
} as Event<"interactionCreate">); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters