Open sergej-js opened 1 year ago
When you call bot.use(scenes.manager())
it injects ctx.scenes
. So when you call it the second time with user scenes manager, it overwrites the previously injected admin scenes manager, and admin scenes are lost.
What are you trying to achieve ultimately? Can you describe your use case?
When you call
bot.use(scenes.manager())
it injectsctx.scenes
. So when you call it the second time with user scenes manager, it overwrites the previously injected admin scenes manager, and admin scenes are lost.What are you trying to achieve ultimately? Can you describe your use case?
I have two composer Admin and user. And each of them has a filter, I want the scenes for administrators to work only for them, and for users only their scenes work.
When you call
bot.use(scenes.manager())
it injectsctx.scenes
. So when you call it the second time with user scenes manager, it overwrites the previously injected admin scenes manager, and admin scenes are lost.What are you trying to achieve ultimately? Can you describe your use case?
I know that you can specify your own filter for each scene, but this does not suit me, because there can be a lot of scenes
When you call
bot.use(scenes.manager())
it injectsctx.scenes
. So when you call it the second time with user scenes manager, it overwrites the previously injected admin scenes manager, and admin scenes are lost.What are you trying to achieve ultimately? Can you describe your use case?
I just want the scenes to work in different composers, but be available from a common ctx.scene
That is not currently possible, I need to think of a good way to separate/filter scenes.
I think at the time being you can keep them together. Besides scenes, you probably have commands that actually start them, and there you can filter. So if users can never start admin scenes in the first place, then scenes can actually live together under the same ScenesComposer.
I agree that it's better to have a way separate them more reliably (which will help when e.g. admin is demoted to normal user while in the scene).
That is not currently possible, I need to think of a good way to separate/filter scenes.
I think at the time being you can keep them together. Besides scenes, you probably have commands that actually start them, and there you can filter. So if users can never start admin scenes in the first place, then scenes can actually live together under the same ScenesComposer.
I agree that it's better to have a way separate them more reliably (which will help when e.g. admin is demoted to normal user while in the scene).
Okay, but I hope you can solve this problem
On second thought, if admin & user scenes are unrelated, it should be possible right now, with something like:
import { Bot } from "grammy"
import { Scene, ScenesComposer } from "grammy-scenes"
import { BotContext } from "./context"
const bot = new Bot<BotContext>("token")
const user1 = new Scene<BotContext>("user1")
const user2 = new Scene<BotContext>("user2")
const userScenes = new ScenesComposer(user1, user2)
const admin1 = new Scene<BotContext>("admin1")
const admin2 = new Scene<BotContext>("admin2")
const adminScenes = new ScenesComposer(admin1, admin2)
const isAdmin = () => false
const isUser = () => true
bot
.filter(isAdmin)
.use(adminScenes.manager())
.command("start", (ctx) => ctx.scenes.enter("admin1"))
.use(adminScenes)
bot
.filter(isUser)
.use(userScenes.manager())
.command("start", (ctx) => ctx.scenes.enter("user1"))
.use(userScenes)
On second though, if admin & user scenes are unrelated, it should be possible right now, with something like:
Thank you!I will try
User scenes(userComposer) Admin scenes(adminComposer) If I use the admin scene and the user scene at the same time, then the user scene works without problems, but when I enter the admin scene, I get the following error The error comes out after I entered the scene and entered some kind of message