From 73d5bab6367307d9c6f50895f9d5cfddefc221fc Mon Sep 17 00:00:00 2001 From: Hero Protagonist Date: Tue, 26 Nov 2024 17:01:39 -0300 Subject: [PATCH] Fix: custom prefix with extra following text (#55) * chore: add test case for custom prefix with extra following text * fix: command name not being sliced after a space --- src/command.ts | 3 ++- test/integration.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/command.ts b/src/command.ts index 0580302..b49e712 100644 --- a/src/command.ts +++ b/src/command.ts @@ -364,10 +364,11 @@ export class Command implements MiddlewareObj { 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, ) diff --git a/test/integration.test.ts b/test/integration.test.ts index 61fd8c1..3a006e0 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -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 () => {