This commit is contained in:
Lukian LEIZOUR 2022-11-19 01:49:12 +01:00
parent be4fd23bcf
commit 0bd53741af
728 changed files with 86573 additions and 0 deletions

39
node_modules/telegraf/lib/scenes/base.js generated vendored Normal file
View file

@ -0,0 +1,39 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseScene = void 0;
const composer_1 = __importDefault(require("../composer"));
const { compose } = composer_1.default;
class BaseScene extends composer_1.default {
constructor(id, options) {
const opts = {
handlers: [],
enterHandlers: [],
leaveHandlers: [],
...options,
};
super(...opts.handlers);
this.id = id;
this.ttl = opts.ttl;
this.enterHandler = compose(opts.enterHandlers);
this.leaveHandler = compose(opts.leaveHandlers);
}
enter(...fns) {
this.enterHandler = compose([this.enterHandler, ...fns]);
return this;
}
leave(...fns) {
this.leaveHandler = compose([this.leaveHandler, ...fns]);
return this;
}
enterMiddleware() {
return this.enterHandler;
}
leaveMiddleware() {
return this.leaveHandler;
}
}
exports.BaseScene = BaseScene;
exports.default = BaseScene;

104
node_modules/telegraf/lib/scenes/context.js generated vendored Normal file
View file

@ -0,0 +1,104 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const composer_1 = __importDefault(require("../composer"));
const debug_1 = __importDefault(require("debug"));
const debug = (0, debug_1.default)('telegraf:scenes:context');
const noop = () => Promise.resolve();
const now = () => Math.floor(Date.now() / 1000);
class SceneContextScene {
constructor(ctx, scenes, options) {
this.ctx = ctx;
this.scenes = scenes;
this.leaving = false;
// @ts-expect-error {} might not be assignable to D
const fallbackSessionDefault = {};
this.options = { defaultSession: fallbackSessionDefault, ...options };
}
get session() {
var _a, _b;
const defaultSession = this.options.defaultSession;
let session = (_b = (_a = this.ctx.session) === null || _a === void 0 ? void 0 : _a.__scenes) !== null && _b !== void 0 ? _b : defaultSession;
if (session.expires !== undefined && session.expires < now()) {
session = defaultSession;
}
if (this.ctx.session === undefined) {
this.ctx.session = { __scenes: session };
}
else {
this.ctx.session.__scenes = session;
}
return session;
}
get state() {
var _a;
var _b;
return ((_a = (_b = this.session).state) !== null && _a !== void 0 ? _a : (_b.state = {}));
}
set state(value) {
this.session.state = { ...value };
}
get current() {
var _a;
const sceneId = (_a = this.session.current) !== null && _a !== void 0 ? _a : this.options.default;
return sceneId === undefined || !this.scenes.has(sceneId)
? undefined
: this.scenes.get(sceneId);
}
reset() {
if (this.ctx.session !== undefined)
this.ctx.session.__scenes = this.options.defaultSession;
}
async enter(sceneId, initialState = {}, silent = false) {
var _a, _b;
if (!this.scenes.has(sceneId)) {
throw new Error(`Can't find scene: ${sceneId}`);
}
if (!silent) {
await this.leave();
}
debug('Entering scene', sceneId, initialState, silent);
this.session.current = sceneId;
this.state = initialState;
const ttl = (_b = (_a = this.current) === null || _a === void 0 ? void 0 : _a.ttl) !== null && _b !== void 0 ? _b : this.options.ttl;
if (ttl !== undefined) {
this.session.expires = now() + ttl;
}
if (this.current === undefined || silent) {
return;
}
const handler = 'enterMiddleware' in this.current &&
typeof this.current.enterMiddleware === 'function'
? this.current.enterMiddleware()
: this.current.middleware();
return await handler(this.ctx, noop);
}
reenter() {
return this.session.current === undefined
? undefined
: this.enter(this.session.current, this.state);
}
async leave() {
if (this.leaving)
return;
debug('Leaving scene');
try {
this.leaving = true;
if (this.current === undefined) {
return;
}
const handler = 'leaveMiddleware' in this.current &&
typeof this.current.leaveMiddleware === 'function'
? this.current.leaveMiddleware()
: composer_1.default.passThru();
await handler(this.ctx, noop);
return this.reset();
}
finally {
this.leaving = false;
}
}
}
exports.default = SceneContextScene;

21
node_modules/telegraf/lib/scenes/index.js generated vendored Normal file
View file

@ -0,0 +1,21 @@
"use strict";
/**
* @see https://github.com/telegraf/telegraf/issues/705#issuecomment-549056045
* @see https://www.npmjs.com/package/telegraf-stateless-question
* @packageDocumentation
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WizardContextWizard = exports.WizardScene = exports.BaseScene = exports.SceneContextScene = exports.Stage = void 0;
var stage_1 = require("./stage");
Object.defineProperty(exports, "Stage", { enumerable: true, get: function () { return stage_1.Stage; } });
var context_1 = require("./context");
Object.defineProperty(exports, "SceneContextScene", { enumerable: true, get: function () { return __importDefault(context_1).default; } });
var base_1 = require("./base");
Object.defineProperty(exports, "BaseScene", { enumerable: true, get: function () { return base_1.BaseScene; } });
var wizard_1 = require("./wizard");
Object.defineProperty(exports, "WizardScene", { enumerable: true, get: function () { return wizard_1.WizardScene; } });
var context_2 = require("./wizard/context");
Object.defineProperty(exports, "WizardContextWizard", { enumerable: true, get: function () { return __importDefault(context_2).default; } });

49
node_modules/telegraf/lib/scenes/stage.js generated vendored Normal file
View file

@ -0,0 +1,49 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stage = void 0;
const session_1 = require("../session");
const context_1 = __importDefault(require("./context"));
const composer_1 = require("../composer");
class Stage extends composer_1.Composer {
constructor(scenes = [], options) {
super();
this.options = { ...options };
this.scenes = new Map();
scenes.forEach((scene) => this.register(scene));
}
register(...scenes) {
scenes.forEach((scene) => {
if ((scene === null || scene === void 0 ? void 0 : scene.id) == null || typeof scene.middleware !== 'function') {
throw new Error('telegraf: Unsupported scene');
}
this.scenes.set(scene.id, scene);
});
return this;
}
middleware() {
const handler = composer_1.Composer.compose([
(ctx, next) => {
const scenes = this.scenes;
const scene = new context_1.default(ctx, scenes, this.options);
ctx.scene = scene;
return next();
},
super.middleware(),
composer_1.Composer.lazy((ctx) => { var _a; return (_a = ctx.scene.current) !== null && _a !== void 0 ? _a : composer_1.Composer.passThru(); }),
]);
return composer_1.Composer.optional(session_1.isSessionContext, handler);
}
static enter(...args) {
return (ctx) => ctx.scene.enter(...args);
}
static reenter(...args) {
return (ctx) => ctx.scene.reenter(...args);
}
static leave(...args) {
return (ctx) => ctx.scene.leave(...args);
}
}
exports.Stage = Stage;

31
node_modules/telegraf/lib/scenes/wizard/context.js generated vendored Normal file
View file

@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class WizardContextWizard {
constructor(ctx, steps) {
var _a;
this.ctx = ctx;
this.steps = steps;
this.state = ctx.scene.state;
this.cursor = (_a = ctx.scene.session.cursor) !== null && _a !== void 0 ? _a : 0;
}
get step() {
return this.steps[this.cursor];
}
get cursor() {
return this.ctx.scene.session.cursor;
}
set cursor(cursor) {
this.ctx.scene.session.cursor = cursor;
}
selectStep(index) {
this.cursor = index;
return this;
}
next() {
return this.selectStep(this.cursor + 1);
}
back() {
return this.selectStep(this.cursor - 1);
}
}
exports.default = WizardContextWizard;

45
node_modules/telegraf/lib/scenes/wizard/index.js generated vendored Normal file
View file

@ -0,0 +1,45 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WizardScene = void 0;
const base_1 = __importDefault(require("../base"));
const context_1 = __importDefault(require("./context"));
const composer_1 = __importDefault(require("../../composer"));
class WizardScene extends base_1.default {
constructor(id, options, ...steps) {
let opts;
let s;
if (typeof options === 'function' || 'middleware' in options) {
opts = undefined;
s = [options, ...steps];
}
else {
opts = options;
s = steps;
}
super(id, opts);
this.steps = s;
}
middleware() {
return composer_1.default.compose([
(ctx, next) => {
ctx.wizard = new context_1.default(ctx, this.steps);
return next();
},
super.middleware(),
(ctx, next) => {
if (ctx.wizard.step === undefined) {
ctx.wizard.selectStep(0);
return ctx.scene.leave();
}
return composer_1.default.unwrap(ctx.wizard.step)(ctx, next);
},
]);
}
enterMiddleware() {
return composer_1.default.compose([this.enterHandler, this.middleware()]);
}
}
exports.WizardScene = WizardScene;