فهرست منبع

Support numbers as well as bigInts

painor 3 سال پیش
والد
کامیت
1e96afa296
5فایلهای تغییر یافته به همراه12 افزوده شده و 3 حذف شده
  1. 4 1
      gramjs/Helpers.ts
  2. 3 0
      gramjs/Utils.ts
  3. 1 1
      gramjs/Version.ts
  4. 3 0
      gramjs/client/users.ts
  5. 1 1
      package.json

+ 4 - 1
gramjs/Helpers.ts

@@ -393,13 +393,16 @@ export function getByteArray(
     );
     );
 }
 }
 
 
-export function returnBigInt(num: bigInt.BigInteger | string | number) {
+export function returnBigInt(num: bigInt.BigInteger | string | number | bigint) {
     if (bigInt.isInstance(num)) {
     if (bigInt.isInstance(num)) {
         return num;
         return num;
     }
     }
     if (typeof num == "number") {
     if (typeof num == "number") {
         return bigInt(num);
         return bigInt(num);
     }
     }
+    if (typeof num == "bigint") {
+        return bigInt(num);
+    }
     return bigInt(num);
     return bigInt(num);
 }
 }
 
 

+ 3 - 0
gramjs/Utils.ts

@@ -987,6 +987,9 @@ export function getPeer(peer: EntityLike | any) {
     if (typeof peer === "string") {
     if (typeof peer === "string") {
         _raiseCastFail(peer, "peer");
         _raiseCastFail(peer, "peer");
     }
     }
+    if (typeof peer=="number" ||typeof peer=="bigint"){
+        peer = returnBigInt(peer);
+    }
     try {
     try {
         if (bigInt.isInstance(peer)) {
         if (bigInt.isInstance(peer)) {
             const res = resolveId(peer);
             const res = resolveId(peer);

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "2.0.3";
+export const version = "2.0.4";

+ 3 - 0
gramjs/client/users.ts

@@ -286,6 +286,9 @@ export async function getInputEntity(
     // will work with accessHash = 0. Similar for channels.getChannels.
     // will work with accessHash = 0. Similar for channels.getChannels.
     // If we're not a bot but the user is in our contacts, it seems to work
     // If we're not a bot but the user is in our contacts, it seems to work
     // regardless. These are the only two special-cased requests.
     // regardless. These are the only two special-cased requests.
+    if (typeof peer === "number"){
+        peer = returnBigInt(peer);
+    }
     peer = utils.getPeer(peer);
     peer = utils.getPeer(peer);
     if (peer instanceof Api.PeerUser) {
     if (peer instanceof Api.PeerUser) {
         const users = await client.invoke(
         const users = await client.invoke(

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "telegram",
   "name": "telegram",
-  "version": "2.0.3",
+  "version": "2.0.4",
   "description": "NodeJS/Browser MTProto API Telegram client library,",
   "description": "NodeJS/Browser MTProto API Telegram client library,",
   "main": "index.js",
   "main": "index.js",
   "types": "index.d.ts",
   "types": "index.d.ts",