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

Do not handle commands from channels #147

Closed
wants to merge 5 commits into from

Conversation

KnorpelSenf
Copy link
Member

They don't exist anyway (the server does not parse the command entities in channels) so we might as well drop this.

#108 will add command handling that does not rely on parsed entities.

This PR has the advantage that ctx.from will now always be present after bot.command.

(ctx): ctx is CommandContext<C> => {
const msg = ctx.message ?? ctx.channelPost;
const txt = msg.text ?? msg.caption;
const entities = msg.entities ?? msg.caption_entities;
Copy link
Member

Choose a reason for hiding this comment

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

This not only removes support for commands in channels but also for commands on media messages with captions?

Not sure if that even works normally, never tried that.

Copy link
Member Author

@KnorpelSenf KnorpelSenf Dec 30, 2021

Choose a reason for hiding this comment

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

grammY used to support commands in captions in its early days, but a lot of people in the community complained that it is not intuitive for command handlers to trigger when e.g. an image caption contains a command. Hence, the support was remove by changing the filter query from ::bot_command to :entities:bot_command.

The code that was removed here was essentially dead code.

Choose a reason for hiding this comment

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

You can mix it, it's perfect!

Copy link
Member Author

Choose a reason for hiding this comment

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

Mix? Do you mean merge?

Copy link

@joseanoxp joseanoxp left a comment

Choose a reason for hiding this comment

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

Get in gear!

Copy link
Member

@rojvv rojvv left a comment

Choose a reason for hiding this comment

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

The changes are doing what they are meant to do. Commands aren't handled in channels, anymore.

@KnorpelSenf
Copy link
Member Author

The changes are doing what they are meant to do. Commands aren't handled in channels, anymore.

Were commands handled in channels before?

@KnorpelSenf
Copy link
Member Author

Oh well. I tested this once again, and interestingly enough the entities are not rendered in any client, but bots receive them. Hence, the assumption that the server does not parse the command entities in channels is wrong. As a result, we cannot drop this feature without doing a breaking change. I will close this unmerged.

Note that if you still want ctx.from to be present, you can do

bot.on('message').command('start', ctx => {
  const name = ctx.from.first_name // `ctx.from` is present now!
})

@KnorpelSenf KnorpelSenf deleted the no-commands-in-channels branch December 31, 2021 10:13
@EdJoPaTo
Copy link
Member

The dead code you mentioned about the commands on captions should still be removed I guess?

@KnorpelSenf
Copy link
Member Author

e322af1

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.

None yet

5 participants