diff options
Diffstat (limited to 'core/CommandAction.ts')
-rw-r--r-- | core/CommandAction.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/core/CommandAction.ts b/core/CommandAction.ts new file mode 100644 index 0000000..ccc997b --- /dev/null +++ b/core/CommandAction.ts @@ -0,0 +1,46 @@ +import { + CommandInteraction, + CommandInteractionOptionResolver, + MessageComponentInteraction, + ModalSubmitInteraction +} from "discord.js"; + +class CommandName extends String { + constructor(...args) { + super(...args); + } +} + +export class CommandAction { + private readonly command: CommandName; + private readonly args: object | CommandInteractionOptionResolver; + private readonly interaction: CommandInteraction | ModalSubmitInteraction | MessageComponentInteraction; + + constructor(command: string, interaction: CommandInteraction | ModalSubmitInteraction | MessageComponentInteraction, args?: object) { + this.command = new CommandName(command); + this.interaction = interaction; + if (args) { + this.args = args; + } else if (interaction instanceof CommandInteraction) { + this.args = interaction.options; + } else { + this.args = {}; + } + } + + public getCommand(): CommandName { + return this.command; + } + + public getInteraction(): CommandInteraction | ModalSubmitInteraction | MessageComponentInteraction { + return this.interaction; + } + + public getArgument(argument: string): any { + if (this.args instanceof CommandInteractionOptionResolver) { + return this.args.get(argument, true).value; + } else { + return this.args[argument]; + } + } +}
\ No newline at end of file |