Skip to content

Commit

Permalink
Check for whitespace in command names
Browse files Browse the repository at this point in the history
  • Loading branch information
mybearworld committed Nov 2, 2024
1 parent a9f36e9 commit f8f3328
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Aliases overriding existing commands.
- Commands with whitespace silently breaking (instead of erroring).

## 1.7.0 - 2024-11-01

Expand Down
18 changes: 10 additions & 8 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,19 @@ export class RoarBot {
name: string,
options: CommandOptions<TPattern>
) {
if (this._commands.some((command) => command.name === name)) {
throw new Error(
`A command with the name of ${JSON.stringify(name)} already exists.`
);
}
options.aliases?.forEach((alias) => {
if (this._commands.some((command) => command.name === alias)) {
const validateName = (name: string) => {
if (/\s/.test(name)) {
throw new Error("A command name cannot include whitespace.");
}
if (this._commands.some((command) => command.name === name)) {
throw new Error(
`A command with the name of ${JSON.stringify(alias)} already exists.`
`A command with the name of ${JSON.stringify(name)} already exists.`
);
}
};
validateName(name);
options.aliases?.forEach((alias) => {
validateName(alias);
});
this._commands.push({
name: name,
Expand Down

0 comments on commit f8f3328

Please sign in to comment.