Proyecto audio control. inicado con panel y control.
This commit is contained in:
28
node_modules/telegraf/scenes/wizard/context.js
generated
vendored
Normal file
28
node_modules/telegraf/scenes/wizard/context.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
class WizardContext {
|
||||
constructor (ctx, steps) {
|
||||
this.ctx = ctx
|
||||
this.steps = steps
|
||||
this.state = ctx.scene.state
|
||||
this.cursor = ctx.scene.session.cursor || 0
|
||||
}
|
||||
|
||||
get step () {
|
||||
return this.cursor >= 0 && this.steps[this.cursor]
|
||||
}
|
||||
|
||||
selectStep (index) {
|
||||
this.cursor = index
|
||||
this.ctx.scene.session.cursor = index
|
||||
return this
|
||||
}
|
||||
|
||||
next () {
|
||||
return this.selectStep(this.cursor + 1)
|
||||
}
|
||||
|
||||
back () {
|
||||
return this.selectStep(this.cursor - 1)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WizardContext
|
||||
51
node_modules/telegraf/scenes/wizard/index.js
generated
vendored
Normal file
51
node_modules/telegraf/scenes/wizard/index.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
const Composer = require('../../composer')
|
||||
const WizardContext = require('./context')
|
||||
const { compose, unwrap } = Composer
|
||||
|
||||
class WizardScene extends Composer {
|
||||
constructor (id, options, ...steps) {
|
||||
super()
|
||||
this.id = id
|
||||
this.options = typeof options === 'function'
|
||||
? { steps: [options, ...steps], leaveHandlers: [] }
|
||||
: { steps: steps, leaveHandlers: [], ...options }
|
||||
this.leaveHandler = compose(this.options.leaveHandlers)
|
||||
}
|
||||
|
||||
set ttl (value) {
|
||||
this.options.ttl = value
|
||||
}
|
||||
|
||||
get ttl () {
|
||||
return this.options.ttl
|
||||
}
|
||||
|
||||
leave (...fns) {
|
||||
this.leaveHandler = compose([this.leaveHandler, ...fns])
|
||||
return this
|
||||
}
|
||||
|
||||
leaveMiddleware () {
|
||||
return this.leaveHandler
|
||||
}
|
||||
|
||||
middleware () {
|
||||
return compose([
|
||||
(ctx, next) => {
|
||||
const wizard = new WizardContext(ctx, this.options.steps)
|
||||
ctx.wizard = wizard
|
||||
return next()
|
||||
},
|
||||
super.middleware(),
|
||||
(ctx, next) => {
|
||||
if (!ctx.wizard.step) {
|
||||
ctx.wizard.selectStep(0)
|
||||
return ctx.scene.leave()
|
||||
}
|
||||
return unwrap(ctx.wizard.step)(ctx, next)
|
||||
}
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WizardScene
|
||||
Reference in New Issue
Block a user