Desplegando App
This commit is contained in:
21
node_modules/telegraf/LICENSE
generated
vendored
Normal file
21
node_modules/telegraf/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2019 Vitaly Domnikov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
108
node_modules/telegraf/bin/telegraf
generated
vendored
Executable file
108
node_modules/telegraf/bin/telegraf
generated
vendored
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const debug = require('debug')
|
||||
const path = require('path')
|
||||
const parse = require('minimist')
|
||||
const { addAlias } = require('module-alias')
|
||||
const Telegraf = require('../')
|
||||
|
||||
const log = debug('telegraf:cli')
|
||||
|
||||
const help = () => {
|
||||
console.log(`Usage: telegraf [opts] <bot-file>
|
||||
-t Bot token [$BOT_TOKEN]
|
||||
-d Webhook domain
|
||||
-H Webhook host [0.0.0.0]
|
||||
-p Webhook port [$PORT or 3000]
|
||||
-s Stop on error
|
||||
-l Enable logs
|
||||
-h Show this help message`)
|
||||
}
|
||||
|
||||
const args = parse(process.argv, {
|
||||
alias: {
|
||||
t: 'token',
|
||||
d: 'domain',
|
||||
H: 'host',
|
||||
h: 'help',
|
||||
l: 'logs',
|
||||
s: 'stop',
|
||||
p: 'port'
|
||||
},
|
||||
boolean: ['h', 'l', 's'],
|
||||
default: {
|
||||
H: '0.0.0.0',
|
||||
p: process.env.PORT || 3000
|
||||
}
|
||||
})
|
||||
|
||||
if (args.help) {
|
||||
help()
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const token = args.token || process.env.BOT_TOKEN
|
||||
const domain = args.domain || process.env.BOT_DOMAIN
|
||||
if (!token) {
|
||||
console.error('Please supply Bot Token')
|
||||
help()
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
let [, , file] = args._
|
||||
|
||||
if (!file) {
|
||||
try {
|
||||
const packageJson = require(path.resolve(process.cwd(), 'package.json'))
|
||||
file = packageJson.main || 'index.js'
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
console.error('Please supply a bot handler file.\n')
|
||||
help()
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (file[0] !== '/') {
|
||||
file = path.resolve(process.cwd(), file)
|
||||
}
|
||||
|
||||
let botHandler
|
||||
let httpHandler
|
||||
let tlsOptions
|
||||
|
||||
try {
|
||||
if (args.logs) {
|
||||
debug.enable('telegraf:*')
|
||||
}
|
||||
addAlias('telegraf', path.join(__dirname, '../'))
|
||||
const mod = require(file)
|
||||
botHandler = mod.botHandler || mod
|
||||
httpHandler = mod.httpHandler
|
||||
tlsOptions = mod.tlsOptions
|
||||
} catch (err) {
|
||||
console.error(`Error importing ${file}`, err.stack)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const config = {}
|
||||
if (domain) {
|
||||
config.webhook = {
|
||||
tlsOptions,
|
||||
host: args.host,
|
||||
port: args.port,
|
||||
domain: domain,
|
||||
cb: httpHandler
|
||||
}
|
||||
}
|
||||
|
||||
const bot = new Telegraf(token)
|
||||
if (!args.stop) {
|
||||
bot.catch(log)
|
||||
}
|
||||
bot.use(botHandler)
|
||||
|
||||
log(`Starting module ${file}`)
|
||||
bot.launch(config)
|
||||
408
node_modules/telegraf/composer.js
generated
vendored
Normal file
408
node_modules/telegraf/composer.js
generated
vendored
Normal file
@@ -0,0 +1,408 @@
|
||||
const Context = require('./context')
|
||||
|
||||
class Composer {
|
||||
constructor (...fns) {
|
||||
this.handler = Composer.compose(fns)
|
||||
}
|
||||
|
||||
use (...fns) {
|
||||
this.handler = Composer.compose([this.handler, ...fns])
|
||||
return this
|
||||
}
|
||||
|
||||
on (updateTypes, ...fns) {
|
||||
return this.use(Composer.mount(updateTypes, ...fns))
|
||||
}
|
||||
|
||||
hears (triggers, ...fns) {
|
||||
return this.use(Composer.hears(triggers, ...fns))
|
||||
}
|
||||
|
||||
command (commands, ...fns) {
|
||||
return this.use(Composer.command(commands, ...fns))
|
||||
}
|
||||
|
||||
action (triggers, ...fns) {
|
||||
return this.use(Composer.action(triggers, ...fns))
|
||||
}
|
||||
|
||||
inlineQuery (triggers, ...fns) {
|
||||
return this.use(Composer.inlineQuery(triggers, ...fns))
|
||||
}
|
||||
|
||||
gameQuery (...fns) {
|
||||
return this.use(Composer.gameQuery(...fns))
|
||||
}
|
||||
|
||||
drop (predicate) {
|
||||
return this.use(Composer.drop(predicate))
|
||||
}
|
||||
|
||||
filter (predicate) {
|
||||
return this.use(Composer.filter(predicate))
|
||||
}
|
||||
|
||||
entity (...args) {
|
||||
return this.use(Composer.entity(...args))
|
||||
}
|
||||
|
||||
email (...args) {
|
||||
return this.use(Composer.email(...args))
|
||||
}
|
||||
|
||||
url (...args) {
|
||||
return this.use(Composer.url(...args))
|
||||
}
|
||||
|
||||
textLink (...args) {
|
||||
return this.use(Composer.textLink(...args))
|
||||
}
|
||||
|
||||
textMention (...args) {
|
||||
return this.use(Composer.textMention(...args))
|
||||
}
|
||||
|
||||
mention (...args) {
|
||||
return this.use(Composer.mention(...args))
|
||||
}
|
||||
|
||||
phone (...args) {
|
||||
return this.use(Composer.phone(...args))
|
||||
}
|
||||
|
||||
hashtag (...args) {
|
||||
return this.use(Composer.hashtag(...args))
|
||||
}
|
||||
|
||||
cashtag (...args) {
|
||||
return this.use(Composer.cashtag(...args))
|
||||
}
|
||||
|
||||
start (...fns) {
|
||||
return this.command('start', Composer.tap((ctx) => {
|
||||
ctx.startPayload = ctx.message.text.substring(7)
|
||||
}), ...fns)
|
||||
}
|
||||
|
||||
help (...fns) {
|
||||
return this.command('help', ...fns)
|
||||
}
|
||||
|
||||
settings (...fns) {
|
||||
return this.command('settings', ...fns)
|
||||
}
|
||||
|
||||
middleware () {
|
||||
return this.handler
|
||||
}
|
||||
|
||||
static reply (...args) {
|
||||
return (ctx) => ctx.reply(...args)
|
||||
}
|
||||
|
||||
static catchAll (...fns) {
|
||||
return Composer.catch((err) => {
|
||||
console.error()
|
||||
console.error((err.stack || err.toString()).replace(/^/gm, ' '))
|
||||
console.error()
|
||||
}, ...fns)
|
||||
}
|
||||
|
||||
static catch (errorHandler, ...fns) {
|
||||
const handler = Composer.compose(fns)
|
||||
return (ctx, next) => Promise.resolve(handler(ctx, next))
|
||||
.catch((err) => errorHandler(err, ctx))
|
||||
}
|
||||
|
||||
static fork (middleware) {
|
||||
const handler = Composer.unwrap(middleware)
|
||||
return (ctx, next) => {
|
||||
setImmediate(handler, ctx, Composer.safePassThru())
|
||||
return next(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
static tap (middleware) {
|
||||
const handler = Composer.unwrap(middleware)
|
||||
return (ctx, next) => Promise.resolve(handler(ctx, Composer.safePassThru())).then(() => next(ctx))
|
||||
}
|
||||
|
||||
static passThru () {
|
||||
return (ctx, next) => next(ctx)
|
||||
}
|
||||
|
||||
static safePassThru () {
|
||||
return (ctx, next) => typeof next === 'function' ? next(ctx) : Promise.resolve()
|
||||
}
|
||||
|
||||
static lazy (factoryFn) {
|
||||
if (typeof factoryFn !== 'function') {
|
||||
throw new Error('Argument must be a function')
|
||||
}
|
||||
return (ctx, next) => Promise.resolve(factoryFn(ctx))
|
||||
.then((middleware) => Composer.unwrap(middleware)(ctx, next))
|
||||
}
|
||||
|
||||
static log (logFn = console.log) {
|
||||
return Composer.fork((ctx) => logFn(JSON.stringify(ctx.update, null, 2)))
|
||||
}
|
||||
|
||||
static branch (predicate, trueMiddleware, falseMiddleware) {
|
||||
if (typeof predicate !== 'function') {
|
||||
return predicate ? trueMiddleware : falseMiddleware
|
||||
}
|
||||
return Composer.lazy((ctx) => Promise.resolve(predicate(ctx))
|
||||
.then((value) => value ? trueMiddleware : falseMiddleware))
|
||||
}
|
||||
|
||||
static optional (predicate, ...fns) {
|
||||
return Composer.branch(predicate, Composer.compose(fns), Composer.safePassThru())
|
||||
}
|
||||
|
||||
static filter (predicate) {
|
||||
return Composer.branch(predicate, Composer.safePassThru(), () => { })
|
||||
}
|
||||
|
||||
static drop (predicate) {
|
||||
return Composer.branch(predicate, () => { }, Composer.safePassThru())
|
||||
}
|
||||
|
||||
static dispatch (routeFn, handlers) {
|
||||
return typeof routeFn === 'function'
|
||||
? Composer.lazy((ctx) => Promise.resolve(routeFn(ctx)).then((value) => handlers[value]))
|
||||
: handlers[routeFn]
|
||||
}
|
||||
|
||||
static mount (updateType, ...fns) {
|
||||
const updateTypes = normalizeTextArguments(updateType)
|
||||
const predicate = (ctx) => updateTypes.includes(ctx.updateType) || updateTypes.some((type) => ctx.updateSubTypes.includes(type))
|
||||
return Composer.optional(predicate, ...fns)
|
||||
}
|
||||
|
||||
static entity (predicate, ...fns) {
|
||||
if (typeof predicate !== 'function') {
|
||||
const entityTypes = normalizeTextArguments(predicate)
|
||||
return Composer.entity(({ type }) => entityTypes.includes(type), ...fns)
|
||||
}
|
||||
return Composer.optional((ctx) => {
|
||||
const message = ctx.message || ctx.channelPost
|
||||
const entities = message && (message.entities || message.caption_entities)
|
||||
const text = message && (message.text || message.caption)
|
||||
return entities && entities.some((entity) =>
|
||||
predicate(entity, text.substring(entity.offset, entity.offset + entity.length), ctx)
|
||||
)
|
||||
}, ...fns)
|
||||
}
|
||||
|
||||
static entityText (entityType, predicate, ...fns) {
|
||||
if (fns.length === 0) {
|
||||
return Array.isArray(predicate)
|
||||
? Composer.entity(entityType, ...predicate)
|
||||
: Composer.entity(entityType, predicate)
|
||||
}
|
||||
const triggers = normalizeTriggers(predicate)
|
||||
return Composer.entity(({ type }, value, ctx) => {
|
||||
if (type !== entityType) {
|
||||
return false
|
||||
}
|
||||
for (const trigger of triggers) {
|
||||
ctx.match = trigger(value, ctx)
|
||||
if (ctx.match) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}, ...fns)
|
||||
}
|
||||
|
||||
static email (email, ...fns) {
|
||||
return Composer.entityText('email', email, ...fns)
|
||||
}
|
||||
|
||||
static phone (number, ...fns) {
|
||||
return Composer.entityText('phone_number', number, ...fns)
|
||||
}
|
||||
|
||||
static url (url, ...fns) {
|
||||
return Composer.entityText('url', url, ...fns)
|
||||
}
|
||||
|
||||
static textLink (link, ...fns) {
|
||||
return Composer.entityText('text_link', link, ...fns)
|
||||
}
|
||||
|
||||
static textMention (mention, ...fns) {
|
||||
return Composer.entityText('text_mention', mention, ...fns)
|
||||
}
|
||||
|
||||
static mention (mention, ...fns) {
|
||||
return Composer.entityText('mention', normalizeTextArguments(mention, '@'), ...fns)
|
||||
}
|
||||
|
||||
static hashtag (hashtag, ...fns) {
|
||||
return Composer.entityText('hashtag', normalizeTextArguments(hashtag, '#'), ...fns)
|
||||
}
|
||||
|
||||
static cashtag (cashtag, ...fns) {
|
||||
return Composer.entityText('cashtag', normalizeTextArguments(cashtag, '$'), ...fns)
|
||||
}
|
||||
|
||||
static match (triggers, ...fns) {
|
||||
return Composer.optional((ctx) => {
|
||||
const text = (
|
||||
(ctx.message && (ctx.message.caption || ctx.message.text)) ||
|
||||
(ctx.callbackQuery && ctx.callbackQuery.data) ||
|
||||
(ctx.inlineQuery && ctx.inlineQuery.query)
|
||||
)
|
||||
for (const trigger of triggers) {
|
||||
ctx.match = trigger(text, ctx)
|
||||
if (ctx.match) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}, ...fns)
|
||||
}
|
||||
|
||||
static hears (triggers, ...fns) {
|
||||
return Composer.mount('text', Composer.match(normalizeTriggers(triggers), ...fns))
|
||||
}
|
||||
|
||||
static command (command, ...fns) {
|
||||
if (fns.length === 0) {
|
||||
return Composer.entity(['bot_command'], command)
|
||||
}
|
||||
const commands = normalizeTextArguments(command, '/')
|
||||
return Composer.mount('text', Composer.lazy((ctx) => {
|
||||
const groupCommands = ctx.me && (ctx.chat.type === 'group' || ctx.chat.type === 'supergroup')
|
||||
? commands.map((command) => `${command}@${ctx.me}`)
|
||||
: []
|
||||
return Composer.entity(({ offset, type }, value) =>
|
||||
offset === 0 &&
|
||||
type === 'bot_command' &&
|
||||
(commands.includes(value) || groupCommands.includes(value))
|
||||
, ...fns)
|
||||
}))
|
||||
}
|
||||
|
||||
static action (triggers, ...fns) {
|
||||
return Composer.mount('callback_query', Composer.match(normalizeTriggers(triggers), ...fns))
|
||||
}
|
||||
|
||||
static inlineQuery (triggers, ...fns) {
|
||||
return Composer.mount('inline_query', Composer.match(normalizeTriggers(triggers), ...fns))
|
||||
}
|
||||
|
||||
static acl (userId, ...fns) {
|
||||
if (typeof userId === 'function') {
|
||||
return Composer.optional(userId, ...fns)
|
||||
}
|
||||
const allowed = Array.isArray(userId) ? userId : [userId]
|
||||
return Composer.optional((ctx) => !ctx.from || allowed.includes(ctx.from.id), ...fns)
|
||||
}
|
||||
|
||||
static memberStatus (status, ...fns) {
|
||||
const statuses = Array.isArray(status) ? status : [status]
|
||||
return Composer.optional((ctx) => ctx.message && ctx.getChatMember(ctx.message.from.id)
|
||||
.then(member => member && statuses.includes(member.status))
|
||||
, ...fns)
|
||||
}
|
||||
|
||||
static admin (...fns) {
|
||||
return Composer.memberStatus(['administrator', 'creator'], ...fns)
|
||||
}
|
||||
|
||||
static creator (...fns) {
|
||||
return Composer.memberStatus('creator', ...fns)
|
||||
}
|
||||
|
||||
static chatType (type, ...fns) {
|
||||
const types = Array.isArray(type) ? type : [type]
|
||||
return Composer.optional((ctx) => ctx.chat && types.includes(ctx.chat.type), ...fns)
|
||||
}
|
||||
|
||||
static privateChat (...fns) {
|
||||
return Composer.chatType('private', ...fns)
|
||||
}
|
||||
|
||||
static groupChat (...fns) {
|
||||
return Composer.chatType(['group', 'supergroup'], ...fns)
|
||||
}
|
||||
|
||||
static gameQuery (...fns) {
|
||||
return Composer.mount('callback_query', Composer.optional((ctx) => ctx.callbackQuery.game_short_name, ...fns))
|
||||
}
|
||||
|
||||
static unwrap (handler) {
|
||||
if (!handler) {
|
||||
throw new Error('Handler is undefined')
|
||||
}
|
||||
return typeof handler.middleware === 'function'
|
||||
? handler.middleware()
|
||||
: handler
|
||||
}
|
||||
|
||||
static compose (middlewares) {
|
||||
if (!Array.isArray(middlewares)) {
|
||||
throw new Error('Middlewares must be an array')
|
||||
}
|
||||
if (middlewares.length === 0) {
|
||||
return Composer.safePassThru()
|
||||
}
|
||||
if (middlewares.length === 1) {
|
||||
return Composer.unwrap(middlewares[0])
|
||||
}
|
||||
return (ctx, next) => {
|
||||
let index = -1
|
||||
return execute(0, ctx)
|
||||
function execute (i, context) {
|
||||
if (!(context instanceof Context)) {
|
||||
return Promise.reject(new Error('next(ctx) called with invalid context'))
|
||||
}
|
||||
if (i <= index) {
|
||||
return Promise.reject(new Error('next() called multiple times'))
|
||||
}
|
||||
index = i
|
||||
const handler = middlewares[i] ? Composer.unwrap(middlewares[i]) : next
|
||||
if (!handler) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
try {
|
||||
return Promise.resolve(
|
||||
handler(context, (ctx = context) => execute(i + 1, ctx))
|
||||
)
|
||||
} catch (err) {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeTriggers (triggers) {
|
||||
if (!Array.isArray(triggers)) {
|
||||
triggers = [triggers]
|
||||
}
|
||||
return triggers.map((trigger) => {
|
||||
if (!trigger) {
|
||||
throw new Error('Invalid trigger')
|
||||
}
|
||||
if (typeof trigger === 'function') {
|
||||
return trigger
|
||||
}
|
||||
if (trigger instanceof RegExp) {
|
||||
return (value) => {
|
||||
trigger.lastIndex = 0
|
||||
return trigger.exec(value || '')
|
||||
}
|
||||
}
|
||||
return (value) => trigger === value ? value : null
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeTextArguments (argument, prefix) {
|
||||
const args = Array.isArray(argument) ? argument : [argument]
|
||||
return args
|
||||
.filter(Boolean)
|
||||
.map((arg) => prefix && typeof arg === 'string' && !arg.startsWith(prefix) ? `${prefix}${arg}` : arg)
|
||||
}
|
||||
|
||||
module.exports = Composer
|
||||
590
node_modules/telegraf/context.js
generated
vendored
Normal file
590
node_modules/telegraf/context.js
generated
vendored
Normal file
@@ -0,0 +1,590 @@
|
||||
const UpdateTypes = [
|
||||
'callback_query',
|
||||
'channel_post',
|
||||
'chosen_inline_result',
|
||||
'edited_channel_post',
|
||||
'edited_message',
|
||||
'inline_query',
|
||||
'shipping_query',
|
||||
'pre_checkout_query',
|
||||
'message',
|
||||
'poll',
|
||||
'poll_answer'
|
||||
]
|
||||
|
||||
const MessageSubTypes = [
|
||||
'voice',
|
||||
'video_note',
|
||||
'video',
|
||||
'animation',
|
||||
'venue',
|
||||
'text',
|
||||
'supergroup_chat_created',
|
||||
'successful_payment',
|
||||
'sticker',
|
||||
'pinned_message',
|
||||
'photo',
|
||||
'new_chat_title',
|
||||
'new_chat_photo',
|
||||
'new_chat_members',
|
||||
'migrate_to_chat_id',
|
||||
'migrate_from_chat_id',
|
||||
'location',
|
||||
'left_chat_member',
|
||||
'invoice',
|
||||
'group_chat_created',
|
||||
'game',
|
||||
'dice',
|
||||
'document',
|
||||
'delete_chat_photo',
|
||||
'contact',
|
||||
'channel_chat_created',
|
||||
'audio',
|
||||
'connected_website',
|
||||
'passport_data',
|
||||
'poll',
|
||||
'forward_date'
|
||||
]
|
||||
|
||||
const MessageSubTypesMapping = {
|
||||
forward_date: 'forward'
|
||||
}
|
||||
|
||||
class TelegrafContext {
|
||||
constructor (update, telegram, options) {
|
||||
this.tg = telegram
|
||||
this.update = update
|
||||
this.options = options
|
||||
this.updateType = UpdateTypes.find((key) => key in this.update)
|
||||
if (this.updateType === 'message' || (this.options.channelMode && this.updateType === 'channel_post')) {
|
||||
this.updateSubTypes = MessageSubTypes
|
||||
.filter((key) => key in this.update[this.updateType])
|
||||
.map((type) => MessageSubTypesMapping[type] || type)
|
||||
} else {
|
||||
this.updateSubTypes = []
|
||||
}
|
||||
Object.getOwnPropertyNames(TelegrafContext.prototype)
|
||||
.filter((key) => key !== 'constructor' && typeof this[key] === 'function')
|
||||
.forEach((key) => (this[key] = this[key].bind(this)))
|
||||
}
|
||||
|
||||
get me () {
|
||||
return this.options && this.options.username
|
||||
}
|
||||
|
||||
get telegram () {
|
||||
return this.tg
|
||||
}
|
||||
|
||||
get message () {
|
||||
return this.update.message
|
||||
}
|
||||
|
||||
get editedMessage () {
|
||||
return this.update.edited_message
|
||||
}
|
||||
|
||||
get inlineQuery () {
|
||||
return this.update.inline_query
|
||||
}
|
||||
|
||||
get shippingQuery () {
|
||||
return this.update.shipping_query
|
||||
}
|
||||
|
||||
get preCheckoutQuery () {
|
||||
return this.update.pre_checkout_query
|
||||
}
|
||||
|
||||
get chosenInlineResult () {
|
||||
return this.update.chosen_inline_result
|
||||
}
|
||||
|
||||
get channelPost () {
|
||||
return this.update.channel_post
|
||||
}
|
||||
|
||||
get editedChannelPost () {
|
||||
return this.update.edited_channel_post
|
||||
}
|
||||
|
||||
get callbackQuery () {
|
||||
return this.update.callback_query
|
||||
}
|
||||
|
||||
get poll () {
|
||||
return this.update.poll
|
||||
}
|
||||
|
||||
get pollAnswer () {
|
||||
return this.update.poll_answer
|
||||
}
|
||||
|
||||
get chat () {
|
||||
return (this.message && this.message.chat) ||
|
||||
(this.editedMessage && this.editedMessage.chat) ||
|
||||
(this.callbackQuery && this.callbackQuery.message && this.callbackQuery.message.chat) ||
|
||||
(this.channelPost && this.channelPost.chat) ||
|
||||
(this.editedChannelPost && this.editedChannelPost.chat)
|
||||
}
|
||||
|
||||
get from () {
|
||||
return (this.message && this.message.from) ||
|
||||
(this.editedMessage && this.editedMessage.from) ||
|
||||
(this.callbackQuery && this.callbackQuery.from) ||
|
||||
(this.inlineQuery && this.inlineQuery.from) ||
|
||||
(this.channelPost && this.channelPost.from) ||
|
||||
(this.editedChannelPost && this.editedChannelPost.from) ||
|
||||
(this.shippingQuery && this.shippingQuery.from) ||
|
||||
(this.preCheckoutQuery && this.preCheckoutQuery.from) ||
|
||||
(this.chosenInlineResult && this.chosenInlineResult.from)
|
||||
}
|
||||
|
||||
get inlineMessageId () {
|
||||
return (this.callbackQuery && this.callbackQuery.inline_message_id) || (this.chosenInlineResult && this.chosenInlineResult.inline_message_id)
|
||||
}
|
||||
|
||||
get passportData () {
|
||||
return this.message && this.message.passport_data
|
||||
}
|
||||
|
||||
get state () {
|
||||
if (!this.contextState) {
|
||||
this.contextState = {}
|
||||
}
|
||||
return this.contextState
|
||||
}
|
||||
|
||||
set state (value) {
|
||||
this.contextState = { ...value }
|
||||
}
|
||||
|
||||
get webhookReply () {
|
||||
return this.tg.webhookReply
|
||||
}
|
||||
|
||||
set webhookReply (enable) {
|
||||
this.tg.webhookReply = enable
|
||||
}
|
||||
|
||||
assert (value, method) {
|
||||
if (!value) {
|
||||
throw new Error(`Telegraf: "${method}" isn't available for "${this.updateType}::${this.updateSubTypes}"`)
|
||||
}
|
||||
}
|
||||
|
||||
answerInlineQuery (...args) {
|
||||
this.assert(this.inlineQuery, 'answerInlineQuery')
|
||||
return this.telegram.answerInlineQuery(this.inlineQuery.id, ...args)
|
||||
}
|
||||
|
||||
answerCbQuery (...args) {
|
||||
this.assert(this.callbackQuery, 'answerCbQuery')
|
||||
return this.telegram.answerCbQuery(this.callbackQuery.id, ...args)
|
||||
}
|
||||
|
||||
answerGameQuery (...args) {
|
||||
this.assert(this.callbackQuery, 'answerGameQuery')
|
||||
return this.telegram.answerGameQuery(this.callbackQuery.id, ...args)
|
||||
}
|
||||
|
||||
answerShippingQuery (...args) {
|
||||
this.assert(this.shippingQuery, 'answerShippingQuery')
|
||||
return this.telegram.answerShippingQuery(this.shippingQuery.id, ...args)
|
||||
}
|
||||
|
||||
answerPreCheckoutQuery (...args) {
|
||||
this.assert(this.preCheckoutQuery, 'answerPreCheckoutQuery')
|
||||
return this.telegram.answerPreCheckoutQuery(this.preCheckoutQuery.id, ...args)
|
||||
}
|
||||
|
||||
editMessageText (text, extra) {
|
||||
this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageText')
|
||||
return this.inlineMessageId
|
||||
? this.telegram.editMessageText(
|
||||
undefined,
|
||||
undefined,
|
||||
this.inlineMessageId,
|
||||
text,
|
||||
extra
|
||||
)
|
||||
: this.telegram.editMessageText(
|
||||
this.chat.id,
|
||||
this.callbackQuery.message.message_id,
|
||||
undefined,
|
||||
text,
|
||||
extra
|
||||
)
|
||||
}
|
||||
|
||||
editMessageCaption (caption, extra) {
|
||||
this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageCaption')
|
||||
return this.inlineMessageId
|
||||
? this.telegram.editMessageCaption(
|
||||
undefined,
|
||||
undefined,
|
||||
this.inlineMessageId,
|
||||
caption,
|
||||
extra
|
||||
)
|
||||
: this.telegram.editMessageCaption(
|
||||
this.chat.id,
|
||||
this.callbackQuery.message.message_id,
|
||||
undefined,
|
||||
caption,
|
||||
extra
|
||||
)
|
||||
}
|
||||
|
||||
editMessageMedia (media, extra) {
|
||||
this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageMedia')
|
||||
return this.inlineMessageId
|
||||
? this.telegram.editMessageMedia(
|
||||
undefined,
|
||||
undefined,
|
||||
this.inlineMessageId,
|
||||
media,
|
||||
extra
|
||||
)
|
||||
: this.telegram.editMessageMedia(
|
||||
this.chat.id,
|
||||
this.callbackQuery.message.message_id,
|
||||
undefined,
|
||||
media,
|
||||
extra
|
||||
)
|
||||
}
|
||||
|
||||
editMessageReplyMarkup (markup) {
|
||||
this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageReplyMarkup')
|
||||
return this.inlineMessageId
|
||||
? this.telegram.editMessageReplyMarkup(
|
||||
undefined,
|
||||
undefined,
|
||||
this.inlineMessageId,
|
||||
markup
|
||||
)
|
||||
: this.telegram.editMessageReplyMarkup(
|
||||
this.chat.id,
|
||||
this.callbackQuery.message.message_id,
|
||||
undefined,
|
||||
markup
|
||||
)
|
||||
}
|
||||
|
||||
editMessageLiveLocation (latitude, longitude, markup) {
|
||||
this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageLiveLocation')
|
||||
return this.inlineMessageId
|
||||
? this.telegram.editMessageLiveLocation(
|
||||
latitude,
|
||||
longitude,
|
||||
undefined,
|
||||
undefined,
|
||||
this.inlineMessageId,
|
||||
markup
|
||||
)
|
||||
: this.telegram.editMessageLiveLocation(
|
||||
latitude,
|
||||
longitude,
|
||||
this.chat.id,
|
||||
this.callbackQuery.message.message_id,
|
||||
undefined,
|
||||
markup
|
||||
)
|
||||
}
|
||||
|
||||
stopMessageLiveLocation (markup) {
|
||||
this.assert(this.callbackQuery || this.inlineMessageId, 'stopMessageLiveLocation')
|
||||
return this.inlineMessageId
|
||||
? this.telegram.stopMessageLiveLocation(
|
||||
undefined,
|
||||
undefined,
|
||||
this.inlineMessageId,
|
||||
markup
|
||||
)
|
||||
: this.telegram.stopMessageLiveLocation(
|
||||
this.chat.id,
|
||||
this.callbackQuery.message.message_id,
|
||||
undefined,
|
||||
markup
|
||||
)
|
||||
}
|
||||
|
||||
reply (...args) {
|
||||
this.assert(this.chat, 'reply')
|
||||
return this.telegram.sendMessage(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
getChat (...args) {
|
||||
this.assert(this.chat, 'getChat')
|
||||
return this.telegram.getChat(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
exportChatInviteLink (...args) {
|
||||
this.assert(this.chat, 'exportChatInviteLink')
|
||||
return this.telegram.exportChatInviteLink(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
kickChatMember (...args) {
|
||||
this.assert(this.chat, 'kickChatMember')
|
||||
return this.telegram.kickChatMember(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
restrictChatMember (...args) {
|
||||
this.assert(this.chat, 'restrictChatMember')
|
||||
return this.telegram.restrictChatMember(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
promoteChatMember (...args) {
|
||||
this.assert(this.chat, 'promoteChatMember')
|
||||
return this.telegram.promoteChatMember(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
setChatAdministratorCustomTitle (...args) {
|
||||
this.assert(this.chat, 'setChatAdministratorCustomTitle')
|
||||
return this.telegram.setChatAdministratorCustomTitle(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
setChatPhoto (...args) {
|
||||
this.assert(this.chat, 'setChatPhoto')
|
||||
return this.telegram.setChatPhoto(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
deleteChatPhoto (...args) {
|
||||
this.assert(this.chat, 'deleteChatPhoto')
|
||||
return this.telegram.deleteChatPhoto(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
setChatTitle (...args) {
|
||||
this.assert(this.chat, 'setChatTitle')
|
||||
return this.telegram.setChatTitle(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
setChatDescription (...args) {
|
||||
this.assert(this.chat, 'setChatDescription')
|
||||
return this.telegram.setChatDescription(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
pinChatMessage (...args) {
|
||||
this.assert(this.chat, 'pinChatMessage')
|
||||
return this.telegram.pinChatMessage(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
unpinChatMessage (...args) {
|
||||
this.assert(this.chat, 'unpinChatMessage')
|
||||
return this.telegram.unpinChatMessage(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
leaveChat (...args) {
|
||||
this.assert(this.chat, 'leaveChat')
|
||||
return this.telegram.leaveChat(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
setChatPermissions (...args) {
|
||||
this.assert(this.chat, 'setChatPermissions')
|
||||
return this.telegram.setChatPermissions(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
getChatAdministrators (...args) {
|
||||
this.assert(this.chat, 'getChatAdministrators')
|
||||
return this.telegram.getChatAdministrators(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
getChatMember (...args) {
|
||||
this.assert(this.chat, 'getChatMember')
|
||||
return this.telegram.getChatMember(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
getChatMembersCount (...args) {
|
||||
this.assert(this.chat, 'getChatMembersCount')
|
||||
return this.telegram.getChatMembersCount(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
setPassportDataErrors (errors) {
|
||||
this.assert(this.chat, 'setPassportDataErrors')
|
||||
return this.telegram.setPassportDataErrors(this.from.id, errors)
|
||||
}
|
||||
|
||||
replyWithPhoto (...args) {
|
||||
this.assert(this.chat, 'replyWithPhoto')
|
||||
return this.telegram.sendPhoto(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithMediaGroup (...args) {
|
||||
this.assert(this.chat, 'replyWithMediaGroup')
|
||||
return this.telegram.sendMediaGroup(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithAudio (...args) {
|
||||
this.assert(this.chat, 'replyWithAudio')
|
||||
return this.telegram.sendAudio(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithDice (...args) {
|
||||
this.assert(this.chat, 'replyWithDice')
|
||||
return this.telegram.sendDice(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithDocument (...args) {
|
||||
this.assert(this.chat, 'replyWithDocument')
|
||||
return this.telegram.sendDocument(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithSticker (...args) {
|
||||
this.assert(this.chat, 'replyWithSticker')
|
||||
return this.telegram.sendSticker(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithVideo (...args) {
|
||||
this.assert(this.chat, 'replyWithVideo')
|
||||
return this.telegram.sendVideo(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithAnimation (...args) {
|
||||
this.assert(this.chat, 'replyWithAnimation')
|
||||
return this.telegram.sendAnimation(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithVideoNote (...args) {
|
||||
this.assert(this.chat, 'replyWithVideoNote')
|
||||
return this.telegram.sendVideoNote(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithInvoice (...args) {
|
||||
this.assert(this.chat, 'replyWithInvoice')
|
||||
return this.telegram.sendInvoice(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithGame (...args) {
|
||||
this.assert(this.chat, 'replyWithGame')
|
||||
return this.telegram.sendGame(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithVoice (...args) {
|
||||
this.assert(this.chat, 'replyWithVoice')
|
||||
return this.telegram.sendVoice(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithPoll (...args) {
|
||||
this.assert(this.chat, 'replyWithPoll')
|
||||
return this.telegram.sendPoll(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithQuiz (...args) {
|
||||
this.assert(this.chat, 'replyWithQuiz')
|
||||
return this.telegram.sendQuiz(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
stopPoll (...args) {
|
||||
this.assert(this.chat, 'stopPoll')
|
||||
return this.telegram.stopPoll(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithChatAction (...args) {
|
||||
this.assert(this.chat, 'replyWithChatAction')
|
||||
return this.telegram.sendChatAction(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithLocation (...args) {
|
||||
this.assert(this.chat, 'replyWithLocation')
|
||||
return this.telegram.sendLocation(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithVenue (...args) {
|
||||
this.assert(this.chat, 'replyWithVenue')
|
||||
return this.telegram.sendVenue(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
replyWithContact (...args) {
|
||||
this.assert(this.from, 'replyWithContact')
|
||||
return this.telegram.sendContact(this.chat.id, ...args)
|
||||
}
|
||||
|
||||
getStickerSet (setName) {
|
||||
return this.telegram.getStickerSet(setName)
|
||||
}
|
||||
|
||||
setChatStickerSet (setName) {
|
||||
this.assert(this.chat, 'setChatStickerSet')
|
||||
return this.telegram.setChatStickerSet(this.chat.id, setName)
|
||||
}
|
||||
|
||||
deleteChatStickerSet () {
|
||||
this.assert(this.chat, 'deleteChatStickerSet')
|
||||
return this.telegram.deleteChatStickerSet(this.chat.id)
|
||||
}
|
||||
|
||||
setStickerPositionInSet (sticker, position) {
|
||||
return this.telegram.setStickerPositionInSet(sticker, position)
|
||||
}
|
||||
|
||||
setStickerSetThumb (...args) {
|
||||
return this.telegram.setStickerSetThumb(...args)
|
||||
}
|
||||
|
||||
deleteStickerFromSet (sticker) {
|
||||
return this.telegram.deleteStickerFromSet(sticker)
|
||||
}
|
||||
|
||||
uploadStickerFile (...args) {
|
||||
this.assert(this.from, 'uploadStickerFile')
|
||||
return this.telegram.uploadStickerFile(this.from.id, ...args)
|
||||
}
|
||||
|
||||
createNewStickerSet (...args) {
|
||||
this.assert(this.from, 'createNewStickerSet')
|
||||
return this.telegram.createNewStickerSet(this.from.id, ...args)
|
||||
}
|
||||
|
||||
addStickerToSet (...args) {
|
||||
this.assert(this.from, 'addStickerToSet')
|
||||
return this.telegram.addStickerToSet(this.from.id, ...args)
|
||||
}
|
||||
|
||||
getMyCommands () {
|
||||
return this.telegram.getMyCommands()
|
||||
}
|
||||
|
||||
setMyCommands (...args) {
|
||||
return this.telegram.setMyCommands(...args)
|
||||
}
|
||||
|
||||
replyWithMarkdown (markdown, extra) {
|
||||
return this.reply(markdown, { parse_mode: 'Markdown', ...extra })
|
||||
}
|
||||
|
||||
replyWithMarkdownV2 (markdown, extra) {
|
||||
return this.reply(markdown, { parse_mode: 'MarkdownV2', ...extra })
|
||||
}
|
||||
|
||||
replyWithHTML (html, extra) {
|
||||
return this.reply(html, { parse_mode: 'HTML', ...extra })
|
||||
}
|
||||
|
||||
deleteMessage (messageId) {
|
||||
this.assert(this.chat, 'deleteMessage')
|
||||
if (typeof messageId !== 'undefined') {
|
||||
return this.telegram.deleteMessage(this.chat.id, messageId)
|
||||
}
|
||||
const message = this.message ||
|
||||
this.editedMessage ||
|
||||
this.channelPost ||
|
||||
this.editedChannelPost ||
|
||||
(this.callbackQuery && this.callbackQuery.message)
|
||||
this.assert(message, 'deleteMessage')
|
||||
return this.telegram.deleteMessage(this.chat.id, message.message_id)
|
||||
}
|
||||
|
||||
forwardMessage (chatId, extra) {
|
||||
this.assert(this.chat, 'forwardMessage')
|
||||
const message = this.message ||
|
||||
this.editedMessage ||
|
||||
this.channelPost ||
|
||||
this.editedChannelPost ||
|
||||
(this.callbackQuery && this.callbackQuery.message)
|
||||
this.assert(message, 'forwardMessage')
|
||||
return this.telegram.forwardMessage(chatId, this.chat.id, message.message_id, extra)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TelegrafContext
|
||||
288
node_modules/telegraf/core/network/client.js
generated
vendored
Normal file
288
node_modules/telegraf/core/network/client.js
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
const debug = require('debug')('telegraf:client')
|
||||
const crypto = require('crypto')
|
||||
const fetch = require('node-fetch').default
|
||||
const fs = require('fs')
|
||||
const https = require('https')
|
||||
const path = require('path')
|
||||
const TelegramError = require('./error')
|
||||
const MultipartStream = require('./multipart-stream')
|
||||
const { isStream } = MultipartStream
|
||||
|
||||
const WEBHOOK_BLACKLIST = [
|
||||
'getChat',
|
||||
'getChatAdministrators',
|
||||
'getChatMember',
|
||||
'getChatMembersCount',
|
||||
'getFile',
|
||||
'getFileLink',
|
||||
'getGameHighScores',
|
||||
'getMe',
|
||||
'getUserProfilePhotos',
|
||||
'getWebhookInfo',
|
||||
'exportChatInviteLink'
|
||||
]
|
||||
|
||||
const DEFAULT_EXTENSIONS = {
|
||||
audio: 'mp3',
|
||||
photo: 'jpg',
|
||||
sticker: 'webp',
|
||||
video: 'mp4',
|
||||
animation: 'mp4',
|
||||
video_note: 'mp4',
|
||||
voice: 'ogg'
|
||||
}
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
apiRoot: 'https://api.telegram.org',
|
||||
webhookReply: true,
|
||||
agent: new https.Agent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 10000
|
||||
})
|
||||
}
|
||||
|
||||
const WEBHOOK_REPLY_STUB = {
|
||||
webhook: true,
|
||||
details: 'https://core.telegram.org/bots/api#making-requests-when-getting-updates'
|
||||
}
|
||||
|
||||
function safeJSONParse (text) {
|
||||
try {
|
||||
return JSON.parse(text)
|
||||
} catch (err) {
|
||||
debug('JSON parse failed', err)
|
||||
}
|
||||
}
|
||||
|
||||
function includesMedia (payload) {
|
||||
return Object.keys(payload).some(
|
||||
(key) => {
|
||||
const value = payload[key]
|
||||
if (Array.isArray(value)) {
|
||||
return value.some(({ media }) => media && typeof media === 'object' && (media.source || media.url))
|
||||
}
|
||||
return (typeof value === 'object') && (
|
||||
value.source ||
|
||||
value.url ||
|
||||
(typeof value.media === 'object' && (value.media.source || value.media.url))
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function buildJSONConfig (payload) {
|
||||
return Promise.resolve({
|
||||
method: 'POST',
|
||||
compress: true,
|
||||
headers: { 'content-type': 'application/json', connection: 'keep-alive' },
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
const FORM_DATA_JSON_FIELDS = [
|
||||
'results',
|
||||
'reply_markup',
|
||||
'mask_position',
|
||||
'shipping_options',
|
||||
'errors'
|
||||
]
|
||||
|
||||
function buildFormDataConfig (payload, agent) {
|
||||
for (const field of FORM_DATA_JSON_FIELDS) {
|
||||
if (field in payload && typeof payload[field] !== 'string') {
|
||||
payload[field] = JSON.stringify(payload[field])
|
||||
}
|
||||
}
|
||||
const boundary = crypto.randomBytes(32).toString('hex')
|
||||
const formData = new MultipartStream(boundary)
|
||||
const tasks = Object.keys(payload).map((key) => attachFormValue(formData, key, payload[key], agent))
|
||||
return Promise.all(tasks).then(() => {
|
||||
return {
|
||||
method: 'POST',
|
||||
compress: true,
|
||||
headers: { 'content-type': `multipart/form-data; boundary=${boundary}`, connection: 'keep-alive' },
|
||||
body: formData
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function attachFormValue (form, id, value, agent) {
|
||||
if (!value) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
const valueType = typeof value
|
||||
if (valueType === 'string' || valueType === 'boolean' || valueType === 'number') {
|
||||
form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"` },
|
||||
body: `${value}`
|
||||
})
|
||||
return Promise.resolve()
|
||||
}
|
||||
if (id === 'thumb') {
|
||||
const attachmentId = crypto.randomBytes(16).toString('hex')
|
||||
return attachFormMedia(form, value, attachmentId, agent)
|
||||
.then(() => form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"` },
|
||||
body: `attach://${attachmentId}`
|
||||
}))
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return Promise.all(
|
||||
value.map((item) => {
|
||||
if (typeof item.media !== 'object') {
|
||||
return Promise.resolve(item)
|
||||
}
|
||||
const attachmentId = crypto.randomBytes(16).toString('hex')
|
||||
return attachFormMedia(form, item.media, attachmentId, agent)
|
||||
.then(() => ({ ...item, media: `attach://${attachmentId}` }))
|
||||
})
|
||||
).then((items) => form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"` },
|
||||
body: JSON.stringify(items)
|
||||
}))
|
||||
}
|
||||
if (typeof value.media !== 'undefined' && typeof value.type !== 'undefined') {
|
||||
const attachmentId = crypto.randomBytes(16).toString('hex')
|
||||
return attachFormMedia(form, value.media, attachmentId, agent)
|
||||
.then(() => form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"` },
|
||||
body: JSON.stringify({
|
||||
...value,
|
||||
media: `attach://${attachmentId}`
|
||||
})
|
||||
}))
|
||||
}
|
||||
return attachFormMedia(form, value, id, agent)
|
||||
}
|
||||
|
||||
function attachFormMedia (form, media, id, agent) {
|
||||
let fileName = media.filename || `${id}.${DEFAULT_EXTENSIONS[id] || 'dat'}`
|
||||
if (media.url) {
|
||||
return fetch(media.url, { agent }).then((res) =>
|
||||
form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"; filename="${fileName}"` },
|
||||
body: res.body
|
||||
})
|
||||
)
|
||||
}
|
||||
if (media.source) {
|
||||
if (fs.existsSync(media.source)) {
|
||||
fileName = media.filename || path.basename(media.source)
|
||||
media.source = fs.createReadStream(media.source)
|
||||
}
|
||||
if (isStream(media.source) || Buffer.isBuffer(media.source)) {
|
||||
form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"; filename="${fileName}"` },
|
||||
body: media.source
|
||||
})
|
||||
}
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function isKoaResponse (response) {
|
||||
return typeof response.set === 'function' && typeof response.header === 'object'
|
||||
}
|
||||
|
||||
function answerToWebhook (response, payload = {}, options) {
|
||||
if (!includesMedia(payload)) {
|
||||
if (isKoaResponse(response)) {
|
||||
response.body = payload
|
||||
return Promise.resolve(WEBHOOK_REPLY_STUB)
|
||||
}
|
||||
if (!response.headersSent) {
|
||||
response.setHeader('content-type', 'application/json')
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
if (response.end.length === 2) {
|
||||
response.end(JSON.stringify(payload), 'utf-8')
|
||||
return resolve(WEBHOOK_REPLY_STUB)
|
||||
}
|
||||
response.end(JSON.stringify(payload), 'utf-8', () => resolve(WEBHOOK_REPLY_STUB))
|
||||
})
|
||||
}
|
||||
|
||||
return buildFormDataConfig(payload, options.agent)
|
||||
.then(({ headers, body }) => {
|
||||
if (isKoaResponse(response)) {
|
||||
Object.keys(headers).forEach(key => response.set(key, headers[key]))
|
||||
response.body = body
|
||||
return Promise.resolve(WEBHOOK_REPLY_STUB)
|
||||
}
|
||||
if (!response.headersSent) {
|
||||
Object.keys(headers).forEach(key => response.setHeader(key, headers[key]))
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
response.on('finish', () => resolve(WEBHOOK_REPLY_STUB))
|
||||
body.pipe(response)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
class ApiClient {
|
||||
constructor (token, options, webhookResponse) {
|
||||
this.token = token
|
||||
this.options = {
|
||||
...DEFAULT_OPTIONS,
|
||||
...options
|
||||
}
|
||||
if (this.options.apiRoot.startsWith('http://')) {
|
||||
this.options.agent = null
|
||||
}
|
||||
this.response = webhookResponse
|
||||
}
|
||||
|
||||
set webhookReply (enable) {
|
||||
this.options.webhookReply = enable
|
||||
}
|
||||
|
||||
get webhookReply () {
|
||||
return this.options.webhookReply
|
||||
}
|
||||
|
||||
callApi (method, data = {}) {
|
||||
const { token, options, response, responseEnd } = this
|
||||
|
||||
const payload = Object.keys(data)
|
||||
.filter((key) => typeof data[key] !== 'undefined' && data[key] !== null)
|
||||
.reduce((acc, key) => ({ ...acc, [key]: data[key] }), {})
|
||||
|
||||
if (options.webhookReply && response && !responseEnd && !WEBHOOK_BLACKLIST.includes(method)) {
|
||||
debug('Call via webhook', method, payload)
|
||||
this.responseEnd = true
|
||||
return answerToWebhook(response, { method, ...payload }, options)
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
throw new TelegramError({ error_code: 401, description: 'Bot Token is required' })
|
||||
}
|
||||
|
||||
debug('HTTP call', method, payload)
|
||||
const buildConfig = includesMedia(payload)
|
||||
? buildFormDataConfig({ method, ...payload }, options.agent)
|
||||
: buildJSONConfig(payload)
|
||||
return buildConfig
|
||||
.then((config) => {
|
||||
const apiUrl = `${options.apiRoot}/bot${token}/${method}`
|
||||
config.agent = options.agent
|
||||
return fetch(apiUrl, config)
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.then((text) => {
|
||||
return safeJSONParse(text) || {
|
||||
error_code: 500,
|
||||
description: 'Unsupported http response from Telegram',
|
||||
response: text
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
if (!data.ok) {
|
||||
debug('API call failed', data)
|
||||
throw new TelegramError(data, { method, payload })
|
||||
}
|
||||
return data.result
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ApiClient
|
||||
12
node_modules/telegraf/core/network/error.js
generated
vendored
Normal file
12
node_modules/telegraf/core/network/error.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
class TelegramError extends Error {
|
||||
constructor (payload = {}, on) {
|
||||
super(`${payload.error_code}: ${payload.description}`)
|
||||
this.code = payload.error_code
|
||||
this.response = payload
|
||||
this.description = payload.description
|
||||
this.parameters = payload.parameters || {}
|
||||
this.on = on || {}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TelegramError
|
||||
37
node_modules/telegraf/core/network/multipart-stream.js
generated
vendored
Normal file
37
node_modules/telegraf/core/network/multipart-stream.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
const stream = require('stream')
|
||||
const { SandwichStream } = require('sandwich-stream')
|
||||
const CRNL = '\r\n'
|
||||
|
||||
class MultipartStream extends SandwichStream {
|
||||
constructor (boundary) {
|
||||
super({
|
||||
head: `--${boundary}${CRNL}`,
|
||||
tail: `${CRNL}--${boundary}--`,
|
||||
separator: `${CRNL}--${boundary}${CRNL}`
|
||||
})
|
||||
}
|
||||
|
||||
addPart (part) {
|
||||
part = part || {}
|
||||
const partStream = new stream.PassThrough()
|
||||
if (part.headers) {
|
||||
for (const key in part.headers) {
|
||||
const header = part.headers[key]
|
||||
partStream.write(`${key}:${header}${CRNL}`)
|
||||
}
|
||||
}
|
||||
partStream.write(CRNL)
|
||||
if (MultipartStream.isStream(part.body)) {
|
||||
part.body.pipe(partStream)
|
||||
} else {
|
||||
partStream.end(part.body)
|
||||
}
|
||||
this.add(partStream)
|
||||
}
|
||||
|
||||
static isStream (stream) {
|
||||
return stream && typeof stream === 'object' && typeof stream.pipe === 'function'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultipartStream
|
||||
39
node_modules/telegraf/core/network/webhook.js
generated
vendored
Normal file
39
node_modules/telegraf/core/network/webhook.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
const debug = require('debug')('telegraf:webhook')
|
||||
|
||||
module.exports = function (hookPath, updateHandler, errorHandler) {
|
||||
return (req, res, next) => {
|
||||
debug('Incoming request', req.method, req.url)
|
||||
if (req.method !== 'POST' || req.url !== hookPath) {
|
||||
if (typeof next === 'function') {
|
||||
return next()
|
||||
}
|
||||
res.statusCode = 403
|
||||
return res.end()
|
||||
}
|
||||
let body = ''
|
||||
req.on('data', (chunk) => {
|
||||
body += chunk.toString()
|
||||
})
|
||||
req.on('end', () => {
|
||||
let update = {}
|
||||
try {
|
||||
update = JSON.parse(body)
|
||||
} catch (error) {
|
||||
res.writeHead(415)
|
||||
res.end()
|
||||
return errorHandler(error)
|
||||
}
|
||||
updateHandler(update, res)
|
||||
.then(() => {
|
||||
if (!res.finished) {
|
||||
res.end()
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
debug('Webhook error', err)
|
||||
res.writeHead(500)
|
||||
res.end()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
140
node_modules/telegraf/core/replicators.js
generated
vendored
Normal file
140
node_modules/telegraf/core/replicators.js
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
const { formatHTML } = require('../markup')
|
||||
|
||||
module.exports = {
|
||||
copyMethods: {
|
||||
audio: 'sendAudio',
|
||||
contact: 'sendContact',
|
||||
document: 'sendDocument',
|
||||
location: 'sendLocation',
|
||||
photo: 'sendPhoto',
|
||||
sticker: 'sendSticker',
|
||||
text: 'sendMessage',
|
||||
venue: 'sendVenue',
|
||||
video: 'sendVideo',
|
||||
video_note: 'sendVideoNote',
|
||||
animation: 'sendAnimation',
|
||||
voice: 'sendVoice',
|
||||
poll: 'sendPoll'
|
||||
},
|
||||
text: (message) => {
|
||||
const entities = message.entities || []
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
parse_mode: entities.length > 0 ? 'HTML' : '',
|
||||
text: formatHTML(message.text, entities)
|
||||
}
|
||||
},
|
||||
contact: (message) => {
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
phone_number: message.contact.phone_number,
|
||||
first_name: message.contact.first_name,
|
||||
last_name: message.contact.last_name
|
||||
}
|
||||
},
|
||||
location: (message) => {
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
latitude: message.location.latitude,
|
||||
longitude: message.location.longitude
|
||||
}
|
||||
},
|
||||
venue: (message) => {
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
latitude: message.venue.location.latitude,
|
||||
longitude: message.venue.location.longitude,
|
||||
title: message.venue.title,
|
||||
address: message.venue.address,
|
||||
foursquare_id: message.venue.foursquare_id
|
||||
}
|
||||
},
|
||||
voice: (message) => {
|
||||
const entities = message.caption_entities || []
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
voice: message.voice.file_id,
|
||||
duration: message.voice.duration,
|
||||
caption: formatHTML(message.caption, entities),
|
||||
parse_mode: entities.length > 0 ? 'HTML' : ''
|
||||
}
|
||||
},
|
||||
audio: (message) => {
|
||||
const entities = message.caption_entities || []
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
audio: message.audio.file_id,
|
||||
thumb: message.audio.thumb,
|
||||
duration: message.audio.duration,
|
||||
performer: message.audio.performer,
|
||||
title: message.audio.title,
|
||||
caption: formatHTML(message.caption, entities),
|
||||
parse_mode: entities.length > 0 ? 'HTML' : ''
|
||||
}
|
||||
},
|
||||
video: (message) => {
|
||||
const entities = message.caption_entities || []
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
video: message.video.file_id,
|
||||
thumb: message.video.thumb,
|
||||
caption: formatHTML(message.caption, entities),
|
||||
parse_mode: entities.length > 0 ? 'HTML' : '',
|
||||
duration: message.video.duration,
|
||||
width: message.video.width,
|
||||
height: message.video.height,
|
||||
supports_streaming: !!message.video.supports_streaming
|
||||
}
|
||||
},
|
||||
document: (message) => {
|
||||
const entities = message.caption_entities || []
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
document: message.document.file_id,
|
||||
caption: formatHTML(message.caption, entities),
|
||||
parse_mode: entities.length > 0 ? 'HTML' : ''
|
||||
}
|
||||
},
|
||||
sticker: (message) => {
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
sticker: message.sticker.file_id
|
||||
}
|
||||
},
|
||||
photo: (message) => {
|
||||
const entities = message.caption_entities || []
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
photo: message.photo[message.photo.length - 1].file_id,
|
||||
parse_mode: entities.length > 0 ? 'HTML' : '',
|
||||
caption: formatHTML(message.caption, entities)
|
||||
}
|
||||
},
|
||||
video_note: (message) => {
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
video_note: message.video_note.file_id,
|
||||
thumb: message.video_note.thumb,
|
||||
length: message.video_note.length,
|
||||
duration: message.video_note.duration
|
||||
}
|
||||
},
|
||||
animation: (message) => {
|
||||
return {
|
||||
reply_markup: message.reply_markup,
|
||||
animation: message.animation.file_id,
|
||||
thumb: message.animation.thumb,
|
||||
duration: message.animation.duration
|
||||
}
|
||||
},
|
||||
poll: (message) => {
|
||||
return {
|
||||
question: message.poll.question,
|
||||
type: message.poll.type,
|
||||
is_anonymous: message.poll.is_anonymous,
|
||||
allows_multiple_answers: message.poll.allows_multiple_answers,
|
||||
correct_option_id: message.poll.correct_option_id,
|
||||
options: message.poll.options.map(({ text }) => text)
|
||||
}
|
||||
}
|
||||
}
|
||||
85
node_modules/telegraf/extra.js
generated
vendored
Normal file
85
node_modules/telegraf/extra.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
const Markup = require('./markup')
|
||||
|
||||
class Extra {
|
||||
constructor (opts) {
|
||||
this.load(opts)
|
||||
}
|
||||
|
||||
load (opts = {}) {
|
||||
return Object.assign(this, opts)
|
||||
}
|
||||
|
||||
inReplyTo (messageId) {
|
||||
this.reply_to_message_id = messageId
|
||||
return this
|
||||
}
|
||||
|
||||
notifications (value = true) {
|
||||
this.disable_notification = !value
|
||||
return this
|
||||
}
|
||||
|
||||
webPreview (value = true) {
|
||||
this.disable_web_page_preview = !value
|
||||
return this
|
||||
}
|
||||
|
||||
markup (markup) {
|
||||
if (typeof markup === 'function') {
|
||||
markup = markup(new Markup())
|
||||
}
|
||||
this.reply_markup = { ...markup }
|
||||
return this
|
||||
}
|
||||
|
||||
HTML (value = true) {
|
||||
this.parse_mode = value ? 'HTML' : undefined
|
||||
return this
|
||||
}
|
||||
|
||||
markdown (value = true) {
|
||||
this.parse_mode = value ? 'Markdown' : undefined
|
||||
return this
|
||||
}
|
||||
|
||||
caption (caption = '') {
|
||||
this.caption = caption
|
||||
return this
|
||||
}
|
||||
|
||||
static inReplyTo (messageId) {
|
||||
return new Extra().inReplyTo(messageId)
|
||||
}
|
||||
|
||||
static notifications (value) {
|
||||
return new Extra().notifications(value)
|
||||
}
|
||||
|
||||
static webPreview (value) {
|
||||
return new Extra().webPreview(value)
|
||||
}
|
||||
|
||||
static load (opts) {
|
||||
return new Extra(opts)
|
||||
}
|
||||
|
||||
static markup (markup) {
|
||||
return new Extra().markup(markup)
|
||||
}
|
||||
|
||||
static HTML (value) {
|
||||
return new Extra().HTML(value)
|
||||
}
|
||||
|
||||
static markdown (value) {
|
||||
return new Extra().markdown(value)
|
||||
}
|
||||
|
||||
static caption (caption) {
|
||||
return new Extra().caption(caption)
|
||||
}
|
||||
}
|
||||
|
||||
Extra.Markup = Markup
|
||||
|
||||
module.exports = Extra
|
||||
242
node_modules/telegraf/markup.js
generated
vendored
Normal file
242
node_modules/telegraf/markup.js
generated
vendored
Normal file
@@ -0,0 +1,242 @@
|
||||
class Markup {
|
||||
forceReply (value = true) {
|
||||
this.force_reply = value
|
||||
return this
|
||||
}
|
||||
|
||||
removeKeyboard (value = true) {
|
||||
this.remove_keyboard = value
|
||||
return this
|
||||
}
|
||||
|
||||
selective (value = true) {
|
||||
this.selective = value
|
||||
return this
|
||||
}
|
||||
|
||||
extra (options) {
|
||||
return {
|
||||
reply_markup: { ...this },
|
||||
...options
|
||||
}
|
||||
}
|
||||
|
||||
keyboard (buttons, options) {
|
||||
const keyboard = buildKeyboard(buttons, { columns: 1, ...options })
|
||||
if (keyboard && keyboard.length > 0) {
|
||||
this.keyboard = keyboard
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
resize (value = true) {
|
||||
this.resize_keyboard = value
|
||||
return this
|
||||
}
|
||||
|
||||
oneTime (value = true) {
|
||||
this.one_time_keyboard = value
|
||||
return this
|
||||
}
|
||||
|
||||
inlineKeyboard (buttons, options) {
|
||||
const keyboard = buildKeyboard(buttons, { columns: buttons.length, ...options })
|
||||
if (keyboard && keyboard.length > 0) {
|
||||
this.inline_keyboard = keyboard
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
button (text, hide) {
|
||||
return Markup.button(text, hide)
|
||||
}
|
||||
|
||||
contactRequestButton (text, hide) {
|
||||
return Markup.contactRequestButton(text, hide)
|
||||
}
|
||||
|
||||
locationRequestButton (text, hide) {
|
||||
return Markup.locationRequestButton(text, hide)
|
||||
}
|
||||
|
||||
urlButton (text, url, hide) {
|
||||
return Markup.urlButton(text, url, hide)
|
||||
}
|
||||
|
||||
callbackButton (text, data, hide) {
|
||||
return Markup.callbackButton(text, data, hide)
|
||||
}
|
||||
|
||||
switchToChatButton (text, value, hide) {
|
||||
return Markup.switchToChatButton(text, value, hide)
|
||||
}
|
||||
|
||||
switchToCurrentChatButton (text, value, hide) {
|
||||
return Markup.switchToCurrentChatButton(text, value, hide)
|
||||
}
|
||||
|
||||
gameButton (text, hide) {
|
||||
return Markup.gameButton(text, hide)
|
||||
}
|
||||
|
||||
payButton (text, hide) {
|
||||
return Markup.payButton(text, hide)
|
||||
}
|
||||
|
||||
loginButton (text, url, opts, hide) {
|
||||
return Markup.loginButton(text, url, opts, hide)
|
||||
}
|
||||
|
||||
static removeKeyboard (value) {
|
||||
return new Markup().removeKeyboard(value)
|
||||
}
|
||||
|
||||
static forceReply (value) {
|
||||
return new Markup().forceReply(value)
|
||||
}
|
||||
|
||||
static keyboard (buttons, options) {
|
||||
return new Markup().keyboard(buttons, options)
|
||||
}
|
||||
|
||||
static inlineKeyboard (buttons, options) {
|
||||
return new Markup().inlineKeyboard(buttons, options)
|
||||
}
|
||||
|
||||
static resize (value = true) {
|
||||
return new Markup().resize(value)
|
||||
}
|
||||
|
||||
static selective (value = true) {
|
||||
return new Markup().selective(value)
|
||||
}
|
||||
|
||||
static oneTime (value = true) {
|
||||
return new Markup().oneTime(value)
|
||||
}
|
||||
|
||||
static button (text, hide = false) {
|
||||
return { text: text, hide: hide }
|
||||
}
|
||||
|
||||
static contactRequestButton (text, hide = false) {
|
||||
return { text: text, request_contact: true, hide: hide }
|
||||
}
|
||||
|
||||
static locationRequestButton (text, hide = false) {
|
||||
return { text: text, request_location: true, hide: hide }
|
||||
}
|
||||
|
||||
static pollRequestButton (text, type, hide = false) {
|
||||
return { text: text, request_poll: { type }, hide: hide }
|
||||
}
|
||||
|
||||
static urlButton (text, url, hide = false) {
|
||||
return { text: text, url: url, hide: hide }
|
||||
}
|
||||
|
||||
static callbackButton (text, data, hide = false) {
|
||||
return { text: text, callback_data: data, hide: hide }
|
||||
}
|
||||
|
||||
static switchToChatButton (text, value, hide = false) {
|
||||
return { text: text, switch_inline_query: value, hide: hide }
|
||||
}
|
||||
|
||||
static switchToCurrentChatButton (text, value, hide = false) {
|
||||
return { text: text, switch_inline_query_current_chat: value, hide: hide }
|
||||
}
|
||||
|
||||
static gameButton (text, hide = false) {
|
||||
return { text: text, callback_game: {}, hide: hide }
|
||||
}
|
||||
|
||||
static payButton (text, hide = false) {
|
||||
return { text: text, pay: true, hide: hide }
|
||||
}
|
||||
|
||||
static loginButton (text, url, opts = {}, hide = false) {
|
||||
return {
|
||||
text: text,
|
||||
login_url: { ...opts, url: url },
|
||||
hide: hide
|
||||
}
|
||||
}
|
||||
|
||||
static formatHTML (text = '', entities = []) {
|
||||
const chars = ['', ...text.split(''), ''].map(escapeHTMLChar)
|
||||
entities.forEach(entity => {
|
||||
const tag = getHTMLTag(entity)
|
||||
const openPos = entity.offset
|
||||
const closePos = entity.offset + entity.length + 1
|
||||
chars[openPos] += tag.open
|
||||
chars[closePos] = tag.close + chars[closePos]
|
||||
})
|
||||
return chars.join('')
|
||||
}
|
||||
}
|
||||
|
||||
function buildKeyboard (buttons, options) {
|
||||
const result = []
|
||||
if (!Array.isArray(buttons)) {
|
||||
return result
|
||||
}
|
||||
if (buttons.find(Array.isArray)) {
|
||||
return buttons.map(row => row.filter((button) => !button.hide))
|
||||
}
|
||||
const wrapFn = options.wrap
|
||||
? options.wrap
|
||||
: (btn, index, currentRow) => currentRow.length >= options.columns
|
||||
let currentRow = []
|
||||
let index = 0
|
||||
for (const btn of buttons.filter((button) => !button.hide)) {
|
||||
if (wrapFn(btn, index, currentRow) && currentRow.length > 0) {
|
||||
result.push(currentRow)
|
||||
currentRow = []
|
||||
}
|
||||
currentRow.push(btn)
|
||||
index++
|
||||
}
|
||||
if (currentRow.length > 0) {
|
||||
result.push(currentRow)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function escapeHTMLChar (c) {
|
||||
switch (c) {
|
||||
case '&': return '&'
|
||||
case '"': return '"'
|
||||
case '\'': return '''
|
||||
case '<': return '<'
|
||||
default : return c
|
||||
}
|
||||
}
|
||||
|
||||
function tag (name, params) {
|
||||
return {
|
||||
open: params
|
||||
? `<${name} ${Object.entries(params).map(([key, value]) => `${key}="${value.replace(/[<&"]/g, escapeHTMLChar)}"`).join(' ')}>`
|
||||
: `<${name}>`,
|
||||
close: `</${name}>`
|
||||
}
|
||||
}
|
||||
|
||||
const HTMLTags = new Map([
|
||||
['bold', tag('b')],
|
||||
['italic', tag('i')],
|
||||
['code', tag('code')],
|
||||
['pre', tag('pre')],
|
||||
['strikethrough', tag('s')],
|
||||
['underline', tag('u')],
|
||||
['text_link', ({ url }) => tag('a', { href: url })],
|
||||
['text_mention', ({ user }) => tag('a', { href: `tg://user?id=${user.id}` })]
|
||||
])
|
||||
|
||||
function getHTMLTag (entity) {
|
||||
const tag = HTMLTags.get(entity.type || 'unknown')
|
||||
if (!tag) return { open: '', close: '' }
|
||||
return typeof tag === 'function' ? tag(entity) : tag
|
||||
}
|
||||
|
||||
module.exports = Markup
|
||||
395
node_modules/telegraf/node_modules/debug/CHANGELOG.md
generated
vendored
Normal file
395
node_modules/telegraf/node_modules/debug/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,395 @@
|
||||
|
||||
3.1.0 / 2017-09-26
|
||||
==================
|
||||
|
||||
* Add `DEBUG_HIDE_DATE` env var (#486)
|
||||
* Remove ReDoS regexp in %o formatter (#504)
|
||||
* Remove "component" from package.json
|
||||
* Remove `component.json`
|
||||
* Ignore package-lock.json
|
||||
* Examples: fix colors printout
|
||||
* Fix: browser detection
|
||||
* Fix: spelling mistake (#496, @EdwardBetts)
|
||||
|
||||
3.0.1 / 2017-08-24
|
||||
==================
|
||||
|
||||
* Fix: Disable colors in Edge and Internet Explorer (#489)
|
||||
|
||||
3.0.0 / 2017-08-08
|
||||
==================
|
||||
|
||||
* Breaking: Remove DEBUG_FD (#406)
|
||||
* Breaking: Use `Date#toISOString()` instead to `Date#toUTCString()` when output is not a TTY (#418)
|
||||
* Breaking: Make millisecond timer namespace specific and allow 'always enabled' output (#408)
|
||||
* Addition: document `enabled` flag (#465)
|
||||
* Addition: add 256 colors mode (#481)
|
||||
* Addition: `enabled()` updates existing debug instances, add `destroy()` function (#440)
|
||||
* Update: component: update "ms" to v2.0.0
|
||||
* Update: separate the Node and Browser tests in Travis-CI
|
||||
* Update: refactor Readme, fixed documentation, added "Namespace Colors" section, redid screenshots
|
||||
* Update: separate Node.js and web browser examples for organization
|
||||
* Update: update "browserify" to v14.4.0
|
||||
* Fix: fix Readme typo (#473)
|
||||
|
||||
2.6.9 / 2017-09-22
|
||||
==================
|
||||
|
||||
* remove ReDoS regexp in %o formatter (#504)
|
||||
|
||||
2.6.8 / 2017-05-18
|
||||
==================
|
||||
|
||||
* Fix: Check for undefined on browser globals (#462, @marbemac)
|
||||
|
||||
2.6.7 / 2017-05-16
|
||||
==================
|
||||
|
||||
* Fix: Update ms to 2.0.0 to fix regular expression denial of service vulnerability (#458, @hubdotcom)
|
||||
* Fix: Inline extend function in node implementation (#452, @dougwilson)
|
||||
* Docs: Fix typo (#455, @msasad)
|
||||
|
||||
2.6.5 / 2017-04-27
|
||||
==================
|
||||
|
||||
* Fix: null reference check on window.documentElement.style.WebkitAppearance (#447, @thebigredgeek)
|
||||
* Misc: clean up browser reference checks (#447, @thebigredgeek)
|
||||
* Misc: add npm-debug.log to .gitignore (@thebigredgeek)
|
||||
|
||||
|
||||
2.6.4 / 2017-04-20
|
||||
==================
|
||||
|
||||
* Fix: bug that would occur if process.env.DEBUG is a non-string value. (#444, @LucianBuzzo)
|
||||
* Chore: ignore bower.json in npm installations. (#437, @joaovieira)
|
||||
* Misc: update "ms" to v0.7.3 (@tootallnate)
|
||||
|
||||
2.6.3 / 2017-03-13
|
||||
==================
|
||||
|
||||
* Fix: Electron reference to `process.env.DEBUG` (#431, @paulcbetts)
|
||||
* Docs: Changelog fix (@thebigredgeek)
|
||||
|
||||
2.6.2 / 2017-03-10
|
||||
==================
|
||||
|
||||
* Fix: DEBUG_MAX_ARRAY_LENGTH (#420, @slavaGanzin)
|
||||
* Docs: Add backers and sponsors from Open Collective (#422, @piamancini)
|
||||
* Docs: Add Slackin invite badge (@tootallnate)
|
||||
|
||||
2.6.1 / 2017-02-10
|
||||
==================
|
||||
|
||||
* Fix: Module's `export default` syntax fix for IE8 `Expected identifier` error
|
||||
* Fix: Whitelist DEBUG_FD for values 1 and 2 only (#415, @pi0)
|
||||
* Fix: IE8 "Expected identifier" error (#414, @vgoma)
|
||||
* Fix: Namespaces would not disable once enabled (#409, @musikov)
|
||||
|
||||
2.6.0 / 2016-12-28
|
||||
==================
|
||||
|
||||
* Fix: added better null pointer checks for browser useColors (@thebigredgeek)
|
||||
* Improvement: removed explicit `window.debug` export (#404, @tootallnate)
|
||||
* Improvement: deprecated `DEBUG_FD` environment variable (#405, @tootallnate)
|
||||
|
||||
2.5.2 / 2016-12-25
|
||||
==================
|
||||
|
||||
* Fix: reference error on window within webworkers (#393, @KlausTrainer)
|
||||
* Docs: fixed README typo (#391, @lurch)
|
||||
* Docs: added notice about v3 api discussion (@thebigredgeek)
|
||||
|
||||
2.5.1 / 2016-12-20
|
||||
==================
|
||||
|
||||
* Fix: babel-core compatibility
|
||||
|
||||
2.5.0 / 2016-12-20
|
||||
==================
|
||||
|
||||
* Fix: wrong reference in bower file (@thebigredgeek)
|
||||
* Fix: webworker compatibility (@thebigredgeek)
|
||||
* Fix: output formatting issue (#388, @kribblo)
|
||||
* Fix: babel-loader compatibility (#383, @escwald)
|
||||
* Misc: removed built asset from repo and publications (@thebigredgeek)
|
||||
* Misc: moved source files to /src (#378, @yamikuronue)
|
||||
* Test: added karma integration and replaced babel with browserify for browser tests (#378, @yamikuronue)
|
||||
* Test: coveralls integration (#378, @yamikuronue)
|
||||
* Docs: simplified language in the opening paragraph (#373, @yamikuronue)
|
||||
|
||||
2.4.5 / 2016-12-17
|
||||
==================
|
||||
|
||||
* Fix: `navigator` undefined in Rhino (#376, @jochenberger)
|
||||
* Fix: custom log function (#379, @hsiliev)
|
||||
* Improvement: bit of cleanup + linting fixes (@thebigredgeek)
|
||||
* Improvement: rm non-maintainted `dist/` dir (#375, @freewil)
|
||||
* Docs: simplified language in the opening paragraph. (#373, @yamikuronue)
|
||||
|
||||
2.4.4 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: work around debug being loaded in preload scripts for electron (#368, @paulcbetts)
|
||||
|
||||
2.4.3 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: navigation.userAgent error for react native (#364, @escwald)
|
||||
|
||||
2.4.2 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: browser colors (#367, @tootallnate)
|
||||
* Misc: travis ci integration (@thebigredgeek)
|
||||
* Misc: added linting and testing boilerplate with sanity check (@thebigredgeek)
|
||||
|
||||
2.4.1 / 2016-12-13
|
||||
==================
|
||||
|
||||
* Fix: typo that broke the package (#356)
|
||||
|
||||
2.4.0 / 2016-12-13
|
||||
==================
|
||||
|
||||
* Fix: bower.json references unbuilt src entry point (#342, @justmatt)
|
||||
* Fix: revert "handle regex special characters" (@tootallnate)
|
||||
* Feature: configurable util.inspect()`options for NodeJS (#327, @tootallnate)
|
||||
* Feature: %O`(big O) pretty-prints objects (#322, @tootallnate)
|
||||
* Improvement: allow colors in workers (#335, @botverse)
|
||||
* Improvement: use same color for same namespace. (#338, @lchenay)
|
||||
|
||||
2.3.3 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: Catch `JSON.stringify()` errors (#195, Jovan Alleyne)
|
||||
* Fix: Returning `localStorage` saved values (#331, Levi Thomason)
|
||||
* Improvement: Don't create an empty object when no `process` (Nathan Rajlich)
|
||||
|
||||
2.3.2 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: be super-safe in index.js as well (@TooTallNate)
|
||||
* Fix: should check whether process exists (Tom Newby)
|
||||
|
||||
2.3.1 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: Added electron compatibility (#324, @paulcbetts)
|
||||
* Improvement: Added performance optimizations (@tootallnate)
|
||||
* Readme: Corrected PowerShell environment variable example (#252, @gimre)
|
||||
* Misc: Removed yarn lock file from source control (#321, @fengmk2)
|
||||
|
||||
2.3.0 / 2016-11-07
|
||||
==================
|
||||
|
||||
* Fix: Consistent placement of ms diff at end of output (#215, @gorangajic)
|
||||
* Fix: Escaping of regex special characters in namespace strings (#250, @zacronos)
|
||||
* Fix: Fixed bug causing crash on react-native (#282, @vkarpov15)
|
||||
* Feature: Enabled ES6+ compatible import via default export (#212 @bucaran)
|
||||
* Feature: Added %O formatter to reflect Chrome's console.log capability (#279, @oncletom)
|
||||
* Package: Update "ms" to 0.7.2 (#315, @DevSide)
|
||||
* Package: removed superfluous version property from bower.json (#207 @kkirsche)
|
||||
* Readme: fix USE_COLORS to DEBUG_COLORS
|
||||
* Readme: Doc fixes for format string sugar (#269, @mlucool)
|
||||
* Readme: Updated docs for DEBUG_FD and DEBUG_COLORS environment variables (#232, @mattlyons0)
|
||||
* Readme: doc fixes for PowerShell (#271 #243, @exoticknight @unreadable)
|
||||
* Readme: better docs for browser support (#224, @matthewmueller)
|
||||
* Tooling: Added yarn integration for development (#317, @thebigredgeek)
|
||||
* Misc: Renamed History.md to CHANGELOG.md (@thebigredgeek)
|
||||
* Misc: Added license file (#226 #274, @CantemoInternal @sdaitzman)
|
||||
* Misc: Updated contributors (@thebigredgeek)
|
||||
|
||||
2.2.0 / 2015-05-09
|
||||
==================
|
||||
|
||||
* package: update "ms" to v0.7.1 (#202, @dougwilson)
|
||||
* README: add logging to file example (#193, @DanielOchoa)
|
||||
* README: fixed a typo (#191, @amir-s)
|
||||
* browser: expose `storage` (#190, @stephenmathieson)
|
||||
* Makefile: add a `distclean` target (#189, @stephenmathieson)
|
||||
|
||||
2.1.3 / 2015-03-13
|
||||
==================
|
||||
|
||||
* Updated stdout/stderr example (#186)
|
||||
* Updated example/stdout.js to match debug current behaviour
|
||||
* Renamed example/stderr.js to stdout.js
|
||||
* Update Readme.md (#184)
|
||||
* replace high intensity foreground color for bold (#182, #183)
|
||||
|
||||
2.1.2 / 2015-03-01
|
||||
==================
|
||||
|
||||
* dist: recompile
|
||||
* update "ms" to v0.7.0
|
||||
* package: update "browserify" to v9.0.3
|
||||
* component: fix "ms.js" repo location
|
||||
* changed bower package name
|
||||
* updated documentation about using debug in a browser
|
||||
* fix: security error on safari (#167, #168, @yields)
|
||||
|
||||
2.1.1 / 2014-12-29
|
||||
==================
|
||||
|
||||
* browser: use `typeof` to check for `console` existence
|
||||
* browser: check for `console.log` truthiness (fix IE 8/9)
|
||||
* browser: add support for Chrome apps
|
||||
* Readme: added Windows usage remarks
|
||||
* Add `bower.json` to properly support bower install
|
||||
|
||||
2.1.0 / 2014-10-15
|
||||
==================
|
||||
|
||||
* node: implement `DEBUG_FD` env variable support
|
||||
* package: update "browserify" to v6.1.0
|
||||
* package: add "license" field to package.json (#135, @panuhorsmalahti)
|
||||
|
||||
2.0.0 / 2014-09-01
|
||||
==================
|
||||
|
||||
* package: update "browserify" to v5.11.0
|
||||
* node: use stderr rather than stdout for logging (#29, @stephenmathieson)
|
||||
|
||||
1.0.4 / 2014-07-15
|
||||
==================
|
||||
|
||||
* dist: recompile
|
||||
* example: remove `console.info()` log usage
|
||||
* example: add "Content-Type" UTF-8 header to browser example
|
||||
* browser: place %c marker after the space character
|
||||
* browser: reset the "content" color via `color: inherit`
|
||||
* browser: add colors support for Firefox >= v31
|
||||
* debug: prefer an instance `log()` function over the global one (#119)
|
||||
* Readme: update documentation about styled console logs for FF v31 (#116, @wryk)
|
||||
|
||||
1.0.3 / 2014-07-09
|
||||
==================
|
||||
|
||||
* Add support for multiple wildcards in namespaces (#122, @seegno)
|
||||
* browser: fix lint
|
||||
|
||||
1.0.2 / 2014-06-10
|
||||
==================
|
||||
|
||||
* browser: update color palette (#113, @gscottolson)
|
||||
* common: make console logging function configurable (#108, @timoxley)
|
||||
* node: fix %o colors on old node <= 0.8.x
|
||||
* Makefile: find node path using shell/which (#109, @timoxley)
|
||||
|
||||
1.0.1 / 2014-06-06
|
||||
==================
|
||||
|
||||
* browser: use `removeItem()` to clear localStorage
|
||||
* browser, node: don't set DEBUG if namespaces is undefined (#107, @leedm777)
|
||||
* package: add "contributors" section
|
||||
* node: fix comment typo
|
||||
* README: list authors
|
||||
|
||||
1.0.0 / 2014-06-04
|
||||
==================
|
||||
|
||||
* make ms diff be global, not be scope
|
||||
* debug: ignore empty strings in enable()
|
||||
* node: make DEBUG_COLORS able to disable coloring
|
||||
* *: export the `colors` array
|
||||
* npmignore: don't publish the `dist` dir
|
||||
* Makefile: refactor to use browserify
|
||||
* package: add "browserify" as a dev dependency
|
||||
* Readme: add Web Inspector Colors section
|
||||
* node: reset terminal color for the debug content
|
||||
* node: map "%o" to `util.inspect()`
|
||||
* browser: map "%j" to `JSON.stringify()`
|
||||
* debug: add custom "formatters"
|
||||
* debug: use "ms" module for humanizing the diff
|
||||
* Readme: add "bash" syntax highlighting
|
||||
* browser: add Firebug color support
|
||||
* browser: add colors for WebKit browsers
|
||||
* node: apply log to `console`
|
||||
* rewrite: abstract common logic for Node & browsers
|
||||
* add .jshintrc file
|
||||
|
||||
0.8.1 / 2014-04-14
|
||||
==================
|
||||
|
||||
* package: re-add the "component" section
|
||||
|
||||
0.8.0 / 2014-03-30
|
||||
==================
|
||||
|
||||
* add `enable()` method for nodejs. Closes #27
|
||||
* change from stderr to stdout
|
||||
* remove unnecessary index.js file
|
||||
|
||||
0.7.4 / 2013-11-13
|
||||
==================
|
||||
|
||||
* remove "browserify" key from package.json (fixes something in browserify)
|
||||
|
||||
0.7.3 / 2013-10-30
|
||||
==================
|
||||
|
||||
* fix: catch localStorage security error when cookies are blocked (Chrome)
|
||||
* add debug(err) support. Closes #46
|
||||
* add .browser prop to package.json. Closes #42
|
||||
|
||||
0.7.2 / 2013-02-06
|
||||
==================
|
||||
|
||||
* fix package.json
|
||||
* fix: Mobile Safari (private mode) is broken with debug
|
||||
* fix: Use unicode to send escape character to shell instead of octal to work with strict mode javascript
|
||||
|
||||
0.7.1 / 2013-02-05
|
||||
==================
|
||||
|
||||
* add repository URL to package.json
|
||||
* add DEBUG_COLORED to force colored output
|
||||
* add browserify support
|
||||
* fix component. Closes #24
|
||||
|
||||
0.7.0 / 2012-05-04
|
||||
==================
|
||||
|
||||
* Added .component to package.json
|
||||
* Added debug.component.js build
|
||||
|
||||
0.6.0 / 2012-03-16
|
||||
==================
|
||||
|
||||
* Added support for "-" prefix in DEBUG [Vinay Pulim]
|
||||
* Added `.enabled` flag to the node version [TooTallNate]
|
||||
|
||||
0.5.0 / 2012-02-02
|
||||
==================
|
||||
|
||||
* Added: humanize diffs. Closes #8
|
||||
* Added `debug.disable()` to the CS variant
|
||||
* Removed padding. Closes #10
|
||||
* Fixed: persist client-side variant again. Closes #9
|
||||
|
||||
0.4.0 / 2012-02-01
|
||||
==================
|
||||
|
||||
* Added browser variant support for older browsers [TooTallNate]
|
||||
* Added `debug.enable('project:*')` to browser variant [TooTallNate]
|
||||
* Added padding to diff (moved it to the right)
|
||||
|
||||
0.3.0 / 2012-01-26
|
||||
==================
|
||||
|
||||
* Added millisecond diff when isatty, otherwise UTC string
|
||||
|
||||
0.2.0 / 2012-01-22
|
||||
==================
|
||||
|
||||
* Added wildcard support
|
||||
|
||||
0.1.0 / 2011-12-02
|
||||
==================
|
||||
|
||||
* Added: remove colors unless stderr isatty [TooTallNate]
|
||||
|
||||
0.0.1 / 2010-01-03
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
19
node_modules/telegraf/node_modules/debug/LICENSE
generated
vendored
Normal file
19
node_modules/telegraf/node_modules/debug/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the 'Software'), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
455
node_modules/telegraf/node_modules/debug/README.md
generated
vendored
Normal file
455
node_modules/telegraf/node_modules/debug/README.md
generated
vendored
Normal file
@@ -0,0 +1,455 @@
|
||||
# debug
|
||||
[](https://travis-ci.org/visionmedia/debug) [](https://coveralls.io/github/visionmedia/debug?branch=master) [](https://visionmedia-community-slackin.now.sh/) [](#backers)
|
||||
[](#sponsors)
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
|
||||
A tiny JavaScript debugging utility modelled after Node.js core's debugging
|
||||
technique. Works in Node.js and web browsers.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install debug
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
`debug` exposes a function; simply pass this function the name of your module, and it will return a decorated version of `console.error` for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.
|
||||
|
||||
Example [_app.js_](./examples/node/app.js):
|
||||
|
||||
```js
|
||||
var debug = require('debug')('http')
|
||||
, http = require('http')
|
||||
, name = 'My App';
|
||||
|
||||
// fake app
|
||||
|
||||
debug('booting %o', name);
|
||||
|
||||
http.createServer(function(req, res){
|
||||
debug(req.method + ' ' + req.url);
|
||||
res.end('hello\n');
|
||||
}).listen(3000, function(){
|
||||
debug('listening');
|
||||
});
|
||||
|
||||
// fake worker of some kind
|
||||
|
||||
require('./worker');
|
||||
```
|
||||
|
||||
Example [_worker.js_](./examples/node/worker.js):
|
||||
|
||||
```js
|
||||
var a = require('debug')('worker:a')
|
||||
, b = require('debug')('worker:b');
|
||||
|
||||
function work() {
|
||||
a('doing lots of uninteresting work');
|
||||
setTimeout(work, Math.random() * 1000);
|
||||
}
|
||||
|
||||
work();
|
||||
|
||||
function workb() {
|
||||
b('doing some work');
|
||||
setTimeout(workb, Math.random() * 2000);
|
||||
}
|
||||
|
||||
workb();
|
||||
```
|
||||
|
||||
The `DEBUG` environment variable is then used to enable these based on space or
|
||||
comma-delimited names.
|
||||
|
||||
Here are some examples:
|
||||
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 04 pm" src="https://user-images.githubusercontent.com/71256/29091703-a6302cdc-7c38-11e7-8304-7c0b3bc600cd.png">
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 38 pm" src="https://user-images.githubusercontent.com/71256/29091700-a62a6888-7c38-11e7-800b-db911291ca2b.png">
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 25 pm" src="https://user-images.githubusercontent.com/71256/29091701-a62ea114-7c38-11e7-826a-2692bedca740.png">
|
||||
|
||||
#### Windows command prompt notes
|
||||
|
||||
##### CMD
|
||||
|
||||
On Windows the environment variable is set using the `set` command.
|
||||
|
||||
```cmd
|
||||
set DEBUG=*,-not_this
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
set DEBUG=* & node app.js
|
||||
```
|
||||
|
||||
##### PowerShell (VS Code default)
|
||||
|
||||
PowerShell uses different syntax to set environment variables.
|
||||
|
||||
```cmd
|
||||
$env:DEBUG = "*,-not_this"
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
$env:DEBUG='app';node app.js
|
||||
```
|
||||
|
||||
Then, run the program to be debugged as usual.
|
||||
|
||||
npm script example:
|
||||
```js
|
||||
"windowsDebug": "@powershell -Command $env:DEBUG='*';node app.js",
|
||||
```
|
||||
|
||||
## Namespace Colors
|
||||
|
||||
Every debug instance has a color generated for it based on its namespace name.
|
||||
This helps when visually parsing the debug output to identify which debug instance
|
||||
a debug line belongs to.
|
||||
|
||||
#### Node.js
|
||||
|
||||
In Node.js, colors are enabled when stderr is a TTY. You also _should_ install
|
||||
the [`supports-color`](https://npmjs.org/supports-color) module alongside debug,
|
||||
otherwise debug will only use a small handful of basic colors.
|
||||
|
||||
<img width="521" src="https://user-images.githubusercontent.com/71256/29092181-47f6a9e6-7c3a-11e7-9a14-1928d8a711cd.png">
|
||||
|
||||
#### Web Browser
|
||||
|
||||
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
|
||||
option. These are WebKit web inspectors, Firefox ([since version
|
||||
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
|
||||
and the Firebug plugin for Firefox (any version).
|
||||
|
||||
<img width="524" src="https://user-images.githubusercontent.com/71256/29092033-b65f9f2e-7c39-11e7-8e32-f6f0d8e865c1.png">
|
||||
|
||||
|
||||
## Millisecond diff
|
||||
|
||||
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
|
||||
When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below:
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091956-6bd78372-7c39-11e7-8c55-c948396d6edd.png">
|
||||
|
||||
|
||||
## Conventions
|
||||
|
||||
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output.
|
||||
|
||||
## Wildcards
|
||||
|
||||
The `*` character may be used as a wildcard. Suppose for example your library has
|
||||
debuggers named "connect:bodyParser", "connect:compress", "connect:session",
|
||||
instead of listing all three with
|
||||
`DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do
|
||||
`DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
|
||||
|
||||
You can also exclude specific debuggers by prefixing them with a "-" character.
|
||||
For example, `DEBUG=*,-connect:*` would include all debuggers except those
|
||||
starting with "connect:".
|
||||
|
||||
## Environment Variables
|
||||
|
||||
When running through Node.js, you can set a few environment variables that will
|
||||
change the behavior of the debug logging:
|
||||
|
||||
| Name | Purpose |
|
||||
|-----------|-------------------------------------------------|
|
||||
| `DEBUG` | Enables/disables specific debugging namespaces. |
|
||||
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
|
||||
| `DEBUG_COLORS`| Whether or not to use colors in the debug output. |
|
||||
| `DEBUG_DEPTH` | Object inspection depth. |
|
||||
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
|
||||
|
||||
|
||||
__Note:__ The environment variables beginning with `DEBUG_` end up being
|
||||
converted into an Options object that gets used with `%o`/`%O` formatters.
|
||||
See the Node.js documentation for
|
||||
[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options)
|
||||
for the complete list.
|
||||
|
||||
## Formatters
|
||||
|
||||
Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting.
|
||||
Below are the officially supported formatters:
|
||||
|
||||
| Formatter | Representation |
|
||||
|-----------|----------------|
|
||||
| `%O` | Pretty-print an Object on multiple lines. |
|
||||
| `%o` | Pretty-print an Object all on a single line. |
|
||||
| `%s` | String. |
|
||||
| `%d` | Number (both integer and float). |
|
||||
| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
|
||||
| `%%` | Single percent sign ('%'). This does not consume an argument. |
|
||||
|
||||
|
||||
### Custom formatters
|
||||
|
||||
You can add custom formatters by extending the `debug.formatters` object.
|
||||
For example, if you wanted to add support for rendering a Buffer as hex with
|
||||
`%h`, you could do something like:
|
||||
|
||||
```js
|
||||
const createDebug = require('debug')
|
||||
createDebug.formatters.h = (v) => {
|
||||
return v.toString('hex')
|
||||
}
|
||||
|
||||
// …elsewhere
|
||||
const debug = createDebug('foo')
|
||||
debug('this is hex: %h', new Buffer('hello world'))
|
||||
// foo this is hex: 68656c6c6f20776f726c6421 +0ms
|
||||
```
|
||||
|
||||
|
||||
## Browser Support
|
||||
|
||||
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
|
||||
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
|
||||
if you don't want to build it yourself.
|
||||
|
||||
Debug's enable state is currently persisted by `localStorage`.
|
||||
Consider the situation shown below where you have `worker:a` and `worker:b`,
|
||||
and wish to debug both. You can enable this using `localStorage.debug`:
|
||||
|
||||
```js
|
||||
localStorage.debug = 'worker:*'
|
||||
```
|
||||
|
||||
And then refresh the page.
|
||||
|
||||
```js
|
||||
a = debug('worker:a');
|
||||
b = debug('worker:b');
|
||||
|
||||
setInterval(function(){
|
||||
a('doing some work');
|
||||
}, 1000);
|
||||
|
||||
setInterval(function(){
|
||||
b('doing some work');
|
||||
}, 1200);
|
||||
```
|
||||
|
||||
|
||||
## Output streams
|
||||
|
||||
By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method:
|
||||
|
||||
Example [_stdout.js_](./examples/node/stdout.js):
|
||||
|
||||
```js
|
||||
var debug = require('debug');
|
||||
var error = debug('app:error');
|
||||
|
||||
// by default stderr is used
|
||||
error('goes to stderr!');
|
||||
|
||||
var log = debug('app:log');
|
||||
// set this namespace to log via console.log
|
||||
log.log = console.log.bind(console); // don't forget to bind to console!
|
||||
log('goes to stdout');
|
||||
error('still goes to stderr!');
|
||||
|
||||
// set all output to go via console.info
|
||||
// overrides all per-namespace log settings
|
||||
debug.log = console.info.bind(console);
|
||||
error('now goes to stdout via console.info');
|
||||
log('still goes to stdout, but via console.info now');
|
||||
```
|
||||
|
||||
## Extend
|
||||
You can simply extend debugger
|
||||
```js
|
||||
const log = require('debug')('auth');
|
||||
|
||||
//creates new debug instance with extended namespace
|
||||
const logSign = log.extend('sign');
|
||||
const logLogin = log.extend('login');
|
||||
|
||||
log('hello'); // auth hello
|
||||
logSign('hello'); //auth:sign hello
|
||||
logLogin('hello'); //auth:login hello
|
||||
```
|
||||
|
||||
## Set dynamically
|
||||
|
||||
You can also enable debug dynamically by calling the `enable()` method :
|
||||
|
||||
```js
|
||||
let debug = require('debug');
|
||||
|
||||
console.log(1, debug.enabled('test'));
|
||||
|
||||
debug.enable('test');
|
||||
console.log(2, debug.enabled('test'));
|
||||
|
||||
debug.disable();
|
||||
console.log(3, debug.enabled('test'));
|
||||
|
||||
```
|
||||
|
||||
print :
|
||||
```
|
||||
1 false
|
||||
2 true
|
||||
3 false
|
||||
```
|
||||
|
||||
Usage :
|
||||
`enable(namespaces)`
|
||||
`namespaces` can include modes separated by a colon and wildcards.
|
||||
|
||||
Note that calling `enable()` completely overrides previously set DEBUG variable :
|
||||
|
||||
```
|
||||
$ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))'
|
||||
=> false
|
||||
```
|
||||
|
||||
`disable()`
|
||||
|
||||
Will disable all namespaces. The functions returns the namespaces currently
|
||||
enabled (and skipped). This can be useful if you want to disable debugging
|
||||
temporarily without knowing what was enabled to begin with.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
let debug = require('debug');
|
||||
debug.enable('foo:*,-foo:bar');
|
||||
let namespaces = debug.disable();
|
||||
debug.enable(namespaces);
|
||||
```
|
||||
|
||||
Note: There is no guarantee that the string will be identical to the initial
|
||||
enable string, but semantically they will be identical.
|
||||
|
||||
## Checking whether a debug target is enabled
|
||||
|
||||
After you've created a debug instance, you can determine whether or not it is
|
||||
enabled by checking the `enabled` property:
|
||||
|
||||
```javascript
|
||||
const debug = require('debug')('http');
|
||||
|
||||
if (debug.enabled) {
|
||||
// do stuff...
|
||||
}
|
||||
```
|
||||
|
||||
You can also manually toggle this property to force the debug instance to be
|
||||
enabled or disabled.
|
||||
|
||||
|
||||
## Authors
|
||||
|
||||
- TJ Holowaychuk
|
||||
- Nathan Rajlich
|
||||
- Andrew Rhyne
|
||||
|
||||
## Backers
|
||||
|
||||
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/debug#backer)]
|
||||
|
||||
<a href="https://opencollective.com/debug/backer/0/website" target="_blank"><img src="https://opencollective.com/debug/backer/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/1/website" target="_blank"><img src="https://opencollective.com/debug/backer/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/2/website" target="_blank"><img src="https://opencollective.com/debug/backer/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/3/website" target="_blank"><img src="https://opencollective.com/debug/backer/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/4/website" target="_blank"><img src="https://opencollective.com/debug/backer/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/5/website" target="_blank"><img src="https://opencollective.com/debug/backer/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/6/website" target="_blank"><img src="https://opencollective.com/debug/backer/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/7/website" target="_blank"><img src="https://opencollective.com/debug/backer/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/8/website" target="_blank"><img src="https://opencollective.com/debug/backer/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/9/website" target="_blank"><img src="https://opencollective.com/debug/backer/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/10/website" target="_blank"><img src="https://opencollective.com/debug/backer/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/11/website" target="_blank"><img src="https://opencollective.com/debug/backer/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/12/website" target="_blank"><img src="https://opencollective.com/debug/backer/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/13/website" target="_blank"><img src="https://opencollective.com/debug/backer/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/14/website" target="_blank"><img src="https://opencollective.com/debug/backer/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/15/website" target="_blank"><img src="https://opencollective.com/debug/backer/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/16/website" target="_blank"><img src="https://opencollective.com/debug/backer/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/17/website" target="_blank"><img src="https://opencollective.com/debug/backer/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/18/website" target="_blank"><img src="https://opencollective.com/debug/backer/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/19/website" target="_blank"><img src="https://opencollective.com/debug/backer/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/20/website" target="_blank"><img src="https://opencollective.com/debug/backer/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/21/website" target="_blank"><img src="https://opencollective.com/debug/backer/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/22/website" target="_blank"><img src="https://opencollective.com/debug/backer/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/23/website" target="_blank"><img src="https://opencollective.com/debug/backer/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/24/website" target="_blank"><img src="https://opencollective.com/debug/backer/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/25/website" target="_blank"><img src="https://opencollective.com/debug/backer/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/26/website" target="_blank"><img src="https://opencollective.com/debug/backer/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/27/website" target="_blank"><img src="https://opencollective.com/debug/backer/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/28/website" target="_blank"><img src="https://opencollective.com/debug/backer/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/29/website" target="_blank"><img src="https://opencollective.com/debug/backer/29/avatar.svg"></a>
|
||||
|
||||
|
||||
## Sponsors
|
||||
|
||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/debug#sponsor)]
|
||||
|
||||
<a href="https://opencollective.com/debug/sponsor/0/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/1/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/2/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/3/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/4/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/5/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/6/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/7/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/8/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/9/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/10/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/11/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/12/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/13/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/14/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/15/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/16/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/17/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/18/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/19/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/20/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/21/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/22/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/23/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/24/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/25/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/26/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/27/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/28/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/29/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/29/avatar.svg"></a>
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
912
node_modules/telegraf/node_modules/debug/dist/debug.js
generated
vendored
Normal file
912
node_modules/telegraf/node_modules/debug/dist/debug.js
generated
vendored
Normal file
@@ -0,0 +1,912 @@
|
||||
"use strict";
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
(function (f) {
|
||||
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined") {
|
||||
module.exports = f();
|
||||
} else if (typeof define === "function" && define.amd) {
|
||||
define([], f);
|
||||
} else {
|
||||
var g;
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
g = window;
|
||||
} else if (typeof global !== "undefined") {
|
||||
g = global;
|
||||
} else if (typeof self !== "undefined") {
|
||||
g = self;
|
||||
} else {
|
||||
g = this;
|
||||
}
|
||||
|
||||
g.debug = f();
|
||||
}
|
||||
})(function () {
|
||||
var define, module, exports;
|
||||
return function () {
|
||||
function r(e, n, t) {
|
||||
function o(i, f) {
|
||||
if (!n[i]) {
|
||||
if (!e[i]) {
|
||||
var c = "function" == typeof require && require;
|
||||
if (!f && c) return c(i, !0);
|
||||
if (u) return u(i, !0);
|
||||
var a = new Error("Cannot find module '" + i + "'");
|
||||
throw a.code = "MODULE_NOT_FOUND", a;
|
||||
}
|
||||
|
||||
var p = n[i] = {
|
||||
exports: {}
|
||||
};
|
||||
e[i][0].call(p.exports, function (r) {
|
||||
var n = e[i][1][r];
|
||||
return o(n || r);
|
||||
}, p, p.exports, r, e, n, t);
|
||||
}
|
||||
|
||||
return n[i].exports;
|
||||
}
|
||||
|
||||
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
|
||||
o(t[i]);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
return r;
|
||||
}()({
|
||||
1: [function (require, module, exports) {
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function (val, options) {
|
||||
options = options || {};
|
||||
|
||||
var type = _typeof(val);
|
||||
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isNaN(val) === false) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
|
||||
throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
|
||||
};
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
||||
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
|
||||
return ms + 'ms';
|
||||
}
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
|
||||
return ms + ' ms';
|
||||
}
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
||||
}, {}],
|
||||
2: [function (require, module, exports) {
|
||||
// shim for using process in browser
|
||||
var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
|
||||
// don't break things. But we need to wrap it in a try catch in case it is
|
||||
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
||||
// function because try/catches deoptimize in certain engines.
|
||||
|
||||
var cachedSetTimeout;
|
||||
var cachedClearTimeout;
|
||||
|
||||
function defaultSetTimout() {
|
||||
throw new Error('setTimeout has not been defined');
|
||||
}
|
||||
|
||||
function defaultClearTimeout() {
|
||||
throw new Error('clearTimeout has not been defined');
|
||||
}
|
||||
|
||||
(function () {
|
||||
try {
|
||||
if (typeof setTimeout === 'function') {
|
||||
cachedSetTimeout = setTimeout;
|
||||
} else {
|
||||
cachedSetTimeout = defaultSetTimout;
|
||||
}
|
||||
} catch (e) {
|
||||
cachedSetTimeout = defaultSetTimout;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof clearTimeout === 'function') {
|
||||
cachedClearTimeout = clearTimeout;
|
||||
} else {
|
||||
cachedClearTimeout = defaultClearTimeout;
|
||||
}
|
||||
} catch (e) {
|
||||
cachedClearTimeout = defaultClearTimeout;
|
||||
}
|
||||
})();
|
||||
|
||||
function runTimeout(fun) {
|
||||
if (cachedSetTimeout === setTimeout) {
|
||||
//normal enviroments in sane situations
|
||||
return setTimeout(fun, 0);
|
||||
} // if setTimeout wasn't available but was latter defined
|
||||
|
||||
|
||||
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
||||
cachedSetTimeout = setTimeout;
|
||||
return setTimeout(fun, 0);
|
||||
}
|
||||
|
||||
try {
|
||||
// when when somebody has screwed with setTimeout but no I.E. maddness
|
||||
return cachedSetTimeout(fun, 0);
|
||||
} catch (e) {
|
||||
try {
|
||||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
||||
return cachedSetTimeout.call(null, fun, 0);
|
||||
} catch (e) {
|
||||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
||||
return cachedSetTimeout.call(this, fun, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function runClearTimeout(marker) {
|
||||
if (cachedClearTimeout === clearTimeout) {
|
||||
//normal enviroments in sane situations
|
||||
return clearTimeout(marker);
|
||||
} // if clearTimeout wasn't available but was latter defined
|
||||
|
||||
|
||||
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
||||
cachedClearTimeout = clearTimeout;
|
||||
return clearTimeout(marker);
|
||||
}
|
||||
|
||||
try {
|
||||
// when when somebody has screwed with setTimeout but no I.E. maddness
|
||||
return cachedClearTimeout(marker);
|
||||
} catch (e) {
|
||||
try {
|
||||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
||||
return cachedClearTimeout.call(null, marker);
|
||||
} catch (e) {
|
||||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
||||
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
||||
return cachedClearTimeout.call(this, marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var queue = [];
|
||||
var draining = false;
|
||||
var currentQueue;
|
||||
var queueIndex = -1;
|
||||
|
||||
function cleanUpNextTick() {
|
||||
if (!draining || !currentQueue) {
|
||||
return;
|
||||
}
|
||||
|
||||
draining = false;
|
||||
|
||||
if (currentQueue.length) {
|
||||
queue = currentQueue.concat(queue);
|
||||
} else {
|
||||
queueIndex = -1;
|
||||
}
|
||||
|
||||
if (queue.length) {
|
||||
drainQueue();
|
||||
}
|
||||
}
|
||||
|
||||
function drainQueue() {
|
||||
if (draining) {
|
||||
return;
|
||||
}
|
||||
|
||||
var timeout = runTimeout(cleanUpNextTick);
|
||||
draining = true;
|
||||
var len = queue.length;
|
||||
|
||||
while (len) {
|
||||
currentQueue = queue;
|
||||
queue = [];
|
||||
|
||||
while (++queueIndex < len) {
|
||||
if (currentQueue) {
|
||||
currentQueue[queueIndex].run();
|
||||
}
|
||||
}
|
||||
|
||||
queueIndex = -1;
|
||||
len = queue.length;
|
||||
}
|
||||
|
||||
currentQueue = null;
|
||||
draining = false;
|
||||
runClearTimeout(timeout);
|
||||
}
|
||||
|
||||
process.nextTick = function (fun) {
|
||||
var args = new Array(arguments.length - 1);
|
||||
|
||||
if (arguments.length > 1) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
args[i - 1] = arguments[i];
|
||||
}
|
||||
}
|
||||
|
||||
queue.push(new Item(fun, args));
|
||||
|
||||
if (queue.length === 1 && !draining) {
|
||||
runTimeout(drainQueue);
|
||||
}
|
||||
}; // v8 likes predictible objects
|
||||
|
||||
|
||||
function Item(fun, array) {
|
||||
this.fun = fun;
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
Item.prototype.run = function () {
|
||||
this.fun.apply(null, this.array);
|
||||
};
|
||||
|
||||
process.title = 'browser';
|
||||
process.browser = true;
|
||||
process.env = {};
|
||||
process.argv = [];
|
||||
process.version = ''; // empty string to avoid regexp issues
|
||||
|
||||
process.versions = {};
|
||||
|
||||
function noop() {}
|
||||
|
||||
process.on = noop;
|
||||
process.addListener = noop;
|
||||
process.once = noop;
|
||||
process.off = noop;
|
||||
process.removeListener = noop;
|
||||
process.removeAllListeners = noop;
|
||||
process.emit = noop;
|
||||
process.prependListener = noop;
|
||||
process.prependOnceListener = noop;
|
||||
|
||||
process.listeners = function (name) {
|
||||
return [];
|
||||
};
|
||||
|
||||
process.binding = function (name) {
|
||||
throw new Error('process.binding is not supported');
|
||||
};
|
||||
|
||||
process.cwd = function () {
|
||||
return '/';
|
||||
};
|
||||
|
||||
process.chdir = function (dir) {
|
||||
throw new Error('process.chdir is not supported');
|
||||
};
|
||||
|
||||
process.umask = function () {
|
||||
return 0;
|
||||
};
|
||||
}, {}],
|
||||
3: [function (require, module, exports) {
|
||||
/**
|
||||
* This is the common logic for both the Node.js and web browser
|
||||
* implementations of `debug()`.
|
||||
*/
|
||||
function setup(env) {
|
||||
createDebug.debug = createDebug;
|
||||
createDebug.default = createDebug;
|
||||
createDebug.coerce = coerce;
|
||||
createDebug.disable = disable;
|
||||
createDebug.enable = enable;
|
||||
createDebug.enabled = enabled;
|
||||
createDebug.humanize = require('ms');
|
||||
Object.keys(env).forEach(function (key) {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
/**
|
||||
* Active `debug` instances.
|
||||
*/
|
||||
|
||||
createDebug.instances = [];
|
||||
/**
|
||||
* The currently active debug mode names, and names to skip.
|
||||
*/
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
/**
|
||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
||||
*
|
||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
||||
*/
|
||||
|
||||
createDebug.formatters = {};
|
||||
/**
|
||||
* Selects a color for a debug namespace
|
||||
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
||||
* @return {Number|String} An ANSI color code for the given namespace
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function selectColor(namespace) {
|
||||
var hash = 0;
|
||||
|
||||
for (var i = 0; i < namespace.length; i++) {
|
||||
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
|
||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
||||
}
|
||||
|
||||
createDebug.selectColor = selectColor;
|
||||
/**
|
||||
* Create a debugger with the given `namespace`.
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function createDebug(namespace) {
|
||||
var prevTime;
|
||||
|
||||
function debug() {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
// Disabled?
|
||||
if (!debug.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = debug; // Set `diff` timestamp
|
||||
|
||||
var curr = Number(new Date());
|
||||
var ms = curr - (prevTime || curr);
|
||||
self.diff = ms;
|
||||
self.prev = prevTime;
|
||||
self.curr = curr;
|
||||
prevTime = curr;
|
||||
args[0] = createDebug.coerce(args[0]);
|
||||
|
||||
if (typeof args[0] !== 'string') {
|
||||
// Anything else let's inspect with %O
|
||||
args.unshift('%O');
|
||||
} // Apply any `formatters` transformations
|
||||
|
||||
|
||||
var index = 0;
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return match;
|
||||
}
|
||||
|
||||
index++;
|
||||
var formatter = createDebug.formatters[format];
|
||||
|
||||
if (typeof formatter === 'function') {
|
||||
var val = args[index];
|
||||
match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format`
|
||||
|
||||
args.splice(index, 1);
|
||||
index--;
|
||||
}
|
||||
|
||||
return match;
|
||||
}); // Apply env-specific formatting (colors, etc.)
|
||||
|
||||
createDebug.formatArgs.call(self, args);
|
||||
var logFn = self.log || createDebug.log;
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.enabled = createDebug.enabled(namespace);
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = selectColor(namespace);
|
||||
debug.destroy = destroy;
|
||||
debug.extend = extend; // Debug.formatArgs = formatArgs;
|
||||
// debug.rawLog = rawLog;
|
||||
// env-specific initialization logic for debug instances
|
||||
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
createDebug.instances.push(debug);
|
||||
return debug;
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
var index = createDebug.instances.indexOf(this);
|
||||
|
||||
if (index !== -1) {
|
||||
createDebug.instances.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
newDebug.log = this.log;
|
||||
return newDebug;
|
||||
}
|
||||
/**
|
||||
* Enables a debug mode by namespaces. This can include modes
|
||||
* separated by a colon and wildcards.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function enable(namespaces) {
|
||||
createDebug.save(namespaces);
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
var i;
|
||||
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
||||
var len = split.length;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!split[i]) {
|
||||
// ignore empty strings
|
||||
continue;
|
||||
}
|
||||
|
||||
namespaces = split[i].replace(/\*/g, '.*?');
|
||||
|
||||
if (namespaces[0] === '-') {
|
||||
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||||
} else {
|
||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < createDebug.instances.length; i++) {
|
||||
var instance = createDebug.instances[i];
|
||||
instance.enabled = createDebug.enabled(instance.namespace);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @return {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function disable() {
|
||||
var namespaces = [].concat(_toConsumableArray(createDebug.names.map(toNamespace)), _toConsumableArray(createDebug.skips.map(toNamespace).map(function (namespace) {
|
||||
return '-' + namespace;
|
||||
}))).join(',');
|
||||
createDebug.enable('');
|
||||
return namespaces;
|
||||
}
|
||||
/**
|
||||
* Returns true if the given mode name is enabled, false otherwise.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function enabled(name) {
|
||||
if (name[name.length - 1] === '*') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var i;
|
||||
var len;
|
||||
|
||||
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
||||
if (createDebug.skips[i].test(name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
||||
if (createDebug.names[i].test(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Convert regexp to namespace
|
||||
*
|
||||
* @param {RegExp} regxep
|
||||
* @return {String} namespace
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function toNamespace(regexp) {
|
||||
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
|
||||
}
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) {
|
||||
return val.stack || val.message;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
return createDebug;
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
}, {
|
||||
"ms": 1
|
||||
}],
|
||||
4: [function (require, module, exports) {
|
||||
(function (process) {
|
||||
/* eslint-env browser */
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
|
||||
/**
|
||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||||
* and the Firebug extension (any Firefox version) are known
|
||||
* to support "%c" CSS customizations.
|
||||
*
|
||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
|
||||
function useColors() {
|
||||
// NB: In an Electron preload script, document will be defined but not fully
|
||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
||||
// explicitly
|
||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
||||
return true;
|
||||
} // Internet Explorer and Edge do not support colors.
|
||||
|
||||
|
||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
||||
return false;
|
||||
} // Is webkit? http://stackoverflow.com/a/16459606/376773
|
||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
||||
|
||||
|
||||
return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
||||
typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||||
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
||||
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
||||
}
|
||||
/**
|
||||
* Colorize log arguments if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function formatArgs(args) {
|
||||
args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
|
||||
|
||||
if (!this.useColors) {
|
||||
return;
|
||||
}
|
||||
|
||||
var c = 'color: ' + this.color;
|
||||
args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other
|
||||
// arguments passed either before or after the %c, so we need to
|
||||
// figure out the correct index to insert the CSS into
|
||||
|
||||
var index = 0;
|
||||
var lastC = 0;
|
||||
args[0].replace(/%[a-zA-Z%]/g, function (match) {
|
||||
if (match === '%%') {
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
|
||||
if (match === '%c') {
|
||||
// We only are interested in the *last* %c
|
||||
// (the user may have provided their own)
|
||||
lastC = index;
|
||||
}
|
||||
});
|
||||
args.splice(lastC, 0, c);
|
||||
}
|
||||
/**
|
||||
* Invokes `console.log()` when available.
|
||||
* No-op when `console.log` is not a "function".
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function log() {
|
||||
var _console;
|
||||
|
||||
// This hackery is required for IE8/9, where
|
||||
// the `console.log` function doesn't have 'apply'
|
||||
return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
|
||||
}
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function save(namespaces) {
|
||||
try {
|
||||
if (namespaces) {
|
||||
exports.storage.setItem('debug', namespaces);
|
||||
} else {
|
||||
exports.storage.removeItem('debug');
|
||||
}
|
||||
} catch (error) {// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function load() {
|
||||
var r;
|
||||
|
||||
try {
|
||||
r = exports.storage.getItem('debug');
|
||||
} catch (error) {} // Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
||||
|
||||
|
||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
||||
r = process.env.DEBUG;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
/**
|
||||
* Localstorage attempts to return the localstorage.
|
||||
*
|
||||
* This is necessary because safari throws
|
||||
* when a user disables cookies/localstorage
|
||||
* and you attempt to access it.
|
||||
*
|
||||
* @return {LocalStorage}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function localstorage() {
|
||||
try {
|
||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
||||
// The Browser also has localStorage in the global context.
|
||||
return localStorage;
|
||||
} catch (error) {// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
var formatters = module.exports.formatters;
|
||||
/**
|
||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||||
*/
|
||||
|
||||
formatters.j = function (v) {
|
||||
try {
|
||||
return JSON.stringify(v);
|
||||
} catch (error) {
|
||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
||||
}
|
||||
};
|
||||
}).call(this, require('_process'));
|
||||
}, {
|
||||
"./common": 3,
|
||||
"_process": 2
|
||||
}]
|
||||
}, {}, [4])(4);
|
||||
});
|
||||
102
node_modules/telegraf/node_modules/debug/package.json
generated
vendored
Normal file
102
node_modules/telegraf/node_modules/debug/package.json
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"_from": "debug@^4.0.1",
|
||||
"_id": "debug@4.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"_location": "/telegraf/debug",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "debug@^4.0.1",
|
||||
"name": "debug",
|
||||
"escapedName": "debug",
|
||||
"rawSpec": "^4.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/telegraf"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"_shasum": "3b72260255109c6b589cee050f1d516139664791",
|
||||
"_spec": "debug@^4.0.1",
|
||||
"_where": "/home/pablinux/Projects/Node/app_sigma/node_modules/telegraf",
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
"browser": "./src/browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/visionmedia/debug/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Nathan Rajlich",
|
||||
"email": "nathan@tootallnate.net",
|
||||
"url": "http://n8.io"
|
||||
},
|
||||
{
|
||||
"name": "Andrew Rhyne",
|
||||
"email": "rhyneandrew@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"ms": "^2.1.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "small debugging utility",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"browserify": "14.4.0",
|
||||
"chai": "^3.5.0",
|
||||
"concurrently": "^3.1.0",
|
||||
"coveralls": "^3.0.2",
|
||||
"istanbul": "^0.4.5",
|
||||
"karma": "^3.0.0",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-phantomjs-launcher": "^1.0.2",
|
||||
"mocha": "^5.2.0",
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"rimraf": "^2.5.4",
|
||||
"xo": "^0.23.0"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"dist/debug.js",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"homepage": "https://github.com/visionmedia/debug#readme",
|
||||
"keywords": [
|
||||
"debug",
|
||||
"log",
|
||||
"debugger"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./src/index.js",
|
||||
"name": "debug",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/visionmedia/debug.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build:debug && npm run build:test",
|
||||
"build:debug": "babel -o dist/debug.js dist/debug.es6.js > dist/debug.js",
|
||||
"build:test": "babel -d dist test.js",
|
||||
"clean": "rimraf dist coverage",
|
||||
"lint": "xo",
|
||||
"prebuild:debug": "mkdir -p dist && browserify --standalone debug -o dist/debug.es6.js .",
|
||||
"pretest:browser": "npm run build",
|
||||
"test": "npm run test:node && npm run test:browser",
|
||||
"test:browser": "karma start --single-run",
|
||||
"test:coverage": "cat ./coverage/lcov.info | coveralls",
|
||||
"test:node": "istanbul cover _mocha -- test.js"
|
||||
},
|
||||
"unpkg": "./dist/debug.js",
|
||||
"version": "4.1.1"
|
||||
}
|
||||
264
node_modules/telegraf/node_modules/debug/src/browser.js
generated
vendored
Normal file
264
node_modules/telegraf/node_modules/debug/src/browser.js
generated
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
/* eslint-env browser */
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [
|
||||
'#0000CC',
|
||||
'#0000FF',
|
||||
'#0033CC',
|
||||
'#0033FF',
|
||||
'#0066CC',
|
||||
'#0066FF',
|
||||
'#0099CC',
|
||||
'#0099FF',
|
||||
'#00CC00',
|
||||
'#00CC33',
|
||||
'#00CC66',
|
||||
'#00CC99',
|
||||
'#00CCCC',
|
||||
'#00CCFF',
|
||||
'#3300CC',
|
||||
'#3300FF',
|
||||
'#3333CC',
|
||||
'#3333FF',
|
||||
'#3366CC',
|
||||
'#3366FF',
|
||||
'#3399CC',
|
||||
'#3399FF',
|
||||
'#33CC00',
|
||||
'#33CC33',
|
||||
'#33CC66',
|
||||
'#33CC99',
|
||||
'#33CCCC',
|
||||
'#33CCFF',
|
||||
'#6600CC',
|
||||
'#6600FF',
|
||||
'#6633CC',
|
||||
'#6633FF',
|
||||
'#66CC00',
|
||||
'#66CC33',
|
||||
'#9900CC',
|
||||
'#9900FF',
|
||||
'#9933CC',
|
||||
'#9933FF',
|
||||
'#99CC00',
|
||||
'#99CC33',
|
||||
'#CC0000',
|
||||
'#CC0033',
|
||||
'#CC0066',
|
||||
'#CC0099',
|
||||
'#CC00CC',
|
||||
'#CC00FF',
|
||||
'#CC3300',
|
||||
'#CC3333',
|
||||
'#CC3366',
|
||||
'#CC3399',
|
||||
'#CC33CC',
|
||||
'#CC33FF',
|
||||
'#CC6600',
|
||||
'#CC6633',
|
||||
'#CC9900',
|
||||
'#CC9933',
|
||||
'#CCCC00',
|
||||
'#CCCC33',
|
||||
'#FF0000',
|
||||
'#FF0033',
|
||||
'#FF0066',
|
||||
'#FF0099',
|
||||
'#FF00CC',
|
||||
'#FF00FF',
|
||||
'#FF3300',
|
||||
'#FF3333',
|
||||
'#FF3366',
|
||||
'#FF3399',
|
||||
'#FF33CC',
|
||||
'#FF33FF',
|
||||
'#FF6600',
|
||||
'#FF6633',
|
||||
'#FF9900',
|
||||
'#FF9933',
|
||||
'#FFCC00',
|
||||
'#FFCC33'
|
||||
];
|
||||
|
||||
/**
|
||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||||
* and the Firebug extension (any Firefox version) are known
|
||||
* to support "%c" CSS customizations.
|
||||
*
|
||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
function useColors() {
|
||||
// NB: In an Electron preload script, document will be defined but not fully
|
||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
||||
// explicitly
|
||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Internet Explorer and Edge do not support colors.
|
||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
||||
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
||||
// Is firebug? http://stackoverflow.com/a/398120/376773
|
||||
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
||||
// Is firefox >= v31?
|
||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
||||
// Double check webkit in userAgent just in case we are in a worker
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
||||
}
|
||||
|
||||
/**
|
||||
* Colorize log arguments if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs(args) {
|
||||
args[0] = (this.useColors ? '%c' : '') +
|
||||
this.namespace +
|
||||
(this.useColors ? ' %c' : ' ') +
|
||||
args[0] +
|
||||
(this.useColors ? '%c ' : ' ') +
|
||||
'+' + module.exports.humanize(this.diff);
|
||||
|
||||
if (!this.useColors) {
|
||||
return;
|
||||
}
|
||||
|
||||
const c = 'color: ' + this.color;
|
||||
args.splice(1, 0, c, 'color: inherit');
|
||||
|
||||
// The final "%c" is somewhat tricky, because there could be other
|
||||
// arguments passed either before or after the %c, so we need to
|
||||
// figure out the correct index to insert the CSS into
|
||||
let index = 0;
|
||||
let lastC = 0;
|
||||
args[0].replace(/%[a-zA-Z%]/g, match => {
|
||||
if (match === '%%') {
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
if (match === '%c') {
|
||||
// We only are interested in the *last* %c
|
||||
// (the user may have provided their own)
|
||||
lastC = index;
|
||||
}
|
||||
});
|
||||
|
||||
args.splice(lastC, 0, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `console.log()` when available.
|
||||
* No-op when `console.log` is not a "function".
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function log(...args) {
|
||||
// This hackery is required for IE8/9, where
|
||||
// the `console.log` function doesn't have 'apply'
|
||||
return typeof console === 'object' &&
|
||||
console.log &&
|
||||
console.log(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
function save(namespaces) {
|
||||
try {
|
||||
if (namespaces) {
|
||||
exports.storage.setItem('debug', namespaces);
|
||||
} else {
|
||||
exports.storage.removeItem('debug');
|
||||
}
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
function load() {
|
||||
let r;
|
||||
try {
|
||||
r = exports.storage.getItem('debug');
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
|
||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
||||
r = process.env.DEBUG;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Localstorage attempts to return the localstorage.
|
||||
*
|
||||
* This is necessary because safari throws
|
||||
* when a user disables cookies/localstorage
|
||||
* and you attempt to access it.
|
||||
*
|
||||
* @return {LocalStorage}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function localstorage() {
|
||||
try {
|
||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
||||
// The Browser also has localStorage in the global context.
|
||||
return localStorage;
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
|
||||
const {formatters} = module.exports;
|
||||
|
||||
/**
|
||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||||
*/
|
||||
|
||||
formatters.j = function (v) {
|
||||
try {
|
||||
return JSON.stringify(v);
|
||||
} catch (error) {
|
||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
||||
}
|
||||
};
|
||||
266
node_modules/telegraf/node_modules/debug/src/common.js
generated
vendored
Normal file
266
node_modules/telegraf/node_modules/debug/src/common.js
generated
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
|
||||
/**
|
||||
* This is the common logic for both the Node.js and web browser
|
||||
* implementations of `debug()`.
|
||||
*/
|
||||
|
||||
function setup(env) {
|
||||
createDebug.debug = createDebug;
|
||||
createDebug.default = createDebug;
|
||||
createDebug.coerce = coerce;
|
||||
createDebug.disable = disable;
|
||||
createDebug.enable = enable;
|
||||
createDebug.enabled = enabled;
|
||||
createDebug.humanize = require('ms');
|
||||
|
||||
Object.keys(env).forEach(key => {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
|
||||
/**
|
||||
* Active `debug` instances.
|
||||
*/
|
||||
createDebug.instances = [];
|
||||
|
||||
/**
|
||||
* The currently active debug mode names, and names to skip.
|
||||
*/
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
|
||||
/**
|
||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
||||
*
|
||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
||||
*/
|
||||
createDebug.formatters = {};
|
||||
|
||||
/**
|
||||
* Selects a color for a debug namespace
|
||||
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
||||
* @return {Number|String} An ANSI color code for the given namespace
|
||||
* @api private
|
||||
*/
|
||||
function selectColor(namespace) {
|
||||
let hash = 0;
|
||||
|
||||
for (let i = 0; i < namespace.length; i++) {
|
||||
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
|
||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
||||
}
|
||||
createDebug.selectColor = selectColor;
|
||||
|
||||
/**
|
||||
* Create a debugger with the given `namespace`.
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
function createDebug(namespace) {
|
||||
let prevTime;
|
||||
|
||||
function debug(...args) {
|
||||
// Disabled?
|
||||
if (!debug.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const self = debug;
|
||||
|
||||
// Set `diff` timestamp
|
||||
const curr = Number(new Date());
|
||||
const ms = curr - (prevTime || curr);
|
||||
self.diff = ms;
|
||||
self.prev = prevTime;
|
||||
self.curr = curr;
|
||||
prevTime = curr;
|
||||
|
||||
args[0] = createDebug.coerce(args[0]);
|
||||
|
||||
if (typeof args[0] !== 'string') {
|
||||
// Anything else let's inspect with %O
|
||||
args.unshift('%O');
|
||||
}
|
||||
|
||||
// Apply any `formatters` transformations
|
||||
let index = 0;
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return match;
|
||||
}
|
||||
index++;
|
||||
const formatter = createDebug.formatters[format];
|
||||
if (typeof formatter === 'function') {
|
||||
const val = args[index];
|
||||
match = formatter.call(self, val);
|
||||
|
||||
// Now we need to remove `args[index]` since it's inlined in the `format`
|
||||
args.splice(index, 1);
|
||||
index--;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
|
||||
// Apply env-specific formatting (colors, etc.)
|
||||
createDebug.formatArgs.call(self, args);
|
||||
|
||||
const logFn = self.log || createDebug.log;
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.enabled = createDebug.enabled(namespace);
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = selectColor(namespace);
|
||||
debug.destroy = destroy;
|
||||
debug.extend = extend;
|
||||
// Debug.formatArgs = formatArgs;
|
||||
// debug.rawLog = rawLog;
|
||||
|
||||
// env-specific initialization logic for debug instances
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
createDebug.instances.push(debug);
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
const index = createDebug.instances.indexOf(this);
|
||||
if (index !== -1) {
|
||||
createDebug.instances.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
newDebug.log = this.log;
|
||||
return newDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a debug mode by namespaces. This can include modes
|
||||
* separated by a colon and wildcards.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
function enable(namespaces) {
|
||||
createDebug.save(namespaces);
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
|
||||
let i;
|
||||
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
||||
const len = split.length;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!split[i]) {
|
||||
// ignore empty strings
|
||||
continue;
|
||||
}
|
||||
|
||||
namespaces = split[i].replace(/\*/g, '.*?');
|
||||
|
||||
if (namespaces[0] === '-') {
|
||||
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||||
} else {
|
||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < createDebug.instances.length; i++) {
|
||||
const instance = createDebug.instances[i];
|
||||
instance.enabled = createDebug.enabled(instance.namespace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @return {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
function disable() {
|
||||
const namespaces = [
|
||||
...createDebug.names.map(toNamespace),
|
||||
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
||||
].join(',');
|
||||
createDebug.enable('');
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given mode name is enabled, false otherwise.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
function enabled(name) {
|
||||
if (name[name.length - 1] === '*') {
|
||||
return true;
|
||||
}
|
||||
|
||||
let i;
|
||||
let len;
|
||||
|
||||
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
||||
if (createDebug.skips[i].test(name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
||||
if (createDebug.names[i].test(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert regexp to namespace
|
||||
*
|
||||
* @param {RegExp} regxep
|
||||
* @return {String} namespace
|
||||
* @api private
|
||||
*/
|
||||
function toNamespace(regexp) {
|
||||
return regexp.toString()
|
||||
.substring(2, regexp.toString().length - 2)
|
||||
.replace(/\.\*\?$/, '*');
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) {
|
||||
return val.stack || val.message;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
|
||||
return createDebug;
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
10
node_modules/telegraf/node_modules/debug/src/index.js
generated
vendored
Normal file
10
node_modules/telegraf/node_modules/debug/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Detect Electron renderer / nwjs process, which is node, but we should
|
||||
* treat as a browser.
|
||||
*/
|
||||
|
||||
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
||||
module.exports = require('./browser.js');
|
||||
} else {
|
||||
module.exports = require('./node.js');
|
||||
}
|
||||
257
node_modules/telegraf/node_modules/debug/src/node.js
generated
vendored
Normal file
257
node_modules/telegraf/node_modules/debug/src/node.js
generated
vendored
Normal file
@@ -0,0 +1,257 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const tty = require('tty');
|
||||
const util = require('util');
|
||||
|
||||
/**
|
||||
* This is the Node.js implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.init = init;
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [6, 2, 3, 4, 5, 1];
|
||||
|
||||
try {
|
||||
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const supportsColor = require('supports-color');
|
||||
|
||||
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
||||
exports.colors = [
|
||||
20,
|
||||
21,
|
||||
26,
|
||||
27,
|
||||
32,
|
||||
33,
|
||||
38,
|
||||
39,
|
||||
40,
|
||||
41,
|
||||
42,
|
||||
43,
|
||||
44,
|
||||
45,
|
||||
56,
|
||||
57,
|
||||
62,
|
||||
63,
|
||||
68,
|
||||
69,
|
||||
74,
|
||||
75,
|
||||
76,
|
||||
77,
|
||||
78,
|
||||
79,
|
||||
80,
|
||||
81,
|
||||
92,
|
||||
93,
|
||||
98,
|
||||
99,
|
||||
112,
|
||||
113,
|
||||
128,
|
||||
129,
|
||||
134,
|
||||
135,
|
||||
148,
|
||||
149,
|
||||
160,
|
||||
161,
|
||||
162,
|
||||
163,
|
||||
164,
|
||||
165,
|
||||
166,
|
||||
167,
|
||||
168,
|
||||
169,
|
||||
170,
|
||||
171,
|
||||
172,
|
||||
173,
|
||||
178,
|
||||
179,
|
||||
184,
|
||||
185,
|
||||
196,
|
||||
197,
|
||||
198,
|
||||
199,
|
||||
200,
|
||||
201,
|
||||
202,
|
||||
203,
|
||||
204,
|
||||
205,
|
||||
206,
|
||||
207,
|
||||
208,
|
||||
209,
|
||||
214,
|
||||
215,
|
||||
220,
|
||||
221
|
||||
];
|
||||
}
|
||||
} catch (error) {
|
||||
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
||||
}
|
||||
|
||||
/**
|
||||
* Build up the default `inspectOpts` object from the environment variables.
|
||||
*
|
||||
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
||||
*/
|
||||
|
||||
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
||||
return /^debug_/i.test(key);
|
||||
}).reduce((obj, key) => {
|
||||
// Camel-case
|
||||
const prop = key
|
||||
.substring(6)
|
||||
.toLowerCase()
|
||||
.replace(/_([a-z])/g, (_, k) => {
|
||||
return k.toUpperCase();
|
||||
});
|
||||
|
||||
// Coerce string value into JS value
|
||||
let val = process.env[key];
|
||||
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
||||
val = true;
|
||||
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
||||
val = false;
|
||||
} else if (val === 'null') {
|
||||
val = null;
|
||||
} else {
|
||||
val = Number(val);
|
||||
}
|
||||
|
||||
obj[prop] = val;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
/**
|
||||
* Is stdout a TTY? Colored output is enabled when `true`.
|
||||
*/
|
||||
|
||||
function useColors() {
|
||||
return 'colors' in exports.inspectOpts ?
|
||||
Boolean(exports.inspectOpts.colors) :
|
||||
tty.isatty(process.stderr.fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds ANSI color escape codes if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs(args) {
|
||||
const {namespace: name, useColors} = this;
|
||||
|
||||
if (useColors) {
|
||||
const c = this.color;
|
||||
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
||||
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
||||
|
||||
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
||||
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
||||
} else {
|
||||
args[0] = getDate() + name + ' ' + args[0];
|
||||
}
|
||||
}
|
||||
|
||||
function getDate() {
|
||||
if (exports.inspectOpts.hideDate) {
|
||||
return '';
|
||||
}
|
||||
return new Date().toISOString() + ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
||||
*/
|
||||
|
||||
function log(...args) {
|
||||
return process.stderr.write(util.format(...args) + '\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
function save(namespaces) {
|
||||
if (namespaces) {
|
||||
process.env.DEBUG = namespaces;
|
||||
} else {
|
||||
// If you set a process.env field to null or undefined, it gets cast to the
|
||||
// string 'null' or 'undefined'. Just delete instead.
|
||||
delete process.env.DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function load() {
|
||||
return process.env.DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init logic for `debug` instances.
|
||||
*
|
||||
* Create a new `inspectOpts` object in case `useColors` is set
|
||||
* differently for a particular `debug` instance.
|
||||
*/
|
||||
|
||||
function init(debug) {
|
||||
debug.inspectOpts = {};
|
||||
|
||||
const keys = Object.keys(exports.inspectOpts);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
|
||||
const {formatters} = module.exports;
|
||||
|
||||
/**
|
||||
* Map %o to `util.inspect()`, all on a single line.
|
||||
*/
|
||||
|
||||
formatters.o = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts)
|
||||
.replace(/\s*\n\s*/g, ' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
||||
*/
|
||||
|
||||
formatters.O = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts);
|
||||
};
|
||||
162
node_modules/telegraf/node_modules/ms/index.js
generated
vendored
Normal file
162
node_modules/telegraf/node_modules/ms/index.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function(val, options) {
|
||||
options = options || {};
|
||||
var type = typeof val;
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isFinite(val)) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
throw new Error(
|
||||
'val is not a non-empty string or a valid number. val=' +
|
||||
JSON.stringify(val)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
||||
str
|
||||
);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
return ms + 'ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
return ms + ' ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
||||
21
node_modules/telegraf/node_modules/ms/license.md
generated
vendored
Normal file
21
node_modules/telegraf/node_modules/ms/license.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Zeit, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
69
node_modules/telegraf/node_modules/ms/package.json
generated
vendored
Normal file
69
node_modules/telegraf/node_modules/ms/package.json
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"_from": "ms@^2.1.1",
|
||||
"_id": "ms@2.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||
"_location": "/telegraf/ms",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "ms@^2.1.1",
|
||||
"name": "ms",
|
||||
"escapedName": "ms",
|
||||
"rawSpec": "^2.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/telegraf/debug"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"_shasum": "d09d1f357b443f493382a8eb3ccd183872ae6009",
|
||||
"_spec": "ms@^2.1.1",
|
||||
"_where": "/home/pablinux/Projects/Node/app_sigma/node_modules/telegraf/node_modules/debug",
|
||||
"bugs": {
|
||||
"url": "https://github.com/zeit/ms/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Tiny millisecond conversion utility",
|
||||
"devDependencies": {
|
||||
"eslint": "4.12.1",
|
||||
"expect.js": "0.3.1",
|
||||
"husky": "0.14.3",
|
||||
"lint-staged": "5.0.0",
|
||||
"mocha": "4.0.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/zeit/ms#readme",
|
||||
"license": "MIT",
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"npm run lint",
|
||||
"prettier --single-quote --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"main": "./index",
|
||||
"name": "ms",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zeit/ms.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint lib/* bin/*",
|
||||
"precommit": "lint-staged",
|
||||
"test": "mocha tests.js"
|
||||
},
|
||||
"version": "2.1.2"
|
||||
}
|
||||
60
node_modules/telegraf/node_modules/ms/readme.md
generated
vendored
Normal file
60
node_modules/telegraf/node_modules/ms/readme.md
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
# ms
|
||||
|
||||
[](https://travis-ci.org/zeit/ms)
|
||||
[](https://spectrum.chat/zeit)
|
||||
|
||||
Use this package to easily convert various time formats to milliseconds.
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
ms('2 days') // 172800000
|
||||
ms('1d') // 86400000
|
||||
ms('10h') // 36000000
|
||||
ms('2.5 hrs') // 9000000
|
||||
ms('2h') // 7200000
|
||||
ms('1m') // 60000
|
||||
ms('5s') // 5000
|
||||
ms('1y') // 31557600000
|
||||
ms('100') // 100
|
||||
ms('-3 days') // -259200000
|
||||
ms('-1h') // -3600000
|
||||
ms('-200') // -200
|
||||
```
|
||||
|
||||
### Convert from Milliseconds
|
||||
|
||||
```js
|
||||
ms(60000) // "1m"
|
||||
ms(2 * 60000) // "2m"
|
||||
ms(-3 * 60000) // "-3m"
|
||||
ms(ms('10 hours')) // "10h"
|
||||
```
|
||||
|
||||
### Time Format Written-Out
|
||||
|
||||
```js
|
||||
ms(60000, { long: true }) // "1 minute"
|
||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
||||
ms(-3 * 60000, { long: true }) // "-3 minutes"
|
||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Works both in [Node.js](https://nodejs.org) and in the browser
|
||||
- If a number is supplied to `ms`, a string with a unit is returned
|
||||
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)
|
||||
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
|
||||
|
||||
## Related Packages
|
||||
|
||||
- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.
|
||||
|
||||
## Caught a Bug?
|
||||
|
||||
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
|
||||
2. Link the package to the global module directory: `npm link`
|
||||
3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!
|
||||
|
||||
As always, you can run the tests using: `npm test`
|
||||
95
node_modules/telegraf/package.json
generated
vendored
Normal file
95
node_modules/telegraf/package.json
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
{
|
||||
"_from": "telegraf",
|
||||
"_id": "telegraf@3.37.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-V3448qwfOolBqkIc87yxjW4zMvR2P6AIF24pPTlX9WhZPwA1TF/x3nQhnWPRLtGh2SJuvDcr83iTkXPXT7Opnw==",
|
||||
"_location": "/telegraf",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "telegraf",
|
||||
"name": "telegraf",
|
||||
"escapedName": "telegraf",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.37.0.tgz",
|
||||
"_shasum": "f88ae3d4bddac6f479137d4c867489acf3f57b66",
|
||||
"_spec": "telegraf",
|
||||
"_where": "/home/pablinux/Projects/Node/app_sigma",
|
||||
"author": {
|
||||
"name": "Vitaly Domnikov",
|
||||
"email": "oss@vitaly.codes"
|
||||
},
|
||||
"bin": {
|
||||
"telegraf": "bin/telegraf"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/telegraf/telegraf/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"debug": "^4.0.1",
|
||||
"minimist": "^1.2.0",
|
||||
"module-alias": "^2.2.2",
|
||||
"node-fetch": "^2.2.0",
|
||||
"sandwich-stream": "^2.0.1",
|
||||
"telegram-typings": "^3.6.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Modern Telegram Bot Framework",
|
||||
"devDependencies": {
|
||||
"@types/node": "^13.1.0",
|
||||
"ava": "^3.0.0",
|
||||
"eslint": "^6.2.2",
|
||||
"eslint-config-standard": "^14.1.0",
|
||||
"eslint-plugin-ava": "^10.0.0",
|
||||
"eslint-plugin-import": "^2.2.0",
|
||||
"eslint-plugin-node": "^11.0.0",
|
||||
"eslint-plugin-promise": "^4.0.0",
|
||||
"eslint-plugin-standard": "^4.0.0",
|
||||
"husky": "^4.2.0",
|
||||
"typescript": "^3.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"files": [
|
||||
"bin/*",
|
||||
"core/**/*.js",
|
||||
"scenes/**/*.js",
|
||||
"typings/*.d.ts",
|
||||
"*.js"
|
||||
],
|
||||
"homepage": "https://github.com/telegraf/telegraf#readme",
|
||||
"keywords": [
|
||||
"telegraf",
|
||||
"telegram",
|
||||
"telegram bot api",
|
||||
"bot",
|
||||
"botapi",
|
||||
"bot framework"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "telegraf.js",
|
||||
"name": "telegraf",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/telegraf/telegraf.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"precommit": "npm run lint && npm run typecheck && npm test",
|
||||
"test": "ava test/*",
|
||||
"typecheck": "tsc"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"types": "./typings/index.d.ts",
|
||||
"version": "3.37.0"
|
||||
}
|
||||
64
node_modules/telegraf/readme.md
generated
vendored
Normal file
64
node_modules/telegraf/readme.md
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||

|
||||
[](https://core.telegram.org/bots/api)
|
||||
[](https://www.npmjs.com/package/telegraf)
|
||||
[](https://www.npmjs.com/package/telegraf)
|
||||
[](https://travis-ci.org/telegraf/telegraf)
|
||||
[](http://standardjs.com/)
|
||||
[](https://t.me/TelegrafJSChat)
|
||||
|
||||
## Introduction
|
||||
|
||||
Bots are special [Telegram](https://telegram.org) accounts designed to handle messages automatically.
|
||||
Users can interact with bots by sending them command messages in private or group chats.
|
||||
These accounts serve as an interface for code running somewhere on your server.
|
||||
|
||||
### Features
|
||||
|
||||
- Full [Telegram Bot API 4.7](https://core.telegram.org/bots/api) support
|
||||
- [Telegram Payment Platform](https://telegram.org/blog/payments)
|
||||
- [HTML5 Games](https://core.telegram.org/bots/api#games)
|
||||
- [Inline mode](https://core.telegram.org/bots/api#inline-mode)
|
||||
- Incredibly fast
|
||||
- [now](https://now.sh)/[Firebase](https://firebase.google.com/products/functions/)/[Glitch](https://dashing-light.glitch.me)/[Heroku](https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction)/[AWS **λ**](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html)/Whatever ready
|
||||
- `http/https/fastify/Connect.js/express.js` compatible webhooks
|
||||
- Easy to extend
|
||||
- `TypeScript` typings
|
||||
|
||||
### Installation
|
||||
|
||||
```
|
||||
$ npm install telegraf
|
||||
```
|
||||
or using `yarn`:
|
||||
```
|
||||
$ yarn add telegraf
|
||||
```
|
||||
|
||||
### Documentation
|
||||
|
||||
[Telegraf developer docs](http://telegraf.js.org)
|
||||
|
||||
### Examples
|
||||
|
||||
```js
|
||||
const Telegraf = require('telegraf')
|
||||
|
||||
const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
bot.start((ctx) => ctx.reply('Welcome!'))
|
||||
bot.help((ctx) => ctx.reply('Send me a sticker'))
|
||||
bot.on('sticker', (ctx) => ctx.reply('👍'))
|
||||
bot.hears('hi', (ctx) => ctx.reply('Hey there'))
|
||||
bot.launch()
|
||||
```
|
||||
|
||||
```js
|
||||
const Telegraf = require('telegraf')
|
||||
|
||||
const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
bot.command('oldschool', (ctx) => ctx.reply('Hello'))
|
||||
bot.command('modern', ({ reply }) => reply('Yo'))
|
||||
bot.command('hipster', Telegraf.reply('λ'))
|
||||
bot.launch()
|
||||
```
|
||||
|
||||
There's some cool [examples too](docs/examples/).
|
||||
43
node_modules/telegraf/router.js
generated
vendored
Normal file
43
node_modules/telegraf/router.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
const { compose, lazy, passThru } = require('./composer')
|
||||
|
||||
class Router {
|
||||
constructor (routeFn, handlers = new Map()) {
|
||||
if (!routeFn) {
|
||||
throw new Error('Missing routing function')
|
||||
}
|
||||
this.routeFn = routeFn
|
||||
this.handlers = handlers
|
||||
this.otherwiseHandler = passThru()
|
||||
}
|
||||
|
||||
on (route, ...fns) {
|
||||
if (fns.length === 0) {
|
||||
throw new TypeError('At least one handler must be provided')
|
||||
}
|
||||
this.handlers.set(route, compose(fns))
|
||||
return this
|
||||
}
|
||||
|
||||
otherwise (...fns) {
|
||||
if (fns.length === 0) {
|
||||
throw new TypeError('At least one otherwise handler must be provided')
|
||||
}
|
||||
this.otherwiseHandler = compose(fns)
|
||||
return this
|
||||
}
|
||||
|
||||
middleware () {
|
||||
return lazy((ctx) => {
|
||||
return Promise.resolve(this.routeFn(ctx)).then((result) => {
|
||||
if (!result || !result.route || !this.handlers.has(result.route)) {
|
||||
return this.otherwiseHandler
|
||||
}
|
||||
Object.assign(ctx, result.context)
|
||||
Object.assign(ctx.state, result.state)
|
||||
return this.handlers.get(result.route)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Router
|
||||
46
node_modules/telegraf/scenes/base.js
generated
vendored
Normal file
46
node_modules/telegraf/scenes/base.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
const Composer = require('../composer')
|
||||
const { compose } = Composer
|
||||
|
||||
class BaseScene extends Composer {
|
||||
constructor (id, options) {
|
||||
const opts = {
|
||||
handlers: [],
|
||||
enterHandlers: [],
|
||||
leaveHandlers: [],
|
||||
...options
|
||||
}
|
||||
super(...opts.handlers)
|
||||
this.id = id
|
||||
this.options = opts
|
||||
this.enterHandler = compose(opts.enterHandlers)
|
||||
this.leaveHandler = compose(opts.leaveHandlers)
|
||||
}
|
||||
|
||||
set ttl (value) {
|
||||
this.options.ttl = value
|
||||
}
|
||||
|
||||
get ttl () {
|
||||
return this.options.ttl
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseScene
|
||||
79
node_modules/telegraf/scenes/context.js
generated
vendored
Normal file
79
node_modules/telegraf/scenes/context.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
const debug = require('debug')('telegraf:scenes:context')
|
||||
const { safePassThru } = require('../composer')
|
||||
|
||||
const noop = () => Promise.resolve()
|
||||
const now = () => Math.floor(Date.now() / 1000)
|
||||
|
||||
class SceneContext {
|
||||
constructor (ctx, scenes, options) {
|
||||
this.ctx = ctx
|
||||
this.scenes = scenes
|
||||
this.options = options
|
||||
}
|
||||
|
||||
get session () {
|
||||
const sessionName = this.options.sessionName
|
||||
let session = this.ctx[sessionName].__scenes || {}
|
||||
if (session.expires < now()) {
|
||||
session = {}
|
||||
}
|
||||
this.ctx[sessionName].__scenes = session
|
||||
return session
|
||||
}
|
||||
|
||||
get state () {
|
||||
this.session.state = this.session.state || {}
|
||||
return this.session.state
|
||||
}
|
||||
|
||||
set state (value) {
|
||||
this.session.state = { ...value }
|
||||
}
|
||||
|
||||
get current () {
|
||||
const sceneId = this.session.current || this.options.default
|
||||
return (sceneId && this.scenes.has(sceneId)) ? this.scenes.get(sceneId) : null
|
||||
}
|
||||
|
||||
reset () {
|
||||
const sessionName = this.options.sessionName
|
||||
delete this.ctx[sessionName].__scenes
|
||||
}
|
||||
|
||||
enter (sceneId, initialState, silent) {
|
||||
if (!sceneId || !this.scenes.has(sceneId)) {
|
||||
throw new Error(`Can't find scene: ${sceneId}`)
|
||||
}
|
||||
const leave = silent ? noop() : this.leave()
|
||||
return leave.then(() => {
|
||||
debug('Enter scene', sceneId, initialState, silent)
|
||||
this.session.current = sceneId
|
||||
this.state = initialState
|
||||
const ttl = this.current.ttl || this.options.ttl
|
||||
if (ttl) {
|
||||
this.session.expires = now() + ttl
|
||||
}
|
||||
if (silent) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
const handler = typeof this.current.enterMiddleware === 'function'
|
||||
? this.current.enterMiddleware()
|
||||
: this.current.middleware()
|
||||
return handler(this.ctx, noop)
|
||||
})
|
||||
}
|
||||
|
||||
reenter () {
|
||||
return this.enter(this.session.current, this.state)
|
||||
}
|
||||
|
||||
leave () {
|
||||
debug('Leave scene')
|
||||
const handler = this.current && this.current.leaveMiddleware
|
||||
? this.current.leaveMiddleware()
|
||||
: safePassThru()
|
||||
return handler(this.ctx, noop).then(() => this.reset())
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SceneContext
|
||||
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
|
||||
33
node_modules/telegraf/session.js
generated
vendored
Normal file
33
node_modules/telegraf/session.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
module.exports = function (opts) {
|
||||
const options = {
|
||||
property: 'session',
|
||||
store: new Map(),
|
||||
getSessionKey: (ctx) => ctx.from && ctx.chat && `${ctx.from.id}:${ctx.chat.id}`,
|
||||
...opts
|
||||
}
|
||||
|
||||
const ttlMs = options.ttl && options.ttl * 1000
|
||||
|
||||
return (ctx, next) => {
|
||||
const key = options.getSessionKey(ctx)
|
||||
if (!key) {
|
||||
return next(ctx)
|
||||
}
|
||||
const now = Date.now()
|
||||
return Promise.resolve(options.store.get(key))
|
||||
.then((state) => state || { session: {} })
|
||||
.then(({ session, expires }) => {
|
||||
if (expires && expires < now) {
|
||||
session = {}
|
||||
}
|
||||
Object.defineProperty(ctx, options.property, {
|
||||
get: function () { return session },
|
||||
set: function (newValue) { session = { ...newValue } }
|
||||
})
|
||||
return next(ctx).then(() => options.store.set(key, {
|
||||
session,
|
||||
expires: ttlMs ? now + ttlMs : null
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
51
node_modules/telegraf/stage.js
generated
vendored
Normal file
51
node_modules/telegraf/stage.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
const SceneContext = require('./scenes/context')
|
||||
const Composer = require('./composer')
|
||||
const { compose, optional, lazy, safePassThru } = Composer
|
||||
|
||||
class Stage extends Composer {
|
||||
constructor (scenes = [], options) {
|
||||
super()
|
||||
this.options = {
|
||||
sessionName: 'session',
|
||||
...options
|
||||
}
|
||||
this.scenes = new Map()
|
||||
scenes.forEach((scene) => this.register(scene))
|
||||
}
|
||||
|
||||
register (...scenes) {
|
||||
scenes.forEach((scene) => {
|
||||
if (!scene || !scene.id || typeof scene.middleware !== 'function') {
|
||||
throw new Error('telegraf: Unsupported scene')
|
||||
}
|
||||
this.scenes.set(scene.id, scene)
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
||||
middleware () {
|
||||
const handler = compose([
|
||||
(ctx, next) => {
|
||||
ctx.scene = new SceneContext(ctx, this.scenes, this.options)
|
||||
return next()
|
||||
},
|
||||
super.middleware(),
|
||||
lazy((ctx) => ctx.scene.current || safePassThru())
|
||||
])
|
||||
return optional((ctx) => ctx[this.options.sessionName], 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)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Stage
|
||||
220
node_modules/telegraf/telegraf.js
generated
vendored
Normal file
220
node_modules/telegraf/telegraf.js
generated
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
const debug = require('debug')('telegraf:core')
|
||||
const Telegram = require('./telegram')
|
||||
const Extra = require('./extra')
|
||||
const Composer = require('./composer')
|
||||
const Markup = require('./markup')
|
||||
const session = require('./session')
|
||||
const Router = require('./router')
|
||||
const Stage = require('./stage')
|
||||
const BaseScene = require('./scenes/base')
|
||||
const Context = require('./context')
|
||||
const generateCallback = require('./core/network/webhook')
|
||||
const crypto = require('crypto')
|
||||
const { URL } = require('url')
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
retryAfter: 1,
|
||||
handlerTimeout: 0,
|
||||
contextType: Context
|
||||
}
|
||||
|
||||
const noop = () => { }
|
||||
|
||||
class Telegraf extends Composer {
|
||||
constructor (token, options) {
|
||||
super()
|
||||
this.options = {
|
||||
...DEFAULT_OPTIONS,
|
||||
...options
|
||||
}
|
||||
this.token = token
|
||||
this.handleError = (err) => {
|
||||
console.error()
|
||||
console.error((err.stack || err.toString()).replace(/^/gm, ' '))
|
||||
console.error()
|
||||
throw err
|
||||
}
|
||||
this.context = {}
|
||||
this.polling = {
|
||||
offset: 0,
|
||||
started: false
|
||||
}
|
||||
}
|
||||
|
||||
set token (token) {
|
||||
this.telegram = new Telegram(token, this.telegram
|
||||
? this.telegram.options
|
||||
: this.options.telegram
|
||||
)
|
||||
}
|
||||
|
||||
get token () {
|
||||
return this.telegram.token
|
||||
}
|
||||
|
||||
set webhookReply (webhookReply) {
|
||||
this.telegram.webhookReply = webhookReply
|
||||
}
|
||||
|
||||
get webhookReply () {
|
||||
return this.telegram.webhookReply
|
||||
}/* eslint brace-style: 0 */
|
||||
|
||||
catch (handler) {
|
||||
this.handleError = handler
|
||||
return this
|
||||
}
|
||||
|
||||
webhookCallback (path = '/') {
|
||||
return generateCallback(path, (update, res) => this.handleUpdate(update, res), debug)
|
||||
}
|
||||
|
||||
startPolling (timeout = 30, limit = 100, allowedUpdates, stopCallback = noop) {
|
||||
this.polling.timeout = timeout
|
||||
this.polling.limit = limit
|
||||
this.polling.allowedUpdates = allowedUpdates
|
||||
? Array.isArray(allowedUpdates) ? allowedUpdates : [`${allowedUpdates}`]
|
||||
: null
|
||||
this.polling.stopCallback = stopCallback
|
||||
if (!this.polling.started) {
|
||||
this.polling.started = true
|
||||
this.fetchUpdates()
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
startWebhook (hookPath, tlsOptions, port, host, cb) {
|
||||
const webhookCb = this.webhookCallback(hookPath)
|
||||
const callback = cb && typeof cb === 'function'
|
||||
? (req, res) => webhookCb(req, res, () => cb(req, res))
|
||||
: webhookCb
|
||||
this.webhookServer = tlsOptions
|
||||
? require('https').createServer(tlsOptions, callback)
|
||||
: require('http').createServer(callback)
|
||||
this.webhookServer.listen(port, host, () => {
|
||||
debug('Webhook listening on port: %s', port)
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
||||
launch (config = {}) {
|
||||
debug('Connecting to Telegram')
|
||||
return this.telegram.getMe()
|
||||
.then((botInfo) => {
|
||||
debug(`Launching @${botInfo.username}`)
|
||||
this.options.username = botInfo.username
|
||||
this.context.botInfo = botInfo
|
||||
if (!config.webhook) {
|
||||
const { timeout, limit, allowedUpdates, stopCallback } = config.polling || {}
|
||||
return this.telegram.deleteWebhook()
|
||||
.then(() => this.startPolling(timeout, limit, allowedUpdates, stopCallback))
|
||||
.then(() => debug('Bot started with long-polling'))
|
||||
}
|
||||
if (typeof config.webhook.domain !== 'string' && typeof config.webhook.hookPath !== 'string') {
|
||||
throw new Error('Webhook domain or webhook path is required')
|
||||
}
|
||||
let domain = config.webhook.domain || ''
|
||||
if (domain.startsWith('https://') || domain.startsWith('http://')) {
|
||||
domain = new URL(domain).host
|
||||
}
|
||||
const hookPath = config.webhook.hookPath || `/telegraf/${crypto.randomBytes(32).toString('hex')}`
|
||||
const { port, host, tlsOptions, cb } = config.webhook
|
||||
this.startWebhook(hookPath, tlsOptions, port, host, cb)
|
||||
if (!domain) {
|
||||
debug('Bot started with webhook')
|
||||
return
|
||||
}
|
||||
return this.telegram
|
||||
.setWebhook(`https://${domain}${hookPath}`)
|
||||
.then(() => debug(`Bot started with webhook @ https://${domain}`))
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Launch failed')
|
||||
console.error(err.stack || err.toString())
|
||||
})
|
||||
}
|
||||
|
||||
stop (cb = noop) {
|
||||
debug('Stopping bot...')
|
||||
return new Promise((resolve) => {
|
||||
const done = () => resolve() & cb()
|
||||
if (this.webhookServer) {
|
||||
return this.webhookServer.close(done)
|
||||
} else if (!this.polling.started) {
|
||||
return done()
|
||||
}
|
||||
this.polling.stopCallback = done
|
||||
this.polling.started = false
|
||||
})
|
||||
}
|
||||
|
||||
handleUpdates (updates) {
|
||||
if (!Array.isArray(updates)) {
|
||||
return Promise.reject(new Error('Updates must be an array'))
|
||||
}
|
||||
const processAll = Promise.all(updates.map((update) => this.handleUpdate(update)))
|
||||
if (this.options.handlerTimeout === 0) {
|
||||
return processAll
|
||||
}
|
||||
return Promise.race([
|
||||
processAll,
|
||||
new Promise((resolve) => setTimeout(resolve, this.options.handlerTimeout))
|
||||
])
|
||||
}
|
||||
|
||||
handleUpdate (update, webhookResponse) {
|
||||
debug('Processing update', update.update_id)
|
||||
const tg = new Telegram(this.token, this.telegram.options, webhookResponse)
|
||||
const TelegrafContext = this.options.contextType
|
||||
const ctx = new TelegrafContext(update, tg, this.options)
|
||||
Object.assign(ctx, this.context)
|
||||
return this.middleware()(ctx).catch((err) => this.handleError(err, ctx))
|
||||
}
|
||||
|
||||
fetchUpdates () {
|
||||
if (!this.polling.started) {
|
||||
this.polling.stopCallback && this.polling.stopCallback()
|
||||
return
|
||||
}
|
||||
const { timeout, limit, offset, allowedUpdates } = this.polling
|
||||
this.telegram.getUpdates(timeout, limit, offset, allowedUpdates)
|
||||
.catch((err) => {
|
||||
if (err.code === 401 || err.code === 409) {
|
||||
throw err
|
||||
}
|
||||
const wait = (err.parameters && err.parameters.retry_after) || this.options.retryAfter
|
||||
console.error(`Failed to fetch updates. Waiting: ${wait}s`, err.message)
|
||||
return new Promise((resolve) => setTimeout(resolve, wait * 1000, []))
|
||||
})
|
||||
.then((updates) => this.polling.started
|
||||
? this.handleUpdates(updates).then(() => updates)
|
||||
: []
|
||||
)
|
||||
.catch((err) => {
|
||||
console.error('Failed to process updates.', err)
|
||||
this.polling.started = false
|
||||
this.polling.offset = 0
|
||||
this.polling.stopCallback && this.polling.stopCallback()
|
||||
return []
|
||||
})
|
||||
.then((updates) => {
|
||||
if (updates.length > 0) {
|
||||
this.polling.offset = updates[updates.length - 1].update_id + 1
|
||||
}
|
||||
this.fetchUpdates()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Object.assign(Telegraf, {
|
||||
Context,
|
||||
Composer,
|
||||
default: Telegraf,
|
||||
Extra,
|
||||
Markup,
|
||||
Router,
|
||||
Telegram,
|
||||
Stage,
|
||||
BaseScene,
|
||||
session
|
||||
})
|
||||
433
node_modules/telegraf/telegram.js
generated
vendored
Normal file
433
node_modules/telegraf/telegram.js
generated
vendored
Normal file
@@ -0,0 +1,433 @@
|
||||
const replicators = require('./core/replicators')
|
||||
const ApiClient = require('./core/network/client')
|
||||
|
||||
class Telegram extends ApiClient {
|
||||
getMe () {
|
||||
return this.callApi('getMe')
|
||||
}
|
||||
|
||||
getFile (fileId) {
|
||||
return this.callApi('getFile', { file_id: fileId })
|
||||
}
|
||||
|
||||
getFileLink (fileId) {
|
||||
return Promise.resolve(fileId)
|
||||
.then((fileId) => {
|
||||
if (fileId && fileId.file_path) {
|
||||
return fileId
|
||||
}
|
||||
const id = fileId && fileId.file_id ? fileId.file_id : fileId
|
||||
return this.getFile(id)
|
||||
})
|
||||
.then((file) => `${this.options.apiRoot}/file/bot${this.token}/${file.file_path}`)
|
||||
}
|
||||
|
||||
getUpdates (timeout, limit, offset, allowedUpdates) {
|
||||
const url = `getUpdates?offset=${offset}&limit=${limit}&timeout=${timeout}`
|
||||
return this.callApi(url, {
|
||||
allowed_updates: allowedUpdates
|
||||
})
|
||||
}
|
||||
|
||||
getWebhookInfo () {
|
||||
return this.callApi('getWebhookInfo')
|
||||
}
|
||||
|
||||
getGameHighScores (userId, inlineMessageId, chatId, messageId) {
|
||||
return this.callApi('getGameHighScores', {
|
||||
user_id: userId,
|
||||
inline_message_id: inlineMessageId,
|
||||
chat_id: chatId,
|
||||
message_id: messageId
|
||||
})
|
||||
}
|
||||
|
||||
setGameScore (userId, score, inlineMessageId, chatId, messageId, editMessage = true, force) {
|
||||
return this.callApi('setGameScore', {
|
||||
force,
|
||||
score,
|
||||
user_id: userId,
|
||||
inline_message_id: inlineMessageId,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
disable_edit_message: !editMessage
|
||||
})
|
||||
}
|
||||
|
||||
setWebhook (url, certificate, maxConnections, allowedUpdates) {
|
||||
return this.callApi('setWebhook', {
|
||||
url,
|
||||
certificate,
|
||||
max_connections: maxConnections,
|
||||
allowed_updates: allowedUpdates
|
||||
})
|
||||
}
|
||||
|
||||
deleteWebhook () {
|
||||
return this.callApi('deleteWebhook')
|
||||
}
|
||||
|
||||
sendMessage (chatId, text, extra) {
|
||||
return this.callApi('sendMessage', { chat_id: chatId, text, ...extra })
|
||||
}
|
||||
|
||||
forwardMessage (chatId, fromChatId, messageId, extra) {
|
||||
return this.callApi('forwardMessage', {
|
||||
chat_id: chatId,
|
||||
from_chat_id: fromChatId,
|
||||
message_id: messageId,
|
||||
...extra
|
||||
})
|
||||
}
|
||||
|
||||
sendChatAction (chatId, action) {
|
||||
return this.callApi('sendChatAction', { chat_id: chatId, action })
|
||||
}
|
||||
|
||||
getUserProfilePhotos (userId, offset, limit) {
|
||||
return this.callApi('getUserProfilePhotos', { user_id: userId, offset, limit })
|
||||
}
|
||||
|
||||
sendLocation (chatId, latitude, longitude, extra) {
|
||||
return this.callApi('sendLocation', { chat_id: chatId, latitude, longitude, ...extra })
|
||||
}
|
||||
|
||||
sendVenue (chatId, latitude, longitude, title, address, extra) {
|
||||
return this.callApi('sendVenue', {
|
||||
latitude,
|
||||
longitude,
|
||||
title,
|
||||
address,
|
||||
chat_id: chatId,
|
||||
...extra
|
||||
})
|
||||
}
|
||||
|
||||
sendInvoice (chatId, invoice, extra) {
|
||||
return this.callApi('sendInvoice', { chat_id: chatId, ...invoice, ...extra })
|
||||
}
|
||||
|
||||
sendContact (chatId, phoneNumber, firstName, extra) {
|
||||
return this.callApi('sendContact', { chat_id: chatId, phone_number: phoneNumber, first_name: firstName, ...extra })
|
||||
}
|
||||
|
||||
sendPhoto (chatId, photo, extra) {
|
||||
return this.callApi('sendPhoto', { chat_id: chatId, photo, ...extra })
|
||||
}
|
||||
|
||||
sendDice (chatId, extra) {
|
||||
return this.callApi('sendDice', { chat_id: chatId, ...extra })
|
||||
}
|
||||
|
||||
sendDocument (chatId, document, extra) {
|
||||
return this.callApi('sendDocument', { chat_id: chatId, document, ...extra })
|
||||
}
|
||||
|
||||
sendAudio (chatId, audio, extra) {
|
||||
return this.callApi('sendAudio', { chat_id: chatId, audio, ...extra })
|
||||
}
|
||||
|
||||
sendSticker (chatId, sticker, extra) {
|
||||
return this.callApi('sendSticker', { chat_id: chatId, sticker, ...extra })
|
||||
}
|
||||
|
||||
sendVideo (chatId, video, extra) {
|
||||
return this.callApi('sendVideo', { chat_id: chatId, video, ...extra })
|
||||
}
|
||||
|
||||
sendAnimation (chatId, animation, extra) {
|
||||
return this.callApi('sendAnimation', { chat_id: chatId, animation, ...extra })
|
||||
}
|
||||
|
||||
sendVideoNote (chatId, videoNote, extra) {
|
||||
return this.callApi('sendVideoNote', { chat_id: chatId, video_note: videoNote, ...extra })
|
||||
}
|
||||
|
||||
sendVoice (chatId, voice, extra) {
|
||||
return this.callApi('sendVoice', { chat_id: chatId, voice, ...extra })
|
||||
}
|
||||
|
||||
sendGame (chatId, gameName, extra) {
|
||||
return this.callApi('sendGame', { chat_id: chatId, game_short_name: gameName, ...extra })
|
||||
}
|
||||
|
||||
sendMediaGroup (chatId, media, extra) {
|
||||
return this.callApi('sendMediaGroup', { chat_id: chatId, media, ...extra })
|
||||
}
|
||||
|
||||
sendPoll (chatId, question, options, extra) {
|
||||
return this.callApi('sendPoll', { chat_id: chatId, type: 'regular', question, options, ...extra })
|
||||
}
|
||||
|
||||
sendQuiz (chatId, question, options, extra) {
|
||||
return this.callApi('sendPoll', { chat_id: chatId, type: 'quiz', question, options, ...extra })
|
||||
}
|
||||
|
||||
stopPoll (chatId, messageId, extra) {
|
||||
return this.callApi('stopPoll', { chat_id: chatId, message_id: messageId, ...extra })
|
||||
}
|
||||
|
||||
getChat (chatId) {
|
||||
return this.callApi('getChat', { chat_id: chatId })
|
||||
}
|
||||
|
||||
getChatAdministrators (chatId) {
|
||||
return this.callApi('getChatAdministrators', { chat_id: chatId })
|
||||
}
|
||||
|
||||
getChatMember (chatId, userId) {
|
||||
return this.callApi('getChatMember', { chat_id: chatId, user_id: userId })
|
||||
}
|
||||
|
||||
getChatMembersCount (chatId) {
|
||||
return this.callApi('getChatMembersCount', { chat_id: chatId })
|
||||
}
|
||||
|
||||
answerInlineQuery (inlineQueryId, results, extra) {
|
||||
return this.callApi('answerInlineQuery', { inline_query_id: inlineQueryId, results, ...extra })
|
||||
}
|
||||
|
||||
setChatPermissions (chatId, permissions) {
|
||||
return this.callApi('setChatPermissions', { chat_id: chatId, permissions })
|
||||
}
|
||||
|
||||
kickChatMember (chatId, userId, untilDate) {
|
||||
return this.callApi('kickChatMember', { chat_id: chatId, user_id: userId, until_date: untilDate })
|
||||
}
|
||||
|
||||
promoteChatMember (chatId, userId, extra) {
|
||||
return this.callApi('promoteChatMember', { chat_id: chatId, user_id: userId, ...extra })
|
||||
}
|
||||
|
||||
restrictChatMember (chatId, userId, extra) {
|
||||
return this.callApi('restrictChatMember', { chat_id: chatId, user_id: userId, ...extra })
|
||||
}
|
||||
|
||||
setChatAdministratorCustomTitle (chatId, userId, title) {
|
||||
return this.callApi('setChatAdministratorCustomTitle', { chat_id: chatId, user_id: userId, custom_title: title })
|
||||
}
|
||||
|
||||
exportChatInviteLink (chatId) {
|
||||
return this.callApi('exportChatInviteLink', { chat_id: chatId })
|
||||
}
|
||||
|
||||
setChatPhoto (chatId, photo) {
|
||||
return this.callApi('setChatPhoto', { chat_id: chatId, photo })
|
||||
}
|
||||
|
||||
deleteChatPhoto (chatId) {
|
||||
return this.callApi('deleteChatPhoto', { chat_id: chatId })
|
||||
}
|
||||
|
||||
setChatTitle (chatId, title) {
|
||||
return this.callApi('setChatTitle', { chat_id: chatId, title })
|
||||
}
|
||||
|
||||
setChatDescription (chatId, description) {
|
||||
return this.callApi('setChatDescription', { chat_id: chatId, description })
|
||||
}
|
||||
|
||||
pinChatMessage (chatId, messageId, extra) {
|
||||
return this.callApi('pinChatMessage', { chat_id: chatId, message_id: messageId, ...extra })
|
||||
}
|
||||
|
||||
unpinChatMessage (chatId) {
|
||||
return this.callApi('unpinChatMessage', { chat_id: chatId })
|
||||
}
|
||||
|
||||
leaveChat (chatId) {
|
||||
return this.callApi('leaveChat', { chat_id: chatId })
|
||||
}
|
||||
|
||||
unbanChatMember (chatId, userId) {
|
||||
return this.callApi('unbanChatMember', { chat_id: chatId, user_id: userId })
|
||||
}
|
||||
|
||||
answerCbQuery (callbackQueryId, text, showAlert, extra) {
|
||||
return this.callApi('answerCallbackQuery', {
|
||||
text,
|
||||
show_alert: showAlert,
|
||||
callback_query_id: callbackQueryId,
|
||||
...extra
|
||||
})
|
||||
}
|
||||
|
||||
answerGameQuery (callbackQueryId, url) {
|
||||
return this.callApi('answerCallbackQuery', {
|
||||
url,
|
||||
callback_query_id: callbackQueryId
|
||||
})
|
||||
}
|
||||
|
||||
answerShippingQuery (shippingQueryId, ok, shippingOptions, errorMessage) {
|
||||
return this.callApi('answerShippingQuery', {
|
||||
ok,
|
||||
shipping_query_id: shippingQueryId,
|
||||
shipping_options: shippingOptions,
|
||||
error_message: errorMessage
|
||||
})
|
||||
}
|
||||
|
||||
answerPreCheckoutQuery (preCheckoutQueryId, ok, errorMessage) {
|
||||
return this.callApi('answerPreCheckoutQuery', {
|
||||
ok,
|
||||
pre_checkout_query_id: preCheckoutQueryId,
|
||||
error_message: errorMessage
|
||||
})
|
||||
}
|
||||
|
||||
editMessageText (chatId, messageId, inlineMessageId, text, extra) {
|
||||
return this.callApi('editMessageText', {
|
||||
text,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
...extra
|
||||
})
|
||||
}
|
||||
|
||||
editMessageCaption (chatId, messageId, inlineMessageId, caption, extra = {}) {
|
||||
return this.callApi('editMessageCaption', {
|
||||
caption,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
parse_mode: extra.parse_mode,
|
||||
reply_markup: extra.parse_mode || extra.reply_markup ? extra.reply_markup : extra
|
||||
})
|
||||
}
|
||||
|
||||
editMessageMedia (chatId, messageId, inlineMessageId, media, extra = {}) {
|
||||
return this.callApi('editMessageMedia', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
media: { ...media, parse_mode: extra.parse_mode },
|
||||
reply_markup: extra.reply_markup ? extra.reply_markup : extra
|
||||
})
|
||||
}
|
||||
|
||||
editMessageReplyMarkup (chatId, messageId, inlineMessageId, markup) {
|
||||
return this.callApi('editMessageReplyMarkup', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
reply_markup: markup
|
||||
})
|
||||
}
|
||||
|
||||
editMessageLiveLocation (latitude, longitude, chatId, messageId, inlineMessageId, markup) {
|
||||
return this.callApi('editMessageLiveLocation', {
|
||||
latitude,
|
||||
longitude,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
reply_markup: markup
|
||||
})
|
||||
}
|
||||
|
||||
stopMessageLiveLocation (chatId, messageId, inlineMessageId, markup) {
|
||||
return this.callApi('stopMessageLiveLocation', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
reply_markup: markup
|
||||
})
|
||||
}
|
||||
|
||||
deleteMessage (chatId, messageId) {
|
||||
return this.callApi('deleteMessage', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId
|
||||
})
|
||||
}
|
||||
|
||||
setChatStickerSet (chatId, setName) {
|
||||
return this.callApi('setChatStickerSet', {
|
||||
chat_id: chatId,
|
||||
sticker_set_name: setName
|
||||
})
|
||||
}
|
||||
|
||||
deleteChatStickerSet (chatId) {
|
||||
return this.callApi('deleteChatStickerSet', { chat_id: chatId })
|
||||
}
|
||||
|
||||
getStickerSet (name) {
|
||||
return this.callApi('getStickerSet', { name })
|
||||
}
|
||||
|
||||
uploadStickerFile (ownerId, stickerFile) {
|
||||
return this.callApi('uploadStickerFile', {
|
||||
user_id: ownerId,
|
||||
png_sticker: stickerFile
|
||||
})
|
||||
}
|
||||
|
||||
createNewStickerSet (ownerId, name, title, stickerData) {
|
||||
return this.callApi('createNewStickerSet', {
|
||||
name,
|
||||
title,
|
||||
user_id: ownerId,
|
||||
...stickerData
|
||||
})
|
||||
}
|
||||
|
||||
addStickerToSet (ownerId, name, stickerData, isMasks) {
|
||||
return this.callApi('addStickerToSet', {
|
||||
name,
|
||||
user_id: ownerId,
|
||||
is_masks: isMasks,
|
||||
...stickerData
|
||||
})
|
||||
}
|
||||
|
||||
setStickerPositionInSet (sticker, position) {
|
||||
return this.callApi('setStickerPositionInSet', {
|
||||
sticker,
|
||||
position
|
||||
})
|
||||
}
|
||||
|
||||
setStickerSetThumb (name, userId, thumb) {
|
||||
return this.callApi('setStickerSetThumb', { name, user_id: userId, thumb })
|
||||
}
|
||||
|
||||
deleteStickerFromSet (sticker) {
|
||||
return this.callApi('deleteStickerFromSet', { sticker })
|
||||
}
|
||||
|
||||
getMyCommands () {
|
||||
return this.callApi('getMyCommands')
|
||||
}
|
||||
|
||||
setMyCommands (commands) {
|
||||
return this.callApi('setMyCommands', { commands })
|
||||
}
|
||||
|
||||
setPassportDataErrors (userId, errors) {
|
||||
return this.callApi('setPassportDataErrors', {
|
||||
user_id: userId,
|
||||
errors: errors
|
||||
})
|
||||
}
|
||||
|
||||
sendCopy (chatId, message, extra) {
|
||||
if (!message) {
|
||||
throw new Error('Message is required')
|
||||
}
|
||||
const type = Object.keys(replicators.copyMethods).find((type) => message[type])
|
||||
if (!type) {
|
||||
throw new Error('Unsupported message type')
|
||||
}
|
||||
const opts = {
|
||||
chat_id: chatId,
|
||||
...replicators[type](message),
|
||||
...extra
|
||||
}
|
||||
return this.callApi(replicators.copyMethods[type], opts)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Telegram
|
||||
1538
node_modules/telegraf/typings/index.d.ts
generated
vendored
Normal file
1538
node_modules/telegraf/typings/index.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
615
node_modules/telegraf/typings/telegram-types.d.ts
generated
vendored
Normal file
615
node_modules/telegraf/typings/telegram-types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,615 @@
|
||||
import * as TT from "telegram-typings";
|
||||
export * from "telegram-typings";
|
||||
|
||||
export type ParseMode = 'Markdown' | 'MarkdownV2' | 'HTML'
|
||||
|
||||
export type ChatAction =
|
||||
'typing' |
|
||||
'upload_photo' |
|
||||
'record_video' |
|
||||
'upload_video' |
|
||||
'record_audio' |
|
||||
'upload_audio' |
|
||||
'upload_document' |
|
||||
'find_location' |
|
||||
'record_video_note' |
|
||||
'upload_video_note'
|
||||
|
||||
export type ChatType =
|
||||
'private' |
|
||||
'group' |
|
||||
'supergroup' |
|
||||
'channel'
|
||||
|
||||
export type UpdateType =
|
||||
'callback_query' |
|
||||
'channel_post' |
|
||||
'chosen_inline_result' |
|
||||
'edited_channel_post' |
|
||||
'edited_message' |
|
||||
'inline_query' |
|
||||
'message' |
|
||||
'pre_checkout_query' |
|
||||
'shipping_query'
|
||||
|
||||
export type MessageSubTypes =
|
||||
'voice' |
|
||||
'video_note' |
|
||||
'video' |
|
||||
'venue' |
|
||||
'text' |
|
||||
'supergroup_chat_created' |
|
||||
'successful_payment' |
|
||||
'sticker' |
|
||||
'pinned_message' |
|
||||
'photo' |
|
||||
'new_chat_title' |
|
||||
'new_chat_photo' |
|
||||
'new_chat_members' |
|
||||
'migrate_to_chat_id' |
|
||||
'migrate_from_chat_id' |
|
||||
'location' |
|
||||
'left_chat_member' |
|
||||
'invoice' |
|
||||
'group_chat_created' |
|
||||
'game' |
|
||||
'document' |
|
||||
'delete_chat_photo' |
|
||||
'contact' |
|
||||
'channel_chat_created' |
|
||||
'audio' |
|
||||
'passport_data' |
|
||||
'connected_website' |
|
||||
'animation'
|
||||
|
||||
export type InlineQueryResult =
|
||||
TT.InlineQueryResultCachedAudio |
|
||||
TT.InlineQueryResultCachedDocument |
|
||||
TT.InlineQueryResultCachedGif |
|
||||
TT.InlineQueryResultCachedMpeg4Gif |
|
||||
TT.InlineQueryResultCachedPhoto |
|
||||
TT.InlineQueryResultCachedSticker |
|
||||
TT.InlineQueryResultCachedVideo |
|
||||
TT.InlineQueryResultCachedVoice |
|
||||
TT.InlineQueryResultArticle |
|
||||
TT.InlineQueryResultAudio |
|
||||
TT.InlineQueryResultContact |
|
||||
TT.InlineQueryResultGame |
|
||||
TT.InlineQueryResultDocument |
|
||||
TT.InlineQueryResultGif |
|
||||
TT.InlineQueryResultLocation |
|
||||
TT.InlineQueryResultMpeg4Gif |
|
||||
TT.InlineQueryResultPhoto |
|
||||
TT.InlineQueryResultVenue |
|
||||
TT.InlineQueryResultVideo |
|
||||
TT.InlineQueryResultVoice
|
||||
|
||||
export type MessageMedia =
|
||||
InputMediaPhoto |
|
||||
InputMediaVideo |
|
||||
InputMediaAnimation |
|
||||
InputMediaAudio |
|
||||
InputMediaDocument
|
||||
|
||||
export interface InputMediaPhoto {
|
||||
type: string
|
||||
media: string
|
||||
caption?: string
|
||||
parse_mode?: string
|
||||
}
|
||||
|
||||
export interface InputMediaVideo {
|
||||
type: string
|
||||
media: string
|
||||
thumb?: string | InputFile
|
||||
caption?: string
|
||||
parse_mode?: string
|
||||
width?: number
|
||||
height?: number
|
||||
duration?: number
|
||||
supports_streaming?: boolean
|
||||
}
|
||||
|
||||
export interface InputMediaAnimation {
|
||||
type: string
|
||||
media: string
|
||||
thumb?: string | InputFile
|
||||
caption?: string
|
||||
parse_mode?: string
|
||||
width?: number
|
||||
height?: number
|
||||
duration?: number
|
||||
supports_streaming?: boolean
|
||||
}
|
||||
|
||||
export interface InputMediaAudio {
|
||||
type: string
|
||||
media: string
|
||||
thumb?: string | InputFile
|
||||
caption?: string
|
||||
parse_mode?: string
|
||||
performer?: string
|
||||
title?: string
|
||||
duration?: number
|
||||
supports_streaming?: boolean
|
||||
}
|
||||
|
||||
export interface InputMediaDocument {
|
||||
type: string
|
||||
media: string
|
||||
thumb?: string | InputFile
|
||||
caption?: string
|
||||
parse_mode?: string
|
||||
}
|
||||
|
||||
export interface StickerData {
|
||||
png_sticker: string | Buffer
|
||||
emojis: string
|
||||
mask_position: TT.MaskPosition
|
||||
}
|
||||
|
||||
type FileId = string
|
||||
|
||||
interface InputFileByPath {
|
||||
source: string
|
||||
}
|
||||
|
||||
interface InputFileByReadableStream {
|
||||
source: NodeJS.ReadableStream
|
||||
}
|
||||
|
||||
interface InputFileByBuffer {
|
||||
source: Buffer
|
||||
}
|
||||
|
||||
interface InputFileByURL {
|
||||
url: string
|
||||
filename: string
|
||||
}
|
||||
|
||||
export type InputFile =
|
||||
FileId |
|
||||
InputFileByPath |
|
||||
InputFileByReadableStream |
|
||||
InputFileByBuffer |
|
||||
InputFileByURL
|
||||
|
||||
/**
|
||||
* Sending video notes by a URL is currently unsupported
|
||||
*/
|
||||
export type InputFileVideoNote = Exclude<InputFile, InputFileByURL>
|
||||
|
||||
export interface ExtraReplyMessage {
|
||||
|
||||
/**
|
||||
* Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
|
||||
*/
|
||||
parse_mode?: ParseMode
|
||||
|
||||
/**
|
||||
* Disables link previews for links in this message
|
||||
*/
|
||||
disable_web_page_preview?: boolean
|
||||
|
||||
/**
|
||||
* Sends the message silently. Users will receive a notification with no sound.
|
||||
*/
|
||||
disable_notification?: boolean
|
||||
|
||||
/**
|
||||
* If the message is a reply, ID of the original message
|
||||
*/
|
||||
reply_to_message_id?: number
|
||||
|
||||
/**
|
||||
* Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
*/
|
||||
reply_markup?: TT.InlineKeyboardMarkup | TT.ReplyKeyboardMarkup | TT.ReplyKeyboardRemove | TT.ForceReply
|
||||
}
|
||||
|
||||
export interface ExtraEditMessage extends ExtraReplyMessage {
|
||||
// no specified properties
|
||||
}
|
||||
|
||||
export interface ExtraAudio extends ExtraReplyMessage {
|
||||
/**
|
||||
* Audio caption, 0-1024 characters
|
||||
*/
|
||||
caption?: string
|
||||
|
||||
/**
|
||||
* Duration of the audio in seconds
|
||||
*/
|
||||
duration?: number
|
||||
|
||||
/**
|
||||
* Performer
|
||||
*/
|
||||
performer?: string
|
||||
|
||||
/**
|
||||
* Track name
|
||||
*/
|
||||
title?: string
|
||||
|
||||
/**
|
||||
* Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
* The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320.
|
||||
* Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file,
|
||||
* so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
*/
|
||||
thumb?: InputFile
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendaudio
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
}
|
||||
|
||||
export interface ExtraDocument extends ExtraReplyMessage {
|
||||
/**
|
||||
* Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
* The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320.
|
||||
* Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file,
|
||||
* so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
*/
|
||||
thumb?: InputFile
|
||||
|
||||
/**
|
||||
* Document caption (may also be used when resending documents by file_id), 0-1024 characters
|
||||
*/
|
||||
caption?: string
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#senddocument
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
}
|
||||
|
||||
export interface ExtraGame extends ExtraReplyMessage {
|
||||
/**
|
||||
* Inline keyboard. If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game.
|
||||
*/
|
||||
reply_markup?: TT.InlineKeyboardMarkup
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendgame
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendgame
|
||||
*/
|
||||
parse_mode?: never
|
||||
}
|
||||
|
||||
export interface ExtraInvoice extends ExtraReplyMessage {
|
||||
/**
|
||||
* Inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
|
||||
*/
|
||||
reply_markup?: TT.InlineKeyboardMarkup
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendinvoice
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendinvoice
|
||||
*/
|
||||
parse_mode?: never
|
||||
}
|
||||
|
||||
export interface ExtraLocation extends ExtraReplyMessage {
|
||||
/**
|
||||
* Period in seconds for which the location will be updated (should be between 60 and 86400)
|
||||
*/
|
||||
live_period?: number
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendlocation
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendlocation
|
||||
*/
|
||||
parse_mode?: never
|
||||
}
|
||||
|
||||
export interface ExtraPhoto extends ExtraReplyMessage {
|
||||
/**
|
||||
* Photo caption (may also be used when resending photos by file_id), 0-1024 characters
|
||||
*/
|
||||
caption?: string
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendphoto
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
}
|
||||
|
||||
export interface ExtraMediaGroup extends ExtraReplyMessage {
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendmediagroup
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendmediagroup
|
||||
*/
|
||||
parse_mode?: never
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendmediagroup
|
||||
*/
|
||||
reply_markup?: never
|
||||
}
|
||||
|
||||
export interface ExtraAnimation extends ExtraReplyMessage {
|
||||
/**
|
||||
* Animation caption (may also be used when resending animation by file_id), 0-200 characters
|
||||
*/
|
||||
caption?: string
|
||||
}
|
||||
|
||||
export interface ExtraSticker extends ExtraReplyMessage {
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendsticker
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendsticker
|
||||
*/
|
||||
parse_mode?: never
|
||||
}
|
||||
|
||||
export interface ExtraVideo extends ExtraReplyMessage {
|
||||
/**
|
||||
* Duration of sent video in seconds
|
||||
*/
|
||||
duration?: number
|
||||
|
||||
/**
|
||||
* Video width
|
||||
*/
|
||||
width?: number
|
||||
|
||||
/**
|
||||
* Video height
|
||||
*/
|
||||
height?: number
|
||||
|
||||
/**
|
||||
* Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
* The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320.
|
||||
* Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file,
|
||||
* so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
*/
|
||||
thumb?: InputFile
|
||||
|
||||
/**
|
||||
* Video caption (may also be used when resending videos by file_id), 0-1024 characters
|
||||
*/
|
||||
caption?: string
|
||||
|
||||
/**
|
||||
* Pass True, if the uploaded video is suitable for streaming
|
||||
*/
|
||||
supports_streaming?: boolean
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendvideo
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
}
|
||||
|
||||
export interface ExtraVideoNote extends ExtraReplyMessage {
|
||||
/**
|
||||
* Duration of sent video in seconds
|
||||
*/
|
||||
duration?: number
|
||||
|
||||
/**
|
||||
* Video width and height, i.e. diameter of the video message
|
||||
*/
|
||||
length?: number
|
||||
|
||||
/**
|
||||
* Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
* The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320.
|
||||
* Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file,
|
||||
* so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
*/
|
||||
thumb?: InputFile
|
||||
}
|
||||
|
||||
export interface ExtraVoice extends ExtraReplyMessage {
|
||||
/**
|
||||
* Voice message caption, 0-1024 characters
|
||||
*/
|
||||
caption?: string
|
||||
|
||||
/**
|
||||
* Duration of the voice message in seconds
|
||||
*/
|
||||
duration?: number
|
||||
|
||||
/**
|
||||
* Does not exist, see https://core.telegram.org/bots/api#sendvoice
|
||||
*/
|
||||
disable_web_page_preview?: never
|
||||
}
|
||||
|
||||
export interface IncomingMessage extends TT.Message {
|
||||
audio?: TT.Audio
|
||||
entities?: TT.MessageEntity[]
|
||||
caption?: string
|
||||
document?: TT.Document
|
||||
game?: TT.Game
|
||||
photo?: TT.PhotoSize[]
|
||||
animation?: TT.Animation
|
||||
sticker?: TT.Sticker
|
||||
video?: TT.Video
|
||||
video_note?: TT.VideoNote
|
||||
contact?: TT.Contact
|
||||
location?: TT.Location
|
||||
venue?: TT.Venue
|
||||
pinned_message?: TT.Message
|
||||
invoice?: TT.Invoice
|
||||
successful_payment?: TT.SuccessfulPayment
|
||||
}
|
||||
|
||||
export interface MessageAudio extends TT.Message {
|
||||
audio: TT.Audio
|
||||
}
|
||||
|
||||
export interface MessageDocument extends TT.Message {
|
||||
document: TT.Document
|
||||
}
|
||||
|
||||
export interface MessageGame extends TT.Message {
|
||||
game: TT.Game
|
||||
}
|
||||
|
||||
export interface MessageInvoice extends TT.Message {
|
||||
invoice: TT.Invoice
|
||||
}
|
||||
|
||||
export interface MessageLocation extends TT.Message {
|
||||
location: TT.Location
|
||||
}
|
||||
|
||||
export interface MessagePhoto extends TT.Message {
|
||||
photo: TT.PhotoSize[]
|
||||
}
|
||||
|
||||
export interface MessageAnimation extends TT.Message {
|
||||
animation: TT.Animation
|
||||
}
|
||||
|
||||
export interface MessageSticker extends TT.Message {
|
||||
sticker: TT.Sticker
|
||||
}
|
||||
|
||||
export interface MessageVideo extends TT.Message {
|
||||
video: TT.Video
|
||||
}
|
||||
|
||||
export interface MessageVideoNote extends TT.Message {
|
||||
video_note: TT.VideoNote
|
||||
}
|
||||
|
||||
export interface MessageVoice extends TT.Message {
|
||||
voice: TT.Voice
|
||||
}
|
||||
|
||||
export interface NewInvoiceParams {
|
||||
/**
|
||||
* Product name, 1-32 characters
|
||||
*/
|
||||
title: string
|
||||
|
||||
/**
|
||||
* Product description, 1-255 characters
|
||||
*/
|
||||
description: string
|
||||
|
||||
/**
|
||||
* Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
|
||||
*/
|
||||
payload: string
|
||||
|
||||
/**
|
||||
* Payments provider token, obtained via Botfather
|
||||
*/
|
||||
provider_token: string
|
||||
|
||||
/**
|
||||
* Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
|
||||
*/
|
||||
start_parameter: string
|
||||
|
||||
/**
|
||||
* Three-letter ISO 4217 currency code, see more on currencies
|
||||
*/
|
||||
currency: string
|
||||
|
||||
/**
|
||||
* Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
|
||||
*/
|
||||
prices: TT.LabeledPrice[]
|
||||
|
||||
/**
|
||||
* URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
|
||||
*/
|
||||
photo_url?: string
|
||||
|
||||
/**
|
||||
* Photo size
|
||||
*/
|
||||
photo_size?: number
|
||||
|
||||
/**
|
||||
* Photo width
|
||||
*/
|
||||
photo_width?: number
|
||||
|
||||
/**
|
||||
* Photo height
|
||||
*/
|
||||
photo_height?: number
|
||||
|
||||
/**
|
||||
* Pass True, if you require the user's full name to complete the order
|
||||
*/
|
||||
need_name?: true
|
||||
|
||||
/**
|
||||
* Pass True, if you require the user's phone number to complete the order
|
||||
*/
|
||||
need_phone_number?: true
|
||||
|
||||
/**
|
||||
* Pass True, if you require the user's email to complete the order
|
||||
*/
|
||||
need_email?: true
|
||||
|
||||
/**
|
||||
* Pass True, if you require the user's shipping address to complete the order
|
||||
*/
|
||||
need_shipping_address?: true
|
||||
|
||||
/**
|
||||
* Pass True, if the final price depends on the shipping method
|
||||
*/
|
||||
is_flexible?: true
|
||||
}
|
||||
|
||||
export interface ExtraAnswerInlineQuery {
|
||||
/**
|
||||
* The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
|
||||
*/
|
||||
cache_time?: number
|
||||
|
||||
/**
|
||||
* Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
|
||||
*/
|
||||
is_personal?: boolean
|
||||
|
||||
/**
|
||||
* Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.
|
||||
*/
|
||||
next_offset?: string
|
||||
|
||||
/**
|
||||
* If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter
|
||||
*/
|
||||
switch_pm_text?: string
|
||||
|
||||
/**
|
||||
* Deep-linking parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
|
||||
*/
|
||||
switch_pm_parameter?: string
|
||||
}
|
||||
Reference in New Issue
Block a user