Skip to content

Commit

Permalink
feat!: rewrite commands to use DJS builders, allow guild commands and…
Browse files Browse the repository at this point in the history
… create CommandDeployer
  • Loading branch information
Amgelo563 committed May 22, 2024
1 parent 1182075 commit 9e9e96b
Show file tree
Hide file tree
Showing 83 changed files with 1,852 additions and 1,970 deletions.
37 changes: 14 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,26 @@ satisfy the respective interface.

### Commands

* Complete application command support, with Standalone commands, Parent commands, Subcommands and SubCommand Groups.
* Complete application command support (slash commands or context menus).
* Add, remove and update commands (including their children) in runtime.
* Route interactions (buttons, select menus and modal submits) to a command, with an easy API that allows storing and
retrieving extra data from the customId.
* Command and SubCommand option autocompletion support.
* Discord's context menus ([User](https://discord.com/developers/docs/interactions/application-commands#user-commands)
and [Message](https://discord.com/developers/docs/interactions/application-commands#message-commands) commands)
support.
* Replace the interaction listeners with your own for even more custom command handling.
* Deny command executions via `CommandMiddlewares` (for general command filtering) or `CommandFilters` (for
command-specific filtering).
* Handle uncaught command errors with a provided `ErrorHandler`.
* Create components (buttons, select menus and modal submits) that trigger a command, with an easy API that allows
storing and retrieving extra data from the customId.
* Intercept command execution with `CommandMiddlewares` (for general filtering) or `CommandFilters` (for command-specific filtering).
* Use the `CommandExecutionMeta` to provide metadata to your commands from your filter, middleware or subscriber.
* Subscribe to meta events in the `CommandEventBus` like command runs.
* Completely override the command interaction listeners with your own for even more custom interaction handling.
* Handle uncaught command errors on a built-in `ErrorHandler`.

### Events

* Register multiple `EventBuses`, each with their own execution logic.
* Subscribe (and unsubscribe) to events on `EventBuses` via `EventSubscriber` objects or callback functions.
* Enforce emitting and receiving events type safely, including your custom `EventBuses`.
* Use the built-in `BotEventBus` to subscribe to `NyxBot` wide events, such as `botStop`, `commandAdd`, `scheduleRun`,
and many more.
* Store event metadata across subscribers to share information about the event itself.
* The metadata allows marking events as handled so the `EventMiddleware` removes subscribers that don't want to
receive such events.
* Specify an `EventDispatcher` to change the way subscribers are called. By default, two are included:
* `EventBus` and `EventSubscriber` based event handling.
* Enforced type safety when emitting and receiving events when using the provided or your custom `EventBuses`.
* Store event metadata to share information about the event itself across subscribers.
* Specify an `EventDispatcher` to change the way subscribers are called. By default, either:
* The `AsyncEventDispatcher` which allows a concurrency limit.
* The `SyncEventDispatcher` which allows a sync timeout limit before calling the next subscriber.
* Deny subscriber executions via `EventMiddlewares` (for general filtering) or `SubscriberFilters` (for subscriber
specific filtering).
* Handle subscriber errors via a flexible `ErrorHandler`.
* Intercept subscriber execution with `EventMiddlewares` (for general filtering) or `SubscriberFilters` (for subscriber-specific filtering).
* Handle uncaught subscriber errors on a built-in `ErrorHandler`.

### Schedules

Expand Down
4 changes: 0 additions & 4 deletions apps/docs/docs/features/commands/command-customid-codec.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ You can create a command custom ID codec by either:
```

```ts
import { DefaultCommandCustomIdCodec } from '@nyx-discord/framework';

class MyCommandCustomIdCodec extends DefaultCommandCustomIdCodec {
// ...
}
Expand All @@ -231,8 +229,6 @@ const myBot = Bot.create((bot) => ({
```

```ts
import { CommandCustomIdCodec } from '@nyx-discord/core';

class MyCommandCustomIdCodec implements CommandCustomIdCodec {
// ...
}
Expand Down
53 changes: 53 additions & 0 deletions apps/docs/docs/features/commands/command-deployer.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: 🪐 Command Deployer
---

The `CommandDeployer` is the object responsible for deploying commands. It's stored by a `CommandManager`, and you can get
it via `CommandManager#getDeployer()`.

You can't modify the repository directly since the `CommandManager` returns a `ReadonlyCommandDeployer` type, but the
hidden methods are available at the `CommandManager`. This is because adding, removing and updating a command needs more
logic than just modifying the repository, and the manager is responsible for coordinating this.

## 👷 Creation

You can create a command deployer by either:

* Extending `DefaultCommandDeployer` from `@framework` (recommended).
* Implementing the `CommandDeployer` interface from `@core`.

```mdx-code-block
<Tabs>
<TabItem value="Extending DefaultCommandDeployer">
```

```ts
class MyCommandDeployer extends DefaultCommandDeployer {
// ...
}

const myBot = Bot.create((bot) => ({
commands: DefaultCommandManager.create(bot, client, clientBus, { deployer: myDeployer }),
}))
```

```mdx-code-block
</TabItem>
<TabItem value="Implementing CommandDeployer">
```

```ts
class MyCommandDeployer implements CommandDeployer {
// ...
}

const myBot = Bot.create((bot) => ({
commands: DefaultCommandManager.create(bot, client, clientBus, { deployer: myDeployer }),
}))
```

```mdx-code-block
</TabItem>
</Tabs>
```

4 changes: 0 additions & 4 deletions apps/docs/docs/features/commands/command-executor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ You can create a custom command executor by either:
```

```ts
import { DefaultCommandExecutor } from '@nyx-discord/framework';

class MyCommandExecutor extends DefaultCommandExecutor {
// ...
}
Expand All @@ -45,8 +43,6 @@ const myBot = Bot.create((bot) => ({
```

```ts
import { CommandExecutor } from '@nyx-discord/core';

class MyCommandExecutor implements CommandExecutor {
// ...
}
Expand Down
4 changes: 0 additions & 4 deletions apps/docs/docs/features/commands/command-interception.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ You can create your own middleware by either:
```

```ts
import { AbstractCommandMiddleware } from '@nyx-discord/framework';

class MyCommandMiddleware extends AbstractCommandMiddleware {
public check(command: ExecutableCommand<CommandData>, ...args: CommandExecutionArgs): MiddlewareResponse {
return this.true();
Expand All @@ -77,8 +75,6 @@ bot.commands.getExecutor().getMiddleware().add(middleware);
```

```ts
import { CommandMiddleware } from '@nyx-discord/core';

class MyCommandMiddleware implements CommandMiddleware {
// ...
}
Expand Down
12 changes: 6 additions & 6 deletions apps/docs/docs/features/commands/command-manager.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ The `CommandManager` is the object that holds together the nyx event system.

It consists of:

* `CommandSubscriberContainer` for managing command-related subscribers.
* `CommandCustomIdProcessor` for processing command customIds.
* `CommandRouter` for routing command interactions to the respective command.
* `CommandExecutor` for executing concrete commands.
* `CommandRepository` for storing the registered commands and managing their registration at Discord.
* `EventBus` for emitting command related events.
* `CommandCustomIdCodec`: De/serializes commands names to/from customId strings, useful for creating message components that will trigger commands.
* `CommandResolver`: Resolves the command data that a given command interaction refers to.
* `CommandExecutor`: Executes command objects, checking its `CommandMiddlewareList` and passing any errors to its `ErrorHandler`.
* `CommandRepository`: Stores all the currently registered commands and their command application mappings. It's also responsible for registering commands at Discord.
* `CommandSubscriptionsContainer`: Stores the [📩 Event Subscribers](../events/event-subscriber) that are subscribed to the [👂 Client event bus](../events/event-manager.mdx#-client-event-bus) to listen for command interactions.
* `EventBus`: An [📣 Event Bus](../events/event-bus) that emits command related events.

As well as methods to interact with them.

Expand Down
Loading

0 comments on commit 9e9e96b

Please sign in to comment.