Skip to content

Commit

Permalink
Fix: custom prefix with extra following text (#55)
Browse files Browse the repository at this point in the history
* chore: add test case for custom prefix with extra following text

* fix: command name not being sliced after a space
  • Loading branch information
carafelix authored Nov 26, 2024
1 parent 4982bb0 commit 73d5bab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,11 @@ export class Command<C extends Context = Context> implements MiddlewareObj<C> {
if (targetedCommands === "ignored" && username) continue;
if (targetedCommands === "required" && !username) continue;
if (username && username !== ctx.me.username) continue;
console.log(command.replace(prefix, ""));
if (
commandNames.some((name) =>
matchesPattern(
command.replace(prefix, ""),
command.replace(prefix, "").split(" ")[0],
name,
options.ignoreCase,
)
Expand Down
14 changes: 14 additions & 0 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ describe("Integration", () => {
assertSpyCalls(defaultHandler, 0);
assertSpyCalls(specificHandler, 1);
});
it("custom prefixed command with extra text", async () => {
const handler = spy(() => {});

const commandGroup = new CommandGroup();
commandGroup.command("kick", "_", handler, { prefix: "!" });

const bot = getBot();
bot.use(commands());
bot.use(commandGroup);

await bot.handleUpdate(getDummyUpdate({ userInput: "!kick 12345" }));

assertSpyCalls(handler, 1);
});
});
describe("add", () => {
it("should add a command that was statically created", async () => {
Expand Down

0 comments on commit 73d5bab

Please sign in to comment.