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

added ctx.menu.at function #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

zxsleebu
Copy link

@zxsleebu zxsleebu commented Sep 23, 2024

useful function for custom methods.
i don't actually have a deno environment, so you should necessarily test this pr!

@KnorpelSenf
Copy link
Member

Will review it tonight. You can test your changes by running

npm install github:zxsleebu/menu

@KnorpelSenf
Copy link
Member

In fact, you can compile it simply by running npm i. No Deno needed.

@@ -34,7 +34,7 @@ const INJECT_METHODS = new Set([
* Context flavor for context objects in listeners that react to menus. Provides
* `ctx.menu`, a control pane for the respective menu.
*/
export interface MenuFlavor {
export interface MenuFlavor<C extends Context> {
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 breaking change.

@KnorpelSenf
Copy link
Member

These changes make ctx.menu.at only available inside button handlers. Was that intended?

#14 outlines that menus should be accessible everywhere, so you can for example do this:

bot.command("menu", ctx => ctx.reply("Menu:", {
  // Send 'my-menu'
  reply_markup: ctx.menu.at("my-menu")
}))

Your changes do not permit that.

@zxsleebu
Copy link
Author

These changes make ctx.menu.at only available inside button handlers. Was that intended?

#14 outlines that menus should be accessible everywhere, so you can for example do this:

bot.command("menu", ctx => ctx.reply("Menu:", {
  // Send 'my-menu'
  reply_markup: ctx.menu.at("my-menu")
}))

Your changes do not permit that.

yes, that was fully intended.
i was trying to make a wrapper for menus which allows them to have preset text content.
i though this change is the simpliest thing to at least minimally simplify custom menu management.
i ended up making a custom patch, but i also agree that ctx.menu.at should exist and be global.
here's an example of my code. maybe you will like the idea of menus with preset text.

const devSettingsMenu = new AutoMenu("devSettingsMenu", async (ctx, menu) => {
    await ctx.reply(`Developer settings`, { reply_markup: menu });
}).text("Request API-Key", ctx => ctx.reply('API-Key requested successfuly'))
    .fastBack()

@KnorpelSenf
Copy link
Member

I neither understand your use case nor the code snippet and I'm also not sure if they have anything to do with each other

@KnorpelSenf
Copy link
Member

Is that like a side-effect function that runs when the menu is sent somewhere? So you end up sending two menus? Or how else would you send a menu now?

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.

2 participants