Browse Source

Forgot an import in Utils

Chris Watson 5 years ago
parent
commit
01d5e702fb
3 changed files with 28 additions and 16 deletions
  1. 5 5
      gramjs/Utils.js
  2. 16 11
      gramjs/client/TelegramClient.js
  3. 7 0
      gramjs/extensions/index.js

+ 5 - 5
gramjs/Utils.js

@@ -1,7 +1,7 @@
 const path = require('path')
 const mime = require('mime-types')
 const struct = require('python-struct')
-const { markdown, html } = require('./extensions')
+const { MarkdownParser, HTMLParser } = require('./extensions')
 const { types } = require('./tl')
 
 const USERNAME_RE = new RegExp('@|(?:https?:\\/\\/)?(?:www\\.)?' +
@@ -868,8 +868,7 @@ function getMessageId(message) {
 }
 
 /**
- Converts the given parse mode into an object with
- `parse` and `unparse` callable properties.
+ Converts the given parse mode into a matching parser.
  */
 function sanitizeParseMode(mode) {
     if (!mode) return null
@@ -889,10 +888,10 @@ function sanitizeParseMode(mode) {
         switch (mode.toLowerCase()) {
         case 'md':
         case 'markdown':
-            return markdown
+            return MarkdownParser
         case 'htm':
         case 'html':
-            return html
+            return HTMLParser
         default:
             throw new Error(`Unknown parse mode ${mode}`)
         }
@@ -1263,6 +1262,7 @@ module.exports = {
     getInputUser,
     getInputChannel,
     getInputPeer,
+    getInputPhoto,
     parsePhone,
     parseUsername,
     getPeer,

+ 16 - 11
gramjs/client/TelegramClient.js

@@ -17,6 +17,9 @@ const Helpers = require('../Helpers')
 const { ConnectionTCPObfuscated } = require('../network/connection/TCPObfuscated')
 const { BinaryWriter } = require('../extensions')
 const events = require('../events')
+
+const { MessageMethods } = require('./Messages')
+
 const DEFAULT_DC_ID = 4
 const DEFAULT_IPV4_IP = '149.154.167.51'
 const DEFAULT_IPV6_IP = '[2001:67c:4e8:f002::a]'
@@ -24,6 +27,8 @@ const DEFAULT_PORT = 443
 
 // Chunk sizes for upload.getFile must be multiples of the smallest size
 const MIN_CHUNK_SIZE = 4096
+
+// eslint-disable-next-line no-unused-vars
 const MAX_CHUNK_SIZE = 512 * 1024
 
 
@@ -340,9 +345,11 @@ class TelegramClient {
             while (typeof args.phone == 'function') {
                 const value = await args.phone()
                 if (value.indexOf(':') !== -1) {
+                    // eslint-disable-next-line require-atomic-updates
                     args.botToken = value
                     break
                 }
+                // eslint-disable-next-line require-atomic-updates
                 args.phone = utils.parsePhone(value) || args.phone
             }
         }
@@ -430,7 +437,6 @@ class TelegramClient {
                     password: args.password,
                 })
             }
-
         }
         const name = utils.getDisplayName(me)
         this._log.error('Signed in successfully as', name)
@@ -460,9 +466,8 @@ class TelegramClient {
         } else if (args.password) {
             const pwd = await this.invoke(new functions.account.GetPasswordRequest())
             result = await this.invoke(new functions.auth.CheckPasswordRequest({
-                    password: computeCheck(pwd, args.password),
-                },
-            ))
+                password: computeCheck(pwd, args.password),
+            }))
         } else if (args.botToken) {
             result = await this.invoke(new functions.auth.ImportBotAuthorizationRequest(
                 {
@@ -909,9 +914,8 @@ class TelegramClient {
         this._log.info(`Exporting authorization for data center ${dc.ipAddress}`)
         const auth = await this.invoke(new functions.auth.ExportAuthorizationRequest({ dcId: dcId }))
         const req = this._initWith(new functions.auth.ImportAuthorizationRequest({
-                id: auth.id, bytes: auth.bytes,
-            },
-        ))
+            id: auth.id, bytes: auth.bytes,
+        }))
         await sender.send(req)
         return sender
     }
@@ -1039,7 +1043,8 @@ class TelegramClient {
             return await this._downloadDocument(media, file, date, args.thumb, args.progressCallback, media.dcId)
         } else if (media instanceof types.MessageMediaContact && args.thumb == null) {
             return this._downloadContact(media, file)
-        } else if ((media instanceof types.WebDocument || media instanceof types.WebDocumentNoProxy) && args.thumb == null) {
+        } else if ((media instanceof types.WebDocument || media instanceof types.WebDocumentNoProxy) &&
+                    args.thumb == null) {
             return await this._downloadWebDocument(media, file, args.progressCallback)
         }
     }
@@ -1108,8 +1113,6 @@ class TelegramClient {
                 throw e
             }
         }
-
-
     }
 
     _getThumb(thumbs, thumb) {
@@ -1215,7 +1218,9 @@ class TelegramClient {
     }
 
     // endregion
-
 }
 
+// Method mixins
+Object.assign(TelegramClient.prototype, MessageMethods)
+
 module.exports = TelegramClient

+ 7 - 0
gramjs/extensions/index.js

@@ -5,6 +5,10 @@ const PromisedWebSockets = require('./PromisedWebSockets')
 const MessagePacker = require('./MessagePacker')
 const AsyncQueue = require('./AsyncQueue')
 const PromisedNetSocket = require('./PromisedNetSockets')
+const Scanner = require('./Scanner')
+const MarkdownParser = require('./Markdown')
+const HTMLParser = null
+
 module.exports = {
     BinaryWriter,
     BinaryReader,
@@ -13,4 +17,7 @@ module.exports = {
     Logger,
     PromisedWebSockets,
     PromisedNetSocket,
+    Scanner,
+    MarkdownParser,
+    HTMLParser,
 }