jai shree ram

This commit is contained in:
shiva yadav
2023-04-14 12:54:23 -07:00
parent e2e5a2bf72
commit 86ff33bfc2
4582 changed files with 370514 additions and 0 deletions

109
node_modules/node-telegram-bot-api/lib/errors.js generated vendored Normal file
View File

@@ -0,0 +1,109 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
exports.BaseError = function (_Error) {
_inherits(BaseError, _Error);
/**
* @class BaseError
* @constructor
* @private
* @param {String} code Error code
* @param {String} message Error message
*/
function BaseError(code, message) {
_classCallCheck(this, BaseError);
var _this = _possibleConstructorReturn(this, (BaseError.__proto__ || Object.getPrototypeOf(BaseError)).call(this, code + ': ' + message));
_this.code = code;
return _this;
}
_createClass(BaseError, [{
key: 'toJSON',
value: function toJSON() {
return {
code: this.code,
message: this.message
};
}
}]);
return BaseError;
}(Error);
exports.FatalError = function (_exports$BaseError) {
_inherits(FatalError, _exports$BaseError);
/**
* Fatal Error. Error code is `"EFATAL"`.
* @class FatalError
* @constructor
* @param {String|Error} data Error object or message
*/
function FatalError(data) {
_classCallCheck(this, FatalError);
var error = typeof data === 'string' ? null : data;
var message = error ? error.message : data;
var _this2 = _possibleConstructorReturn(this, (FatalError.__proto__ || Object.getPrototypeOf(FatalError)).call(this, 'EFATAL', message));
if (error) _this2.stack = error.stack;
return _this2;
}
return FatalError;
}(exports.BaseError);
exports.ParseError = function (_exports$BaseError2) {
_inherits(ParseError, _exports$BaseError2);
/**
* Error during parsing. Error code is `"EPARSE"`.
* @class ParseError
* @constructor
* @param {String} message Error message
* @param {http.IncomingMessage} response Server response
*/
function ParseError(message, response) {
_classCallCheck(this, ParseError);
var _this3 = _possibleConstructorReturn(this, (ParseError.__proto__ || Object.getPrototypeOf(ParseError)).call(this, 'EPARSE', message));
_this3.response = response;
return _this3;
}
return ParseError;
}(exports.BaseError);
exports.TelegramError = function (_exports$BaseError3) {
_inherits(TelegramError, _exports$BaseError3);
/**
* Error returned from Telegram. Error code is `"ETELEGRAM"`.
* @class TelegramError
* @constructor
* @param {String} message Error message
* @param {http.IncomingMessage} response Server response
*/
function TelegramError(message, response) {
_classCallCheck(this, TelegramError);
var _this4 = _possibleConstructorReturn(this, (TelegramError.__proto__ || Object.getPrototypeOf(TelegramError)).call(this, 'ETELEGRAM', message));
_this4.response = response;
return _this4;
}
return TelegramError;
}(exports.BaseError);

3361
node_modules/node-telegram-bot-api/lib/telegram.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,245 @@
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var errors = require('./errors');
var debug = require('debug')('node-telegram-bot-api');
var deprecate = require('./utils').deprecate;
var ANOTHER_WEB_HOOK_USED = 409;
var TelegramBotPolling = function () {
/**
* Handles polling against the Telegram servers.
* @param {TelegramBot} bot
* @see https://core.telegram.org/bots/api#getting-updates
*/
function TelegramBotPolling(bot) {
_classCallCheck(this, TelegramBotPolling);
this.bot = bot;
this.options = typeof bot.options.polling === 'boolean' ? {} : bot.options.polling;
this.options.interval = typeof this.options.interval === 'number' ? this.options.interval : 300;
this.options.params = _typeof(this.options.params) === 'object' ? this.options.params : {};
this.options.params.offset = typeof this.options.params.offset === 'number' ? this.options.params.offset : 0;
this.options.params.timeout = typeof this.options.params.timeout === 'number' ? this.options.params.timeout : 10;
if (typeof this.options.timeout === 'number') {
deprecate('`options.polling.timeout` is deprecated. Use `options.polling.params` instead.');
this.options.params.timeout = this.options.timeout;
}
this._lastUpdate = 0;
this._lastRequest = null;
this._abort = false;
this._pollingTimeout = null;
}
/**
* Start polling
* @param {Object} [options]
* @param {Object} [options.restart]
* @return {Promise}
*/
_createClass(TelegramBotPolling, [{
key: 'start',
value: function start() {
var _this = this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (this._lastRequest) {
if (!options.restart) {
return Promise.resolve();
}
return this.stop({
cancel: true,
reason: 'Polling restart'
}).then(function () {
return _this._polling();
});
}
return this._polling();
}
/**
* Stop polling
* @param {Object} [options] Options
* @param {Boolean} [options.cancel] Cancel current request
* @param {String} [options.reason] Reason for stopping polling
* @return {Promise}
*/
}, {
key: 'stop',
value: function stop() {
var _this2 = this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (!this._lastRequest) {
return Promise.resolve();
}
var lastRequest = this._lastRequest;
this._lastRequest = null;
clearTimeout(this._pollingTimeout);
if (options.cancel) {
var reason = options.reason || 'Polling stop';
lastRequest.cancel(reason);
return Promise.resolve();
}
this._abort = true;
return lastRequest.finally(function () {
_this2._abort = false;
});
}
/**
* Return `true` if is polling. Otherwise, `false`.
*/
}, {
key: 'isPolling',
value: function isPolling() {
return !!this._lastRequest;
}
/**
* Handle error thrown during polling.
* @private
* @param {Error} error
*/
}, {
key: '_error',
value: function _error(error) {
if (!this.bot.listeners('polling_error').length) {
return console.error('error: [polling_error] %j', error); // eslint-disable-line no-console
}
return this.bot.emit('polling_error', error);
}
/**
* Invokes polling (with recursion!)
* @return {Promise} promise of the current request
* @private
*/
}, {
key: '_polling',
value: function _polling() {
var _this3 = this;
this._lastRequest = this._getUpdates().then(function (updates) {
_this3._lastUpdate = Date.now();
debug('polling data %j', updates);
updates.forEach(function (update) {
_this3.options.params.offset = update.update_id + 1;
debug('updated offset: %s', _this3.options.params.offset);
try {
_this3.bot.processUpdate(update);
} catch (err) {
err._processing = true;
throw err;
}
});
return null;
}).catch(function (err) {
debug('polling error: %s', err.message);
if (!err._processing) {
return _this3._error(err);
}
delete err._processing;
/*
* An error occured while processing the items,
* i.e. in `this.bot.processUpdate()` above.
* We need to mark the already-processed items
* to avoid fetching them again once the application
* is restarted, or moves to next polling interval
* (in cases where unhandled rejections do not terminate
* the process).
* See https://github.com/yagop/node-telegram-bot-api/issues/36#issuecomment-268532067
*/
if (!_this3.bot.options.badRejection) {
return _this3._error(err);
}
var opts = {
offset: _this3.options.params.offset,
limit: 1,
timeout: 0
};
return _this3.bot.getUpdates(opts).then(function () {
return _this3._error(err);
}).catch(function (requestErr) {
/*
* We have been unable to handle this error.
* We have to log this to stderr to ensure devops
* understands that they may receive already-processed items
* on app restart.
* We simply can not rescue this situation, emit "error"
* event, with the hope that the application exits.
*/
/* eslint-disable no-console */
var bugUrl = 'https://github.com/yagop/node-telegram-bot-api/issues/36#issuecomment-268532067';
console.error('error: Internal handling of The Offset Infinite Loop failed');
console.error('error: Due to error \'' + requestErr + '\'');
console.error('error: You may receive already-processed updates on app restart');
console.error('error: Please see ' + bugUrl + ' for more information');
/* eslint-enable no-console */
return _this3.bot.emit('error', new errors.FatalError(err));
});
}).finally(function () {
if (_this3._abort) {
debug('Polling is aborted!');
} else {
debug('setTimeout for %s miliseconds', _this3.options.interval);
_this3._pollingTimeout = setTimeout(function () {
return _this3._polling();
}, _this3.options.interval);
}
});
return this._lastRequest;
}
/**
* Unset current webhook. Used when we detect that a webhook has been set
* and we are trying to poll. Polling and WebHook are mutually exclusive.
* @see https://core.telegram.org/bots/api#getting-updates
* @private
*/
}, {
key: '_unsetWebHook',
value: function _unsetWebHook() {
debug('unsetting webhook');
return this.bot._request('setWebHook');
}
/**
* Retrieve updates
*/
}, {
key: '_getUpdates',
value: function _getUpdates() {
var _this4 = this;
debug('polling with options: %j', this.options.params);
return this.bot.getUpdates(this.options.params).catch(function (err) {
if (err.response && err.response.statusCode === ANOTHER_WEB_HOOK_USED) {
return _this4._unsetWebHook().then(function () {
return _this4.bot.getUpdates(_this4.options.params);
});
}
throw err;
});
}
}]);
return TelegramBotPolling;
}();
module.exports = TelegramBotPolling;

View File

@@ -0,0 +1,188 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var errors = require('./errors');
var debug = require('debug')('node-telegram-bot-api');
var https = require('https');
var http = require('http');
var fs = require('fs');
var bl = require('bl');
var TelegramBotWebHook = function () {
/**
* Sets up a webhook to receive updates
* @param {TelegramBot} bot
* @see https://core.telegram.org/bots/api#getting-updates
*/
function TelegramBotWebHook(bot) {
_classCallCheck(this, TelegramBotWebHook);
this.bot = bot;
this.options = typeof bot.options.webHook === 'boolean' ? {} : bot.options.webHook;
this.options.host = this.options.host || '0.0.0.0';
this.options.port = this.options.port || 8443;
this.options.https = this.options.https || {};
this.options.healthEndpoint = this.options.healthEndpoint || '/healthz';
this._healthRegex = new RegExp(this.options.healthEndpoint);
this._webServer = null;
this._open = false;
this._requestListener = this._requestListener.bind(this);
this._parseBody = this._parseBody.bind(this);
if (this.options.key && this.options.cert) {
debug('HTTPS WebHook enabled (by key/cert)');
this.options.https.key = fs.readFileSync(this.options.key);
this.options.https.cert = fs.readFileSync(this.options.cert);
this._webServer = https.createServer(this.options.https, this._requestListener);
} else if (this.options.pfx) {
debug('HTTPS WebHook enabled (by pfx)');
this.options.https.pfx = fs.readFileSync(this.options.pfx);
this._webServer = https.createServer(this.options.https, this._requestListener);
} else if (Object.keys(this.options.https).length) {
debug('HTTPS WebHook enabled by (https)');
this._webServer = https.createServer(this.options.https, this._requestListener);
} else {
debug('HTTP WebHook enabled');
this._webServer = http.createServer(this._requestListener);
}
}
/**
* Open WebHook by listening on the port
* @return {Promise}
*/
_createClass(TelegramBotWebHook, [{
key: 'open',
value: function open() {
var _this = this;
if (this.isOpen()) {
return Promise.resolve();
}
return new Promise(function (resolve) {
_this._webServer.listen(_this.options.port, _this.options.host, function () {
debug('WebHook listening on port %s', _this.options.port);
_this._open = true;
return resolve();
});
});
}
/**
* Close the webHook
* @return {Promise}
*/
}, {
key: 'close',
value: function close() {
var _this2 = this;
if (!this.isOpen()) {
return Promise.resolve();
}
return new Promise(function (resolve, reject) {
_this2._webServer.close(function (error) {
if (error) return reject(error);
_this2._open = false;
return resolve();
});
});
}
/**
* Return `true` if server is listening. Otherwise, `false`.
*/
}, {
key: 'isOpen',
value: function isOpen() {
// NOTE: Since `http.Server.listening` was added in v5.7.0
// and we still need to support Node v4,
// we are going to fallback to 'this._open'.
// The following LOC would suffice for newer versions of Node.js
// return this._webServer.listening;
return this._open;
}
/**
* Handle error thrown during processing of webhook request.
* @private
* @param {Error} error
*/
}, {
key: '_error',
value: function _error(error) {
if (!this.bot.listeners('webhook_error').length) {
return console.error('error: [webhook_error] %j', error); // eslint-disable-line no-console
}
return this.bot.emit('webhook_error', error);
}
/**
* Handle request body by passing it to 'callback'
* @private
*/
}, {
key: '_parseBody',
value: function _parseBody(error, body) {
if (error) {
return this._error(new errors.FatalError(error));
}
var data = void 0;
try {
data = JSON.parse(body.toString());
} catch (parseError) {
return this._error(new errors.ParseError(parseError.message));
}
return this.bot.processUpdate(data);
}
/**
* Listener for 'request' event on server
* @private
* @see https://nodejs.org/docs/latest/api/http.html#http_http_createserver_requestlistener
* @see https://nodejs.org/docs/latest/api/https.html#https_https_createserver_options_requestlistener
*/
}, {
key: '_requestListener',
value: function _requestListener(req, res) {
debug('WebHook request URL: %s', req.url);
debug('WebHook request headers: %j', req.headers);
if (req.url.indexOf(this.bot.token) !== -1) {
if (req.method !== 'POST') {
debug('WebHook request isn\'t a POST');
res.statusCode = 418; // I'm a teabot!
res.end();
} else {
req.pipe(bl(this._parseBody)).on('finish', function () {
return res.end('OK');
});
}
} else if (this._healthRegex.test(req.url)) {
debug('WebHook health check passed');
res.statusCode = 200;
res.end('OK');
} else {
debug('WebHook request unauthorized');
res.statusCode = 401;
res.end();
}
}
}]);
return TelegramBotWebHook;
}();
module.exports = TelegramBotWebHook;

7
node_modules/node-telegram-bot-api/lib/utils.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
'use strict';
var util = require('util');
// Native deprecation warning
exports.deprecate = function (msg) {
return util.deprecate(function () {}, msg, 'node-telegram-bot-api')();
};