-
Notifications
You must be signed in to change notification settings - Fork 121
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
base: v2
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT?
Composer
): match any commandreturn true; | ||
let index = cmd.indexOf("@"); | ||
if (index === -1) { | ||
index = Infinity; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any argument value that is less than
0
or greater thanstr.length
is treated as if it were0
andstr.length
, respectively.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 entities
→text
but fails for caption_entities
→caption
. Smells like
- it's related to bad type distribution or
- the above assumption is wrong
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing
grammY/src/temporary_types/message.ts
Line 66 in a55168c
caption?: string; |
There was a problem hiding this comment.
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 isstring
, as expected... Onlymsg.text ?? msg.caption
breaks.
Very interesting, that fits my intuition, but I'll still have to investigate it properly
Happy new year!
Closes #685