IPC removed, replaced by WS
This commit is contained in:
1 parent
ba4217fb24
commit
656c193511
503 files changed
+28128
-34498
No files matched your search
+22
@@ -34,6 +34,7 @@ const MessageSubTypes = [
|
||||
'invoice',
|
||||
'group_chat_created',
|
||||
'game',
|
||||
'dice',
|
||||
'document',
|
||||
'delete_chat_photo',
|
||||
'contact',
|
||||
@@ -419,6 +420,11 @@ class TelegrafContext {
|
||||
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)
|
||||
@@ -512,6 +518,10 @@ class TelegrafContext {
|
||||
return this.telegram.setStickerPositionInSet(sticker, position)
|
||||
}
|
||||
|
||||
setStickerSetThumb (...args) {
|
||||
return this.telegram.setStickerSetThumb(...args)
|
||||
}
|
||||
|
||||
deleteStickerFromSet (sticker) {
|
||||
return this.telegram.deleteStickerFromSet(sticker)
|
||||
}
|
||||
@@ -531,10 +541,22 @@ class TelegrafContext {
|
||||
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 })
|
||||
}
|
||||
|
||||
+46
-74
@@ -163,80 +163,16 @@ class Markup {
|
||||
}
|
||||
}
|
||||
|
||||
static formatHTML (text, entities) {
|
||||
const chars = [...text]
|
||||
const available = [...entities]
|
||||
const opened = []
|
||||
const result = []
|
||||
for (let offset = 0; offset < chars.length; offset++) {
|
||||
while (true) {
|
||||
const index = available.findIndex((entity) => entity.offset === offset)
|
||||
if (index === -1) {
|
||||
break
|
||||
}
|
||||
const entity = available[index]
|
||||
switch (entity.type) {
|
||||
case 'bold':
|
||||
result.push('<b>')
|
||||
break
|
||||
case 'italic':
|
||||
result.push('<i>')
|
||||
break
|
||||
case 'code':
|
||||
result.push('<code>')
|
||||
break
|
||||
case 'pre':
|
||||
result.push('<pre>')
|
||||
break
|
||||
case 'strikethrough':
|
||||
result.push('<s>')
|
||||
break
|
||||
case 'underline':
|
||||
result.push('<u>')
|
||||
break
|
||||
case 'text_link':
|
||||
result.push(`<a href="${entity.url}">`)
|
||||
break
|
||||
}
|
||||
opened.unshift(entity)
|
||||
available.splice(index, 1)
|
||||
}
|
||||
|
||||
result.push(chars[offset])
|
||||
|
||||
while (true) {
|
||||
const index = opened.findIndex((entity) => entity.offset + entity.length - 1 === offset)
|
||||
if (index === -1) {
|
||||
break
|
||||
}
|
||||
const entity = opened[index]
|
||||
switch (entity.type) {
|
||||
case 'bold':
|
||||
result.push('</b>')
|
||||
break
|
||||
case 'italic':
|
||||
result.push('</i>')
|
||||
break
|
||||
case 'code':
|
||||
result.push('</code>')
|
||||
break
|
||||
case 'pre':
|
||||
result.push('</pre>')
|
||||
break
|
||||
case 'strikethrough':
|
||||
result.push('</s>')
|
||||
break
|
||||
case 'underline':
|
||||
result.push('</u>')
|
||||
break
|
||||
case 'text_link':
|
||||
result.push('</a>')
|
||||
break
|
||||
}
|
||||
opened.splice(index, 1)
|
||||
}
|
||||
}
|
||||
return result.join('')
|
||||
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('')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,4 +203,40 @@ function buildKeyboard (buttons, options) {
|
||||
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
|
||||
+12
-12
@@ -1,41 +1,40 @@
|
||||
{
|
||||
"_from": "telegraf@3.36.0",
|
||||
"_id": "telegraf@3.36.0",
|
||||
"_from": "telegraf@3.37.0",
|
||||
"_id": "telegraf@3.37.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-9o6AJKRiTm5vMWYI6WpTfBHzu4FMpWBNKxvnMxRds/cbMY9RnsVVjdi8i4bFFlfd+xbi73EbrnI3dybayryICA==",
|
||||
"_integrity": "sha512-V3448qwfOolBqkIc87yxjW4zMvR2P6AIF24pPTlX9WhZPwA1TF/x3nQhnWPRLtGh2SJuvDcr83iTkXPXT7Opnw==",
|
||||
"_location": "/telegraf",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "telegraf@3.36.0",
|
||||
"raw": "telegraf@3.37.0",
|
||||
"name": "telegraf",
|
||||
"escapedName": "telegraf",
|
||||
"rawSpec": "3.36.0",
|
||||
"rawSpec": "3.37.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "3.36.0"
|
||||
"fetchSpec": "3.37.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.36.0.tgz",
|
||||
"_shasum": "eab1160159df6033d3cb92ac990902523277822a",
|
||||
"_spec": "telegraf@3.36.0",
|
||||
"_resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.37.0.tgz",
|
||||
"_shasum": "f88ae3d4bddac6f479137d4c867489acf3f57b66",
|
||||
"_spec": "telegraf@3.37.0",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer",
|
||||
"author": {
|
||||
"name": "Vitaly Domnikov",
|
||||
"email": "oss@vitaly.codes"
|
||||
},
|
||||
"bin": {
|
||||
"telegraf": "./bin/telegraf"
|
||||
"telegraf": "bin/telegraf"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/telegraf/telegraf/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@types/node": "^13.1.0",
|
||||
"debug": "^4.0.1",
|
||||
"minimist": "^1.2.0",
|
||||
"module-alias": "^2.2.2",
|
||||
@@ -46,6 +45,7 @@
|
||||
"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",
|
||||
@@ -91,5 +91,5 @@
|
||||
},
|
||||
"type": "commonjs",
|
||||
"types": "./typings/index.d.ts",
|
||||
"version": "3.36.0"
|
||||
"version": "3.37.0"
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@ const debug = require('debug')('telegraf:scenes:context')
|
||||
const { safePassThru } = require('../composer')
|
||||
|
||||
const noop = () => Promise.resolve()
|
||||
const now = () => Math.floor(new Date().getTime() / 1000)
|
||||
const now = () => Math.floor(Date.now() / 1000)
|
||||
|
||||
class SceneContext {
|
||||
constructor (ctx, scenes, options) {
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ module.exports = function (opts) {
|
||||
if (!key) {
|
||||
return next(ctx)
|
||||
}
|
||||
const now = new Date().getTime()
|
||||
const now = Date.now()
|
||||
return Promise.resolve(options.store.get(key))
|
||||
.then((state) => state || { session: {} })
|
||||
.then(({ session, expires }) => {
|
||||
|
||||
+1
-10
@@ -209,16 +209,7 @@ class Telegraf extends Composer {
|
||||
module.exports = Object.assign(Telegraf, {
|
||||
Context,
|
||||
Composer,
|
||||
Extra,
|
||||
Markup,
|
||||
Router,
|
||||
Telegram,
|
||||
session
|
||||
})
|
||||
|
||||
module.exports.default = Object.assign(Telegraf, {
|
||||
Context,
|
||||
Composer,
|
||||
default: Telegraf,
|
||||
Extra,
|
||||
Markup,
|
||||
Router,
|
||||
|
||||
+16
@@ -115,6 +115,10 @@ class Telegram extends ApiClient {
|
||||
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 })
|
||||
}
|
||||
@@ -386,10 +390,22 @@ class Telegram extends ApiClient {
|
||||
})
|
||||
}
|
||||
|
||||
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,
|
||||
|
||||
Reference in new issue
Block a user