Browse Source

Update packages.
Fix fromUsers not working.

painor 3 years ago
parent
commit
27ad1cdc9b

+ 2 - 2
gramjs/Password.ts

@@ -206,7 +206,7 @@ async function computeDigest(
 ) {
     try {
         checkPrimeAndGood(algo.p, algo.g);
-    } catch (e) {
+    } catch (e:any) {
         throw new Error("bad p/g in password");
     }
 
@@ -244,7 +244,7 @@ async function computeCheck(request: Api.account.Password, password: string) {
     const B = readBigIntFromBuffer(srp_B, false);
     try {
         checkPrimeAndGood(algo.p, g);
-    } catch (e) {
+    } catch (e:any) {
         throw new Error("bad /g in password");
     }
     if (!isGoodLarge(B, p)) {

+ 1 - 1
gramjs/Utils.ts

@@ -188,7 +188,7 @@ export function _getEntityPair(
     let inputEntity;
     try {
         inputEntity = cache.get(entityId);
-    } catch (e) {
+    } catch (e:any) {
         try {
             inputEntity = getInputPeerFunction(inputEntity);
         } catch (e) {}

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "1.9.0";
+export const version = "1.9.1";

+ 1 - 1
gramjs/client/2fa.ts

@@ -129,7 +129,7 @@ export async function updateTwoFaSettings(
                         new Api.account.ConfirmPasswordEmail({ code })
                     );
                     break;
-                } catch (err) {
+                } catch (err: any) {
                     onEmailCodeError!(err);
                 }
             }

+ 23 - 22
gramjs/client/auth.ts

@@ -3,6 +3,7 @@ import * as utils from "../Utils";
 import { sleep } from "../Helpers";
 import { computeCheck as computePasswordSrpCheck } from "../Password";
 import type { TelegramClient } from "./TelegramClient";
+import { RPCError } from "../errors";
 
 /**
  * For when you want to login as a {@link Api.User}<br/>
@@ -92,7 +93,7 @@ export async function start(
 
     const apiCredentials = {
         apiId: client.apiId,
-        apiHash: client.apiHash,
+        apiHash: client.apiHash
     };
 
     await _authFlow(client, apiCredentials, authParams);
@@ -123,7 +124,7 @@ export async function signInUser(
             if (typeof authParams.phoneNumber === "function") {
                 try {
                     phoneNumber = await authParams.phoneNumber();
-                } catch (err) {
+                } catch (err: any) {
                     if (err.errorMessage === "RESTART_AUTH_WITH_QR") {
                         return client.signInUserWithQrCode(
                             apiCredentials,
@@ -149,7 +150,7 @@ export async function signInUser(
             }
 
             break;
-        } catch (err) {
+        } catch (err:any) {
             if (typeof authParams.phoneNumber !== "function") {
                 throw err;
             }
@@ -169,7 +170,7 @@ export async function signInUser(
         try {
             try {
                 phoneCode = await authParams.phoneCode(isCodeViaApp);
-            } catch (err) {
+            } catch (err:any) {
                 // This is the support for changing phone number from the phone code screen.
                 if (err.errorMessage === "RESTART_AUTH") {
                     return client.signInUser(apiCredentials, authParams);
@@ -186,7 +187,7 @@ export async function signInUser(
                 new Api.auth.SignIn({
                     phoneNumber,
                     phoneCodeHash,
-                    phoneCode,
+                    phoneCode
                 })
             );
 
@@ -197,7 +198,7 @@ export async function signInUser(
             }
 
             return result.user;
-        } catch (err) {
+        } catch (err:any) {
             if (err.errorMessage === "SESSION_PASSWORD_NEEDED") {
                 return client.signInWithPassword(apiCredentials, authParams);
             } else {
@@ -228,7 +229,7 @@ export async function signInUser(
                         phoneNumber,
                         phoneCodeHash,
                         firstName,
-                        lastName,
+                        lastName
                     })
                 )) as Api.auth.Authorization;
 
@@ -236,13 +237,13 @@ export async function signInUser(
                     // This is a violation of Telegram rules: the user should be presented with and accept TOS.
                     await client.invoke(
                         new Api.help.AcceptTermsOfService({
-                            id: termsOfService.id,
+                            id: termsOfService.id
                         })
                     );
                 }
 
                 return user;
-            } catch (err) {
+            } catch (err:any) {
                 const shouldWeStop = await authParams.onError(err);
                 if (shouldWeStop) {
                     throw new Error("AUTH_USER_CANCEL");
@@ -267,7 +268,7 @@ export async function signInUserWithQrCode(
                 new Api.auth.ExportLoginToken({
                     apiId: Number(apiCredentials.apiId),
                     apiHash: apiCredentials.apiHash,
-                    exceptIds: [],
+                    exceptIds: []
                 })
             );
 
@@ -279,7 +280,7 @@ export async function signInUserWithQrCode(
             if (authParams.qrCode) {
                 await Promise.race([
                     authParams.qrCode({ token, expires }),
-                    sleep(QR_CODE_TIMEOUT),
+                    sleep(QR_CODE_TIMEOUT)
                 ]);
             }
             await sleep(QR_CODE_TIMEOUT);
@@ -305,7 +306,7 @@ export async function signInUserWithQrCode(
             new Api.auth.ExportLoginToken({
                 apiId: Number(apiCredentials.apiId),
                 apiHash: apiCredentials.apiHash,
-                exceptIds: [],
+                exceptIds: []
             })
         );
         if (
@@ -317,7 +318,7 @@ export async function signInUserWithQrCode(
             await client._switchDC(result2.dcId);
             const migratedResult = await client.invoke(
                 new Api.auth.ImportLoginToken({
-                    token: result2.token,
+                    token: result2.token
                 })
             );
 
@@ -328,7 +329,7 @@ export async function signInUserWithQrCode(
                 return migratedResult.authorization.user;
             }
         }
-    } catch (err) {
+    } catch (err:any) {
         if (err.errorMessage === "SESSION_PASSWORD_NEEDED") {
             return client.signInWithPassword(apiCredentials, authParams);
         }
@@ -355,7 +356,7 @@ export async function sendCode(
                 phoneNumber,
                 apiId,
                 apiHash,
-                settings: new Api.CodeSettings({}),
+                settings: new Api.CodeSettings({})
             })
         );
 
@@ -364,22 +365,22 @@ export async function sendCode(
             return {
                 phoneCodeHash: sendResult.phoneCodeHash,
                 isCodeViaApp:
-                    sendResult.type instanceof Api.auth.SentCodeTypeApp,
+                    sendResult.type instanceof Api.auth.SentCodeTypeApp
             };
         }
 
         const resendResult = await client.invoke(
             new Api.auth.ResendCode({
                 phoneNumber,
-                phoneCodeHash: sendResult.phoneCodeHash,
+                phoneCodeHash: sendResult.phoneCodeHash
             })
         );
 
         return {
             phoneCodeHash: resendResult.phoneCodeHash,
-            isCodeViaApp: resendResult.type instanceof Api.auth.SentCodeTypeApp,
+            isCodeViaApp: resendResult.type instanceof Api.auth.SentCodeTypeApp
         };
-    } catch (err) {
+    } catch (err:any) {
         if (err.errorMessage === "AUTH_RESTART") {
             return client.sendCode(apiCredentials, phoneNumber, forceSMS);
         } else {
@@ -416,12 +417,12 @@ export async function signInWithPassword(
             );
             const { user } = (await client.invoke(
                 new Api.auth.CheckPassword({
-                    password: passwordSrpCheck,
+                    password: passwordSrpCheck
                 })
             )) as Api.auth.Authorization;
 
             return user;
-        } catch (err) {
+        } catch (err:any) {
             const shouldWeStop = await authParams.onError(err);
             if (shouldWeStop) {
                 throw new Error("AUTH_USER_CANCEL");
@@ -460,7 +461,7 @@ export async function signInBot(
         new Api.auth.ImportBotAuthorization({
             apiId,
             apiHash,
-            botAuthToken,
+            botAuthToken
         })
     )) as Api.auth.Authorization;
     return user;

+ 1 - 1
gramjs/client/messages.ts

@@ -357,7 +357,7 @@ export class _IDsIter extends RequestIter {
                         id: ids,
                     })
                 );
-            } catch (e) {
+            } catch (e:any) {
                 if (e.errorMessage == "MESSAGE_IDS_EMPTY") {
                     r = new Api.messages.MessagesNotModified({
                         count: ids.length,

+ 1 - 1
gramjs/client/telegramBaseClient.ts

@@ -412,7 +412,7 @@ export abstract class TelegramBaseClient {
                 sender.userDisconnected = false;
 
                 return sender;
-            } catch (err) {
+            } catch (err:any) {
                 if (err.errorMessage === "DC_ID_INVALID") {
                     sender._authenticated = true;
                     sender.userDisconnected = false;

+ 2 - 2
gramjs/client/updates.ts

@@ -182,7 +182,7 @@ export async function _updateLoop(client: TelegramClient): Promise<void> {
                 PING_FAIL_ATTEMPTS,
                 PING_FAIL_INTERVAL
             );
-        } catch (err) {
+        } catch (err:any) {
             // eslint-disable-next-line no-console
             client._log.error(err);
             if (client._reconnecting) {
@@ -218,7 +218,7 @@ async function attempts(cb: CallableFunction, times: number, pause: number) {
         try {
             // We need to `return await` here so it can be caught locally
             return await cb();
-        } catch (err) {
+        } catch (err: any) {
             if (i === times - 1) {
                 throw err;
             }

+ 1 - 1
gramjs/client/uploads.ts

@@ -125,7 +125,7 @@ export async function uploadFile(
                                           bytes: bytesMemo,
                                       })
                             );
-                        } catch (err) {
+                        } catch (err: any) {
                             if (sender && !sender.isConnected()) {
                                 await sleep(DISCONNECT_SLEEP);
                                 continue;

+ 3 - 3
gramjs/client/users.ts

@@ -32,7 +32,7 @@ export async function invoke<R extends Api.AnyRequest>(
             client.session.processEntities(result);
             client._entityCache.add(result);
             return result;
-        } catch (e) {
+        } catch (e:any) {
             if (
                 e instanceof errors.ServerError ||
                 e.errorMessage === "RPC_CALL_FAIL" ||
@@ -326,7 +326,7 @@ export async function _getEntityFromString(
                     }
                 }
             }
-        } catch (e) {
+        } catch (e:any) {
             if (e.errorMessage === "BOT_METHOD_INVALID") {
                 throw new Error(
                     "Cannot get entity by phone number as a " +
@@ -372,7 +372,7 @@ export async function _getEntityFromString(
                         }
                     }
                 }
-            } catch (e) {
+            } catch (e:any) {
                 if (e.errorMessage === "USERNAME_NOT_OCCUPIED") {
                     throw new Error(`No user has "${username}" as username`);
                 }

+ 13 - 6
gramjs/events/NewMessage.ts

@@ -2,7 +2,7 @@ import {
     _intoIdSet,
     DefaultEventInterface,
     EventBuilder,
-    EventCommon,
+    EventCommon
 } from "./common";
 import type { Entity, EntityLike } from "../define";
 import type { TelegramClient } from "..";
@@ -89,7 +89,7 @@ export class NewMessage extends EventBuilder {
             fromUsers,
             forwards,
             pattern,
-            blacklistChats = false,
+            blacklistChats = false
         } = newMessageParams;
         if (incoming && outgoing) {
             incoming = outgoing = undefined;
@@ -115,7 +115,7 @@ export class NewMessage extends EventBuilder {
             pattern,
             fromUsers,
             forwards,
-            func,
+            func
         ].every((v) => v == undefined);
     }
 
@@ -156,7 +156,7 @@ export class NewMessage extends EventBuilder {
                     fwdFrom: update.fwdFrom,
                     viaBotId: update.viaBotId,
                     replyTo: update.replyTo,
-                    entities: update.entities,
+                    entities: update.entities
                     // ttlPeriod:update.ttlPeriod
                 }),
                 update
@@ -176,7 +176,7 @@ export class NewMessage extends EventBuilder {
                     fwdFrom: update.fwdFrom,
                     viaBotId: update.viaBotId,
                     replyTo: update.replyTo,
-                    entities: update.entities,
+                    entities: update.entities
                     // ttlPeriod:update.ttlPeriod
                 }),
                 update
@@ -199,6 +199,13 @@ export class NewMessage extends EventBuilder {
                 return;
             }
         }
+
+        if (this.fromUsers != undefined) {
+            if (!this.fromUsers.includes(event.message.senderId!)) {
+                return;
+            }
+        }
+
         if (this.pattern) {
             const match = event.message.message?.match(this.pattern);
             if (!match) {
@@ -222,7 +229,7 @@ export class NewMessageEvent extends EventCommon {
         super({
             msgId: message.id,
             chatPeer: message.peerId,
-            broadcast: message.post,
+            broadcast: message.post
         });
         this.originalUpdate = originalUpdate;
         this.message = message;

+ 6 - 6
gramjs/network/MTProtoSender.ts

@@ -431,7 +431,7 @@ export class MTProtoSender {
 
             try {
                 await this._connection!.send(data);
-            } catch (e) {
+            } catch (e:any) {
                 this._log.error(e);
                 this._log.info("Connection closed while sending data");
                 return;
@@ -462,7 +462,7 @@ export class MTProtoSender {
             this._log.debug("Receiving items from the network...");
             try {
                 body = await this._connection!.recv();
-            } catch (e) {
+            } catch (e:any) {
                 /** when the server disconnects us we want to reconnect */
                 this._log.warn("Connection closed while receiving data");
                 if (!this.userDisconnected) {
@@ -474,7 +474,7 @@ export class MTProtoSender {
             }
             try {
                 message = await this._state.decryptMessageData(body);
-            } catch (e) {
+            } catch (e:any) {
                 if (e instanceof TypeNotFoundError) {
                     // Received object which we don't know how to deserialize
                     this._log.info(
@@ -527,7 +527,7 @@ export class MTProtoSender {
             }
             try {
                 await this._processMessage(message);
-            } catch (e) {
+            } catch (e:any) {
                 this._log.error("Unhandled error while receiving data");
                 this._log.error(e);
             }
@@ -624,7 +624,7 @@ export class MTProtoSender {
                 if (!(reader.tgReadObject() instanceof Api.upload.File)) {
                     throw new Error("Not an upload.File");
                 }
-            } catch (e) {
+            } catch (e:any) {
                 this._log.error(e);
                 if (e instanceof TypeNotFoundError) {
                     this._log.info(
@@ -910,7 +910,7 @@ export class MTProtoSender {
         this._log.debug("Closing current connection...");
         try {
             await this.disconnect();
-        } catch (err) {
+        } catch (err: any) {
             this._log.warn(err);
         }
         // @ts-ignore

+ 2 - 2
gramjs/network/connection/Connection.ts

@@ -117,7 +117,7 @@ class Connection {
                 }
                 await this._send(data);
             }
-        } catch (e) {
+        } catch (e:any) {
             this._log.info("The server closed the connection while sending");
         }
     }
@@ -130,7 +130,7 @@ class Connection {
                 if (!data) {
                     throw new Error("no data received");
                 }
-            } catch (e) {
+            } catch (e:any) {
                 this._log.info("connection closed");
                 //await this._recvArray.push()
 

+ 2 - 2
gramjs/tl/custom/messageButton.ts

@@ -69,7 +69,7 @@ export class MessageButton {
             });
             try {
                 return await this._client.invoke(request);
-            } catch (e) {
+            } catch (e:any) {
                 if (e.errorMessage == "BOT_RESPONSE_TIMEOUT") {
                     return null;
                 }
@@ -93,7 +93,7 @@ export class MessageButton {
             });
             try {
                 return await this._client.invoke(request);
-            } catch (e) {
+            } catch (e:any) {
                 if (e.errorMessage == "BOT_RESPONSE_TIMEOUT") {
                     return null;
                 }

+ 7 - 7
gramjs/tl/generationHelpers.ts

@@ -15,7 +15,7 @@ const CORE_TYPES = new Set([
     0x997275b5, // boolTrue#997275b5 = Bool;
     0x3fedd339, // true#3fedd339 = True;
     0xc4b9f9bb, // error#c4b9f9bb code:int text:string = Error;
-    0x56730bcc, // null#56730bcc = Null;
+    0x56730bcc // null#56730bcc = Null;
 ]);
 const AUTH_KEY_TYPES = new Set([
     0x05162463, // resPQ,
@@ -28,7 +28,7 @@ const AUTH_KEY_TYPES = new Set([
     0x6643b654, // client_DH_inner_data
     0xd712e4be, // req_DH_params
     0xf5045f1f, // set_client_DH_params
-    0x3072cfa1, // gzip_packed
+    0x3072cfa1 // gzip_packed
 ]);
 
 const fromLine = (line: string, isFunction: boolean) => {
@@ -48,7 +48,7 @@ const fromLine = (line: string, isFunction: boolean) => {
         subclassOfId: crc32(match[3]),
         result: match[3],
         isFunction: isFunction,
-        namespace: undefined,
+        namespace: undefined
     };
     if (!currentConfig.constructorId) {
         const hexId = "";
@@ -112,7 +112,7 @@ function buildArgConfig(name: string, argType: string) {
         flagIndex: -1,
         flagIndicator: true,
         type: null,
-        useVectorId: null,
+        useVectorId: null
     };
 
     // Special case: some types can be inferred, which makes it
@@ -235,7 +235,7 @@ const parseTl = function* (
                 objByName[result.name] = result;
                 objByType[result.result].push(result);
             }
-        } catch (e) {
+        } catch (e: any) {
             if (!e.toString().includes("vector#1cb5c415")) {
                 throw e;
             }
@@ -301,7 +301,7 @@ export function serializeBytes(data: Buffer | string | any) {
                 254,
                 data.length % 256,
                 (data.length >> 8) % 256,
-                (data.length >> 16) % 256,
+                (data.length >> 16) % 256
             ])
         );
         r.push(data);
@@ -333,5 +333,5 @@ export {
     fromLine,
     CORE_TYPES,
     snakeToCamelCase,
-    variableSnakeToCamelCase,
+    variableSnakeToCamelCase
 };

File diff suppressed because it is too large
+ 1067 - 1824
package-lock.json


+ 8 - 4
package.json

@@ -1,6 +1,6 @@
 {
   "name": "telegram",
-  "version": "1.9.0",
+  "version": "1.9.1",
   "description": "NodeJS/Browser MTProto API Telegram client library,",
   "main": "index.js",
   "types": "index.d.ts",
@@ -25,6 +25,10 @@
     "api"
   ],
   "homepage": "https://github.com/gram-js/gramjs#readme",
+  "optionalDependencies": {
+    "bufferutil": "^4.0.3",
+    "utf-8-validate": "^5.0.5"
+  },
   "devDependencies": {
     "@babel/core": "^7.12.13",
     "@babel/plugin-proposal-class-properties": "^7.12.13",
@@ -34,7 +38,7 @@
     "@types/node": "^15.12.0",
     "@types/node-localstorage": "^1.3.0",
     "@types/pako": "^1.0.1",
-    "@types/websocket": "^1.0.1",
+    "@types/websocket": "^1.0.4",
     "babel-loader": "^8.2.2",
     "jest": "^26.6.3",
     "prettier": "2.3.1",
@@ -62,8 +66,8 @@
     "socks": "^2.6.1",
     "store2": "^2.12.0",
     "ts-custom-error": "^3.2.0",
-    "ts-mixer": "^5.4.0",
+    "ts-mixer": "^6.0.0",
     "util": "^0.12.4",
-    "websocket": "^1.0.33"
+    "websocket": "^1.0.34"
   }
 }

Some files were not shown because too many files changed in this diff