-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
29e0aee
commit 6bd60f1
Showing
12 changed files
with
159 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Command, Subcommand, type CommandInteraction } from "carbon"; | ||
import { sleep } from "./index.js"; | ||
|
||
class Sub1 extends Command { | ||
name = "sub1" | ||
description = "Subcommand 1" | ||
defer = true | ||
|
||
async run(interaction: CommandInteraction) { | ||
await sleep(3000) | ||
interaction.reply({ content: "Subcommand 1" }) | ||
} | ||
} | ||
|
||
class Sub2 extends Command { | ||
name = "sub2" | ||
description = "Subcommand 2" | ||
defer = true | ||
|
||
async run(interaction: CommandInteraction) { | ||
await sleep(3000) | ||
interaction.reply({ content: "Subcommand 2" }) | ||
} | ||
} | ||
|
||
|
||
export class Subc extends Subcommand { | ||
name = "subc" | ||
description = "Subcommands!" | ||
defer = true | ||
|
||
subcommands = [new Sub1(), new Sub2()] | ||
} |
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,40 +1,19 @@ | ||
import type { RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord-api-types/v10" | ||
import { ApplicationCommandType } from "discord-api-types/v10" | ||
import type { CommandInteraction } from "../structures/CommandInteraction.js" | ||
import { BaseCommand } from "../structures/_BaseCommand.js" | ||
|
||
/** | ||
* Represents a command that the user creates | ||
* Represents a standard command that the user creates | ||
*/ | ||
export abstract class Command { | ||
/** | ||
* The name of the command (e.g. "ping" for /ping) | ||
*/ | ||
abstract name: string | ||
/** | ||
* A description of the command | ||
*/ | ||
abstract description: string | ||
/** | ||
* Whether the command response should be automatically deferred | ||
*/ | ||
defer = false | ||
/** | ||
* Whether the command response should be ephemeral | ||
*/ | ||
ephemeral = false | ||
|
||
export abstract class Command extends BaseCommand { | ||
type = ApplicationCommandType.ChatInput | ||
/** | ||
* The function that is called when the command is ran | ||
* @param interaction The interaction that triggered the command | ||
*/ | ||
abstract run(interaction: CommandInteraction): Promise<void> | ||
|
||
/** | ||
* Serializes the command into a JSON object that can be sent to Discord | ||
*/ | ||
serialize() { | ||
return { | ||
name: this.name, | ||
description: this.description | ||
} satisfies RESTPostAPIChatInputApplicationCommandsJSONBody | ||
serializeOptions() { | ||
return [] | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type APIApplicationCommandBasicOption, ApplicationCommandType } from "discord-api-types/v10"; | ||
import { BaseCommand } from "../structures/_BaseCommand.js"; | ||
import type { Command } from "./Command.js"; | ||
|
||
/** | ||
* Represents a subcommand command that the user creates. | ||
* You make this instead of a {@link Command} class when you want to have subcommands in your options. | ||
*/ | ||
export abstract class Subcommand extends BaseCommand { | ||
type = ApplicationCommandType.ChatInput | ||
abstract subcommands: Command[] | ||
|
||
serializeOptions(): APIApplicationCommandBasicOption[] { | ||
return this.subcommands.map((subcommand) => subcommand.serialize()) as unknown as APIApplicationCommandBasicOption[]; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { ApplicationCommandType, RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10" | ||
|
||
/** | ||
* Represents the base data of a command that the user creates | ||
*/ | ||
export abstract class BaseCommand { | ||
/** | ||
* The name of the command (e.g. "ping" for /ping) | ||
*/ | ||
abstract name: string | ||
/** | ||
* A description of the command | ||
*/ | ||
abstract description: string | ||
/** | ||
* Whether the command response should be automatically deferred | ||
*/ | ||
defer = false | ||
/** | ||
* Whether the command response should be ephemeral | ||
*/ | ||
ephemeral = false | ||
/** | ||
* The type of the command | ||
*/ | ||
abstract type: ApplicationCommandType | ||
|
||
/** | ||
* Serializes the command into a JSON object that can be sent to Discord | ||
*/ | ||
serialize() { | ||
const data: RESTPostAPIApplicationCommandsJSONBody = { | ||
name: this.name, | ||
description: this.description, | ||
type: this.type, | ||
options: this.serializeOptions() | ||
} | ||
|
||
return data | ||
} | ||
|
||
abstract serializeOptions(): RESTPostAPIApplicationCommandsJSONBody["options"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const Omit = <T, K extends keyof T>(Class: new () => T, keys: K[]): new () => Omit<T, typeof keys[number]> => Class; |
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