Skip to content

Commit

Permalink
fix: do not split string before sending over the network
Browse files Browse the repository at this point in the history
  • Loading branch information
sasial-dev committed Feb 11, 2024
1 parent 7049038 commit a673c0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/client/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class ServerCommand extends BaseCommand {
return new ServerCommand(registry, path, options);
}

execute(interaction: CommandInteraction, args: string[]) {
execute(interaction: CommandInteraction, text: string) {
const [success, data] = pcall(() =>
Remotes.Execute.InvokeServer(this.path.toString(), args.join(" ")),
Remotes.Execute.InvokeServer(this.path.toString(), text),
);

if (!success) {
Expand Down
11 changes: 7 additions & 4 deletions src/shared/core/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "../types";
import { ObjectUtil, ReadonlyDeepObject } from "../util/data";
import { MetadataReflect } from "../util/reflect";
import { splitStringBySpace } from "../util/string";
import { MetadataKey } from "./decorators";
import { CommandInteraction } from "./interaction";
import { ImmutableCommandPath } from "./path";
Expand Down Expand Up @@ -86,7 +87,7 @@ export abstract class BaseCommand {
}
}

abstract execute(interaction: CommandInteraction, args: string[]): unknown;
abstract execute(interaction: CommandInteraction, text: string): unknown;

getPath() {
return this.path;
Expand Down Expand Up @@ -133,14 +134,14 @@ export class ExecutableCommand extends BaseCommand {
);
}

execute(interaction: CommandInteraction, args: string[]) {
execute(interaction: CommandInteraction, text: string) {
for (const guard of this.guards) {
if (!guard(interaction)) return;
}

if (interaction.isReplyReceived()) return;

const transformedArgs = this.transformArgs(args, interaction);
const transformedArgs = this.transformArgs(text, interaction);
if (transformedArgs.isErr()) {
interaction.error(transformedArgs.unwrapErr());
return;
Expand All @@ -154,9 +155,11 @@ export class ExecutableCommand extends BaseCommand {
}

transformArgs(
args: string[],
text: string,
interaction: CommandInteraction,
): Result<unknown[], string> {
const args = splitStringBySpace(text);

const argOptions = this.options.arguments;
if (argOptions === undefined || argOptions.isEmpty()) {
return Result.ok([]);
Expand Down
4 changes: 1 addition & 3 deletions src/shared/core/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export abstract class BaseDispatcher {
return interaction;
}

const args = splitStringBySpace(text);

command.execute(interaction, args);
command.execute(interaction, text);
if (!interaction.isReplyReceived()) {
interaction.reply(DEFAULT_REPLY_TEXT);
}
Expand Down

0 comments on commit a673c0b

Please sign in to comment.