Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not split string before sending over the network #20

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading