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(composer): match any command #733

Open
wants to merge 5 commits into
base: v2
Choose a base branch
from
Open

feat(composer): match any command #733

wants to merge 5 commits into from

Conversation

wojpawlik
Copy link
Contributor

Happy new year!
Closes #685

@wojpawlik wojpawlik linked an issue Dec 31, 2024 that may be closed by this pull request
Copy link
Member

@carafelix carafelix left a comment

Choose a reason for hiding this comment

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

WDYT?

src/context.ts Outdated Show resolved Hide resolved
@wojpawlik wojpawlik changed the title feat(Composer): match any command feat(composer): match any command Jan 2, 2025
return true;
let index = cmd.indexOf("@");
if (index === -1) {
index = Infinity;
Copy link
Member

Choose a reason for hiding this comment

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

This is a big of a hack, isn't it?

Copy link
Contributor Author

@wojpawlik wojpawlik Jan 2, 2025

Choose a reason for hiding this comment

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

Not really:

Any argument value that is less than 0 or greater than str.length is treated as if it were 0 and str.length, respectively.

Suggested change
index = Infinity;
index = cmd.length;

undefined would require adding a type annotation.

@@ -110,7 +110,7 @@ describe("Composer types", () => {
const channelPostCaption = ctx.channelPost?.caption;
const channelPostText = ctx.channelPost?.text;
const match = ctx.match;
assertType<IsExact<typeof msgText, string>>(true);
assertType<IsExact<typeof msgText, string | undefined>>(true);
Copy link
Member

Choose a reason for hiding this comment

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

Could you also assert that ctx.msg.text ?? ctx.msg.caption is string? If it isn't, then I'd like to fix up the filter queries first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's string | undefined, no idea why :(

@carafelix #686 required touching 3 files, not 1 line, and uncovered a bug.

Copy link
Member

Choose a reason for hiding this comment

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

It's odd to me that this seems to work correctly for entitiestext but fails for caption_entitiescaption. Smells like

  • it's related to bad type distribution or
  • the above assumption is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (ctx.has(":caption_entities")) ctx.msg.caption actually is string, as expected... Only msg.text ?? msg.caption breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing

caption?: string;
to required "fixes" the issue

Copy link
Member

Choose a reason for hiding this comment

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

if (ctx.has(":caption_entities")) ctx.msg.caption actually is string, as expected... Only msg.text ?? msg.caption breaks.

Very interesting, that fits my intuition, but I'll still have to investigate it properly

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.

feat: bot.command() should match any bot command
3 participants