Skip to content

Commit

Permalink
feat(interaction): add path field
Browse files Browse the repository at this point in the history
  • Loading branch information
sasial-dev committed Feb 9, 2024
1 parent 9d037a1 commit acfdffb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/server/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class ServerDispatcher extends BaseDispatcher {
} catch (err) {
this.handleError(player, text, err);
interactionData = {
path: commandPath,
executor: player,
text,
reply: {
Expand All @@ -52,7 +53,7 @@ export class ServerDispatcher extends BaseDispatcher {
return this.executeCommand(path, executor, text).catch((err) => {
this.handleError(executor, text, err);

const interaction = new CommandInteraction(executor, text);
const interaction = new CommandInteraction(path, executor, text);
interaction.error("An error occurred.");
return interaction;
});
Expand Down
2 changes: 1 addition & 1 deletion src/shared/core/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class BaseDispatcher {
text: string,
) {
const command = this.registry.getCommand(path);
const interaction = new CommandInteraction(executor, text);
const interaction = new CommandInteraction(path, executor, text);

if (command === undefined) {
interaction.error("Command not found.");
Expand Down
3 changes: 3 additions & 0 deletions src/shared/core/interaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CommandInteractionData, CommandReply } from "../types";
import { CommandPath } from "./path";

/**
* A data structure containing the executor of a command, the
Expand All @@ -9,6 +10,7 @@ export class CommandInteraction {
private replyData?: CommandReply;

constructor(
readonly path: CommandPath,
readonly executor: Player,
readonly text: string,
) {}
Expand All @@ -22,6 +24,7 @@ export class CommandInteraction {
*/
getData(): CommandInteractionData {
return {
path: this.path,
executor: this.executor,
text: this.text,
reply: this.replyData,
Expand Down
2 changes: 2 additions & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Result } from "@rbxts/rust-classes";
import { t } from "@rbxts/t";
import { CommandInteraction } from "./core/interaction";
import { CommandPath } from "./core/path";

export type CommandGuard = (
runNext: () => void,
Expand Down Expand Up @@ -53,6 +54,7 @@ export interface CommandReply {
}

export interface CommandInteractionData {
path: CommandPath;
executor: Player;
text: string;
reply?: CommandReply;
Expand Down

0 comments on commit acfdffb

Please sign in to comment.