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

feat: fill ctx.match and add ctx.commandMatch and node chores #57

Merged
merged 4 commits into from
Dec 26, 2024

Conversation

roziscoding
Copy link
Contributor

@roziscoding roziscoding commented Dec 7, 2024

  • Allow users to get the "arguments" of a command using ctx.match
  • Expose result of RegExp match through ctx.commandMatch

Example usage:

type MyContext = Context & CommandsFlavor;

const bot = new Bot<MyContext>("TOKEN");

const commands = new CommandGroup<MyContext>();

commands.command(/start ?(?<name>.*)?/, "a", async (ctx) => {
  console.log(ctx.commandMatch);
  // { command: /start ?(?<name>.*)?/, rest: 'name', match: ['start name', 'name'] }

  return ctx.reply(`Hello`);
});

bot.use(commands);

bot.start({
  onStart: () => {
    console.log("Bot started");
  },
});

Closes #58

@roziscoding roziscoding self-assigned this Dec 7, 2024
@roziscoding roziscoding requested a review from carafelix December 7, 2024 16:08
Copy link

@polRk polRk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we should add fuzz tests

@roziscoding
Copy link
Contributor Author

I think, we should add fuzz tests

I don't really have the time for that right now, but I'd gladly review a new PQ :)

@carafelix carafelix changed the title feat: fill ctx.match and add ctx.commandMatch feat: fill ctx.match and add ctx.commandMatch and chores Dec 26, 2024
@carafelix carafelix changed the title feat: fill ctx.match and add ctx.commandMatch and chores feat: fill ctx.match and add ctx.commandMatch and node chores Dec 26, 2024
@roziscoding roziscoding merged commit ceccd32 into main Dec 26, 2024
6 checks passed
@roziscoding roziscoding deleted the ctx-dot-match branch December 26, 2024 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to get command parameter
3 participants