rubjs 2.2.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/rubjs/client.js +2 -2
  4. package/rubjs/methods/index.d.ts +9 -0
  5. package/rubjs/methods/index.js +45 -39
  6. package/rubjs/methods/messages/sendDocument.d.ts +2 -2
  7. package/rubjs/methods/messages/sendDocument.js +2 -2
  8. package/rubjs/methods/messages/sendGif.d.ts +1 -1
  9. package/rubjs/methods/messages/sendGif.js +2 -2
  10. package/rubjs/methods/messages/sendMessage.js +23 -11
  11. package/rubjs/methods/messages/sendMusic.d.ts +2 -2
  12. package/rubjs/methods/messages/sendMusic.js +2 -2
  13. package/rubjs/methods/messages/sendPhoto.d.ts +1 -1
  14. package/rubjs/methods/messages/sendPhoto.js +2 -2
  15. package/rubjs/methods/messages/sendVideo.d.ts +2 -2
  16. package/rubjs/methods/messages/sendVideo.js +2 -2
  17. package/rubjs/methods/messages/sendVideoMessage.d.ts +2 -2
  18. package/rubjs/methods/messages/sendVideoMessage.js +2 -2
  19. package/rubjs/methods/messages/sendVoice.d.ts +2 -2
  20. package/rubjs/methods/messages/sendVoice.js +2 -2
  21. package/rubjs/methods/utilities/download.d.ts +3 -2
  22. package/rubjs/methods/utilities/download.js +3 -3
  23. package/rubjs/methods/utilities/get.d.ts +4 -0
  24. package/rubjs/methods/utilities/get.js +21 -0
  25. package/rubjs/methods/utilities/index.d.ts +3 -1
  26. package/rubjs/methods/utilities/index.js +5 -1
  27. package/rubjs/methods/utilities/post.d.ts +4 -0
  28. package/rubjs/methods/utilities/post.js +21 -0
  29. package/rubjs/methods/utilities/thumbnail.d.ts +1 -0
  30. package/rubjs/methods/utilities/thumbnail.js +15 -1
  31. package/rubjs/network/index.d.ts +1 -0
  32. package/rubjs/network/index.js +63 -9
  33. package/rubjs/parser/index.js +4 -2
  34. package/rubjs/types/message.d.ts +9 -2
  35. package/rubjs/types/message.js +34 -4
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  ### حساب‌ غیرهمزمان
11
11
 
12
12
  ```javascript
13
- const { Client, Utils, Filters } = require("../rubjs");
13
+ const { Client, Utils, Filters } = require("rubjs");
14
14
 
15
15
  const bot = new Client("bot");
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubjs",
3
- "version": "2.2.3",
3
+ "version": "2.4.0",
4
4
  "main": "rubjs/index.js",
5
5
  "types": "rubjs/index.d.ts",
6
6
  "keywords": [
package/rubjs/client.js CHANGED
@@ -20,8 +20,8 @@ class Client extends methods_1.default {
20
20
  this.userAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36`;
21
21
  if (platform.toLowerCase() === "android") {
22
22
  this.defaultPlatform.platform = "Android";
23
- this.defaultPlatform["package"] = "app.rbmain.a";
24
- this.defaultPlatform["app_version"] = "3.6.4";
23
+ this.defaultPlatform.package = "app.rbmain.a";
24
+ this.defaultPlatform.app_version = "3.6.4";
25
25
  }
26
26
  this.sessionFile = sessionFile;
27
27
  this.userGuid = null;
@@ -143,8 +143,14 @@ declare class Methods {
143
143
  getPollOptionVoters(this: Client, ...args: Parameters<typeof Messages.getPollOptionVoters>): Promise<MessagesTypes.GetPollOptionVoters>;
144
144
  getPollStatus(this: Client, ...args: Parameters<typeof Messages.getPollStatus>): Promise<MessagesTypes.GetPollStatus>;
145
145
  requestSendFile(this: Client, ...args: Parameters<typeof Messages.requestSendFile>): Promise<MessagesTypes.RequestSendFile>;
146
+ sendDocument(this: Client, ...args: Parameters<typeof Messages.sendDocument>): Promise<any>;
147
+ sendGif(this: Client, ...args: Parameters<typeof Messages.sendGif>): Promise<any>;
146
148
  sendMessage(this: Client, ...args: Parameters<typeof Messages.sendMessage>): Promise<MessagesTypes.SendMessageResult>;
149
+ sendMusic(this: Client, ...args: Parameters<typeof Messages.sendMusic>): Promise<any>;
147
150
  sendPhoto(this: Client, ...args: Parameters<typeof Messages.sendPhoto>): Promise<MessagesTypes.SendMessageResult>;
151
+ sendVideo(this: Client, ...args: Parameters<typeof Messages.sendVideo>): Promise<any>;
152
+ sendVideoMessage(this: Client, ...args: Parameters<typeof Messages.sendVideoMessage>): Promise<any>;
153
+ sendVoice(this: Client, ...args: Parameters<typeof Messages.sendVoice>): Promise<any>;
148
154
  setPinMessage(this: Client, ...args: Parameters<typeof Messages.setPinMessage>): Promise<MessagesTypes.SetPinMessage>;
149
155
  votePoll(this: Client, ...args: Parameters<typeof Messages.votePoll>): Promise<MessagesTypes.GetPollStatus>;
150
156
  sendText(this: Client, ...args: Parameters<typeof Messages.sendText>): Promise<MessagesTypes.SendMessageResult>;
@@ -179,7 +185,10 @@ declare class Methods {
179
185
  getMe(this: Client, ...args: Parameters<typeof Users.getMe>): Promise<UserTypes.UserInfo>;
180
186
  getUserInfo(this: Client, ...args: Parameters<typeof Users.getUserInfo>): Promise<UserTypes.UserInfo>;
181
187
  setBlockUser(this: Client, ...args: Parameters<typeof Users.setBlockUser>): Promise<any>;
188
+ download(this: Client, ...args: Parameters<typeof Utilities.download>): Promise<any>;
182
189
  downloadProfilePicture(this: Client, ...args: Parameters<typeof Utilities.downloadProfilePicture>): Promise<any>;
190
+ get(this: Client, ...args: Parameters<typeof Utilities.get>): Promise<any>;
191
+ post(this: Client, ...args: Parameters<typeof Utilities.post>): Promise<any>;
183
192
  run(this: Client, ...args: Parameters<typeof Utilities.run>): Promise<any>;
184
193
  start(this: Client, ...args: Parameters<typeof Utilities.start>): Promise<any>;
185
194
  }
@@ -675,29 +675,26 @@ class Methods {
675
675
  return Messages.requestSendFile.apply(this, args);
676
676
  });
677
677
  }
678
- // async sendDocument(
679
- // this: Client,
680
- // ...args: Parameters<typeof Messages.sendDocument>
681
- // ): Promise<any> {
682
- // return Messages.sendDocument.apply(this, args);
683
- // }
684
- // async sendGif(
685
- // this: Client,
686
- // ...args: Parameters<typeof Messages.sendGif>
687
- // ): Promise<any> {
688
- // return Messages.sendGif.apply(this, args);
689
- // }
678
+ sendDocument(...args) {
679
+ return __awaiter(this, void 0, void 0, function* () {
680
+ return Messages.sendDocument.apply(this, args);
681
+ });
682
+ }
683
+ sendGif(...args) {
684
+ return __awaiter(this, void 0, void 0, function* () {
685
+ return Messages.sendGif.apply(this, args);
686
+ });
687
+ }
690
688
  sendMessage(...args) {
691
689
  return __awaiter(this, void 0, void 0, function* () {
692
690
  return Messages.sendMessage.apply(this, args);
693
691
  });
694
692
  }
695
- // async sendMusic(
696
- // this: Client,
697
- // ...args: Parameters<typeof Messages.sendMusic>
698
- // ): Promise<any> {
699
- // return Messages.sendMusic.apply(this, args);
700
- // }
693
+ sendMusic(...args) {
694
+ return __awaiter(this, void 0, void 0, function* () {
695
+ return Messages.sendMusic.apply(this, args);
696
+ });
697
+ }
701
698
  sendPhoto(...args) {
702
699
  return __awaiter(this, void 0, void 0, function* () {
703
700
  return Messages.sendPhoto.apply(this, args);
@@ -709,24 +706,21 @@ class Methods {
709
706
  // ): Promise<any> {
710
707
  // return Messages.sendSticker.apply(this, args);
711
708
  // }
712
- // async sendVideo(
713
- // this: Client,
714
- // ...args: Parameters<typeof Messages.sendVideo>
715
- // ): Promise<any> {
716
- // return Messages.sendVideo.apply(this, args);
717
- // }
718
- // async sendVideoMessage(
719
- // this: Client,
720
- // ...args: Parameters<typeof Messages.sendVideoMessage>
721
- // ): Promise<any> {
722
- // return Messages.sendVideoMessage.apply(this, args);
723
- // }
724
- // async sendVoice(
725
- // this: Client,
726
- // ...args: Parameters<typeof Messages.sendVoice>
727
- // ): Promise<any> {
728
- // return Messages.sendVoice.apply(this, args);
729
- // }
709
+ sendVideo(...args) {
710
+ return __awaiter(this, void 0, void 0, function* () {
711
+ return Messages.sendVideo.apply(this, args);
712
+ });
713
+ }
714
+ sendVideoMessage(...args) {
715
+ return __awaiter(this, void 0, void 0, function* () {
716
+ return Messages.sendVideoMessage.apply(this, args);
717
+ });
718
+ }
719
+ sendVoice(...args) {
720
+ return __awaiter(this, void 0, void 0, function* () {
721
+ return Messages.sendVoice.apply(this, args);
722
+ });
723
+ }
730
724
  setPinMessage(...args) {
731
725
  return __awaiter(this, void 0, void 0, function* () {
732
726
  return Messages.setPinMessage.apply(this, args);
@@ -901,14 +895,26 @@ class Methods {
901
895
  });
902
896
  }
903
897
  // utilities
904
- // async download( this: Client, ...args: Parameters<typeof Utilities.download> ): Promise<any> {
905
- // return Utilities.download.apply(this, args);
906
- // }
898
+ download(...args) {
899
+ return __awaiter(this, void 0, void 0, function* () {
900
+ return Utilities.download.apply(this, args);
901
+ });
902
+ }
907
903
  downloadProfilePicture(...args) {
908
904
  return __awaiter(this, void 0, void 0, function* () {
909
905
  return Utilities.downloadProfilePicture.apply(this, args);
910
906
  });
911
907
  }
908
+ get(...args) {
909
+ return __awaiter(this, void 0, void 0, function* () {
910
+ return Utilities.get.apply(this, args);
911
+ });
912
+ }
913
+ post(...args) {
914
+ return __awaiter(this, void 0, void 0, function* () {
915
+ return Utilities.post.apply(this, args);
916
+ });
917
+ }
912
918
  run(...args) {
913
919
  return __awaiter(this, void 0, void 0, function* () {
914
920
  return Utilities.run.apply(this, args);
@@ -1,3 +1,3 @@
1
- import Client from '../..';
2
- declare function sendDocument(this: Client): Promise<any>;
1
+ import Client from "../..";
2
+ declare function sendDocument(this: Client, object_guid: string, document: string | Buffer<ArrayBufferLike>, caption?: string, reply_to_message_id?: string, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
3
3
  export default sendDocument;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function sendDocument() {
12
+ function sendDocument(object_guid, document, caption, reply_to_message_id, auto_delete) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- return yield this.builder('sendDocument', {});
14
+ return yield this.sendMessage(object_guid, caption, reply_to_message_id, document, "File", null, null, null, auto_delete);
15
15
  });
16
16
  }
17
17
  exports.default = sendDocument;
@@ -1,3 +1,3 @@
1
1
  import Client from '../..';
2
- declare function sendGif(this: Client): Promise<any>;
2
+ declare function sendGif(this: Client, object_guid: string, gif: string | Buffer<ArrayBufferLike>, caption?: string, reply_to_message_id?: string, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
3
3
  export default sendGif;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function sendGif() {
12
+ function sendGif(object_guid, gif, caption, reply_to_message_id, auto_delete) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- return yield this.builder('sendGif', {});
14
+ return yield this.sendMessage(object_guid, caption, reply_to_message_id, gif, "Gif", null, true, null, auto_delete);
15
15
  });
16
16
  }
17
17
  exports.default = sendGif;
@@ -54,16 +54,17 @@ function sendMessage(object_guid_1) {
54
54
  if (["me", "cloud", "self"].includes(object_guid.toLowerCase())) {
55
55
  object_guid = this.userGuid;
56
56
  }
57
+ let duration = 5000;
58
+ let file_uploaded;
59
+ let fileName = null;
60
+ let audio_data;
57
61
  let input = {
58
62
  object_guid,
59
- reply_to_message_id,
60
63
  rnd: Math.floor(Math.random() * 1e6 + 1),
64
+ reply_to_message_id,
61
65
  };
62
66
  if (text)
63
67
  input = Object.assign(Object.assign({}, input), parser_1.default.toMetadata(text));
64
- let file_uploaded;
65
- let fileName = null;
66
- let audio_data;
67
68
  if (file_inline) {
68
69
  if (typeof file_inline === "string") {
69
70
  fileName = file_inline;
@@ -78,19 +79,27 @@ function sendMessage(object_guid_1) {
78
79
  }
79
80
  if (file_inline && Buffer.isBuffer(file_inline)) {
80
81
  if (!fileName) {
81
- fileName = `file_${Date.now()}` + type === "Image" ? ".png" : ".mp4";
82
- yield fs.promises.writeFile(fileName, file_inline);
82
+ if (["Music", "Voice"].includes(type))
83
+ fileName = `file_${new Date().toDateString()}.mp3`;
84
+ else if (["Video", "Gif", "VideoMessage"].includes(type))
85
+ fileName = `file_${new Date().toDateString()}.mp4`;
86
+ else if (type === "Image")
87
+ fileName = `file_${new Date().toDateString()}.jpg`;
88
+ else
89
+ fileName = `file_${new Date().toDateString()}.zip`;
83
90
  }
84
91
  if (["Music", "Voice"].includes(type)) {
85
92
  thumb = false;
86
93
  if (audio_info) {
87
94
  audio_data = yield (0, music_metadata_1.parseBuffer)(file_inline);
95
+ duration = audio_data.format.duration || 5000;
88
96
  }
89
97
  }
90
98
  if (thumb) {
91
99
  try {
92
100
  if (["Video", "Gif", "VideoMessage"].includes(type)) {
93
101
  thumb = yield utilities_1.thumbnail.fromVideo(fileName);
102
+ duration = (yield utilities_1.thumbnail.getTime(fileName)) * 1000 || 5000;
94
103
  }
95
104
  else if (type === "Image") {
96
105
  thumb = yield utilities_1.thumbnail.fromImage(fileName);
@@ -102,25 +111,28 @@ function sendMessage(object_guid_1) {
102
111
  }
103
112
  }
104
113
  file_uploaded = yield this.network.uploadFile(fileName);
105
- // await fs.promises.unlink(fileName);
106
114
  if (type === "VideoMessage")
107
115
  file_uploaded["is_round"] = true;
108
116
  file_uploaded["type"] = type === "VideoMessage" ? "Video" : type;
109
- file_uploaded["is_spoil"] = is_spoil;
117
+ if (is_spoil)
118
+ file_uploaded["is_spoil"] = is_spoil;
110
119
  if (thumb) {
111
- file_uploaded["time"] = 0;
120
+ if (type !== "Image") {
121
+ file_uploaded["time"] = duration;
122
+ }
112
123
  file_uploaded["width"] = 320;
113
124
  file_uploaded["height"] = 320;
114
125
  file_uploaded["thumb_inline"] = thumb;
115
126
  }
116
127
  if (audio_info) {
117
- file_uploaded["music_performer"] = audio_data.common.title || "Unknown";
118
- file_uploaded["time"] = audio_data.format.duration || 0;
128
+ file_uploaded["music_performer"] = audio_data.common.title || "RubJS";
129
+ file_uploaded["time"] = audio_data.format.duration || 5000;
119
130
  }
120
131
  }
121
132
  if (file_inline) {
122
133
  input["file_inline"] = file_uploaded;
123
134
  }
135
+ console.log(input);
124
136
  const result = yield this.builder("sendMessage", input);
125
137
  if (auto_delete) {
126
138
  const res = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
@@ -1,3 +1,3 @@
1
- import Client from '../..';
2
- declare function sendMusic(this: Client): Promise<any>;
1
+ import Client from "../..";
2
+ declare function sendMusic(this: Client, object_guid: string, music: string | Buffer<ArrayBufferLike>, caption?: string, reply_to_message_id?: string, is_spoil?: boolean, audio_info?: boolean, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
3
3
  export default sendMusic;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function sendMusic() {
12
+ function sendMusic(object_guid, music, caption, reply_to_message_id, is_spoil, audio_info, auto_delete) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- return yield this.builder('sendMusic', {});
14
+ return yield this.sendMessage(object_guid, caption, reply_to_message_id, music, "Music", is_spoil, null, audio_info, auto_delete);
15
15
  });
16
16
  }
17
17
  exports.default = sendMusic;
@@ -1,3 +1,3 @@
1
1
  import Client from "../..";
2
- declare function sendPhoto(this: Client, object_guid: string, text: string, file_inline: Buffer<ArrayBufferLike> | string, reply_id?: string, is_spoil?: boolean, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
2
+ declare function sendPhoto(this: Client, object_guid: string, photo: Buffer<ArrayBufferLike> | string, text?: string, reply_id?: string, is_spoil?: boolean, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
3
3
  export default sendPhoto;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function sendPhoto(object_guid, text, file_inline, reply_id, is_spoil, auto_delete) {
12
+ function sendPhoto(object_guid, photo, text, reply_id, is_spoil, auto_delete) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- return this.sendMessage(object_guid, text, reply_id, file_inline, "Image", is_spoil, true, false, auto_delete);
14
+ return this.sendMessage(object_guid, text, reply_id, photo, "Image", is_spoil, true, false, auto_delete);
15
15
  });
16
16
  }
17
17
  exports.default = sendPhoto;
@@ -1,3 +1,3 @@
1
- import Client from '../..';
2
- declare function sendVideo(this: Client): Promise<any>;
1
+ import Client from "../..";
2
+ declare function sendVideo(this: Client, object_guid: string, video: string | Buffer<ArrayBufferLike>, caption?: string, reply_to_message_id?: string, is_spoil?: boolean, thumb?: string | boolean, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
3
3
  export default sendVideo;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function sendVideo() {
12
+ function sendVideo(object_guid, video, caption, reply_to_message_id, is_spoil, thumb, auto_delete) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- return yield this.builder('sendVideo', {});
14
+ return yield this.sendMessage(object_guid, caption, reply_to_message_id, video, "Video", is_spoil, thumb, null, auto_delete);
15
15
  });
16
16
  }
17
17
  exports.default = sendVideo;
@@ -1,3 +1,3 @@
1
- import Client from '../..';
2
- declare function sendVideoMessage(this: Client): Promise<any>;
1
+ import Client from "../..";
2
+ declare function sendVideoMessage(this: Client, object_guid: string, video: string | Buffer<ArrayBufferLike>, reply_to_message_id?: string, is_spoil?: boolean, thumb?: string | boolean, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
3
3
  export default sendVideoMessage;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function sendVideoMessage() {
12
+ function sendVideoMessage(object_guid, video, reply_to_message_id, is_spoil, thumb, auto_delete) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- return yield this.builder('sendVideoMessage', {});
14
+ return yield this.sendMessage(object_guid, null, reply_to_message_id, video, "VideoMessage", is_spoil, thumb, null, auto_delete);
15
15
  });
16
16
  }
17
17
  exports.default = sendVideoMessage;
@@ -1,3 +1,3 @@
1
- import Client from '../..';
2
- declare function sendVoice(this: Client): Promise<any>;
1
+ import Client from "../..";
2
+ declare function sendVoice(this: Client, object_guid: string, voice: string | Buffer<ArrayBufferLike>, caption?: string, reply_to_message_id?: string, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
3
3
  export default sendVoice;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function sendVoice() {
12
+ function sendVoice(object_guid, voice, caption, reply_to_message_id, auto_delete) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
- return yield this.builder('sendVoice', {});
14
+ return yield this.sendMessage(object_guid, caption, reply_to_message_id, voice, "Voice", null, null, null, auto_delete);
15
15
  });
16
16
  }
17
17
  exports.default = sendVoice;
@@ -1,3 +1,4 @@
1
- import Client from '../..';
2
- declare function download(this: Client): Promise<any>;
1
+ import Client from "../..";
2
+ import { FileInline } from "../../types/decorators";
3
+ declare function download(this: Client, file_inline: FileInline, callback?: (totalSize: number, downloadedSize: number) => Promise<void>, speed?: boolean): Promise<Buffer<ArrayBufferLike>>;
3
4
  export default download;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function download() {
13
- return __awaiter(this, void 0, void 0, function* () {
14
- return yield this.builder('download', {});
12
+ function download(file_inline_1, callback_1) {
13
+ return __awaiter(this, arguments, void 0, function* (file_inline, callback, speed = false) {
14
+ return yield this.network.download(file_inline.dc_id, file_inline.file_id, file_inline.access_hash_rec, file_inline.size, 1054768, callback, speed);
15
15
  });
16
16
  }
17
17
  exports.default = download;
@@ -0,0 +1,4 @@
1
+ import { AxiosRequestConfig } from "axios";
2
+ import Client from "../..";
3
+ declare function get(this: Client, url: string, config: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
4
+ export default get;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const axios_1 = __importDefault(require("axios"));
16
+ function get(url, config) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ return yield axios_1.default.get(url, config);
19
+ });
20
+ }
21
+ exports.default = get;
@@ -1,6 +1,8 @@
1
1
  import download from "./download";
2
2
  import downloadProfilePicture from "./downloadProfilePicture";
3
+ import get from "./get";
4
+ import post from "./post";
3
5
  import run from "./run";
4
6
  import start from "./start";
5
7
  import thumbnail from "./thumbnail";
6
- export { download, downloadProfilePicture, run, start, thumbnail };
8
+ export { download, downloadProfilePicture, run, start, thumbnail, get, post };
@@ -3,11 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.thumbnail = exports.start = exports.run = exports.downloadProfilePicture = exports.download = void 0;
6
+ exports.post = exports.get = exports.thumbnail = exports.start = exports.run = exports.downloadProfilePicture = exports.download = void 0;
7
7
  const download_1 = __importDefault(require("./download"));
8
8
  exports.download = download_1.default;
9
9
  const downloadProfilePicture_1 = __importDefault(require("./downloadProfilePicture"));
10
10
  exports.downloadProfilePicture = downloadProfilePicture_1.default;
11
+ const get_1 = __importDefault(require("./get"));
12
+ exports.get = get_1.default;
13
+ const post_1 = __importDefault(require("./post"));
14
+ exports.post = post_1.default;
11
15
  const run_1 = __importDefault(require("./run"));
12
16
  exports.run = run_1.default;
13
17
  const start_1 = __importDefault(require("./start"));
@@ -0,0 +1,4 @@
1
+ import { AxiosRequestConfig } from "axios";
2
+ import Client from "../..";
3
+ declare function post(this: Client, url: string, data: any, config: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
4
+ export default post;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const axios_1 = __importDefault(require("axios"));
16
+ function post(url, data, config) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ return yield axios_1.default.post(url, data, config);
19
+ });
20
+ }
21
+ exports.default = post;
@@ -1,4 +1,5 @@
1
1
  declare class ThumbnailGenerator {
2
+ static getTime(videoPath: string): Promise<number>;
2
3
  static fromVideo(videoPath: string): Promise<string>;
3
4
  static fromImage(imagePath: string, width?: number): Promise<string>;
4
5
  }
@@ -18,6 +18,20 @@ const path_1 = __importDefault(require("path"));
18
18
  const os_1 = __importDefault(require("os"));
19
19
  const sharp_1 = __importDefault(require("sharp"));
20
20
  class ThumbnailGenerator {
21
+ static getTime(videoPath) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return new Promise((resolve, reject) => {
24
+ fluent_ffmpeg_1.default.ffprobe(videoPath, (err, metadata) => {
25
+ if (err) {
26
+ console.error("Error fetching metadata:", err);
27
+ reject(err);
28
+ return;
29
+ }
30
+ resolve(metadata.format.duration);
31
+ });
32
+ });
33
+ });
34
+ }
21
35
  static fromVideo(videoPath) {
22
36
  return __awaiter(this, void 0, void 0, function* () {
23
37
  const tempImagePath = path_1.default.join(os_1.default.tmpdir(), `thumbnail_${Date.now()}.png`);
@@ -31,7 +45,7 @@ class ThumbnailGenerator {
31
45
  timemarks: ["00:00:00.000"],
32
46
  filename: path_1.default.basename(tempImagePath),
33
47
  folder: path_1.default.dirname(tempImagePath),
34
- size: "320x?",
48
+ size: "400x?",
35
49
  });
36
50
  });
37
51
  const thumbnailBuffer = yield promises_1.default.readFile(tempImagePath);
@@ -33,5 +33,6 @@ declare class Network {
33
33
  file_name: string;
34
34
  access_hash_rec: string;
35
35
  }>;
36
+ download(dc_id: number, file_id: number, access_hash: string, size: number, chunk?: number, callback?: (totalSize: number, downloadedSize: number) => Promise<void>, speed?: boolean): Promise<Buffer>;
36
37
  }
37
38
  export default Network;
@@ -63,12 +63,10 @@ class Network {
63
63
  };
64
64
  this.client = client;
65
65
  this.Headers["user-agent"] = this.client.userAgent;
66
- if (this.client.defaultPlatform["platform"] === "Android") {
67
- delete this.Headers["origin"];
68
- delete this.Headers["referer"];
66
+ if (this.client.defaultPlatform.platform === "Android") {
67
+ delete this.Headers.origin;
68
+ delete this.Headers.referer;
69
69
  this.Headers["user-agent"] = "okhttp/3.12.1";
70
- this.client.defaultPlatform["package"] = "app.rbmain.a";
71
- this.client.defaultPlatform["app_version"] = "3.6.4";
72
70
  }
73
71
  this.agent = new https_1.default.Agent({ rejectUnauthorized: false });
74
72
  const axiosConfig = {
@@ -95,8 +93,8 @@ class Network {
95
93
  return true;
96
94
  }
97
95
  }
98
- catch (error) {
99
- console.error("Error while fetching dcs:", error);
96
+ catch (_a) {
97
+ console.error("Error while fetching dcs");
100
98
  continue;
101
99
  }
102
100
  }
@@ -112,7 +110,7 @@ class Network {
112
110
  }
113
111
  }
114
112
  catch (error) {
115
- console.error("Error in request:", error);
113
+ console.error("Error in request ");
116
114
  continue;
117
115
  }
118
116
  }
@@ -207,6 +205,7 @@ class Network {
207
205
  }
208
206
  uploadFile(file_1) {
209
207
  return __awaiter(this, arguments, void 0, function* (file, mime = null, fileName = null, chunk = 1048576, callback = null) {
208
+ var _a;
210
209
  if (typeof file === "string") {
211
210
  if (!fs.existsSync(file))
212
211
  throw new Error("File not found in the given path");
@@ -219,7 +218,7 @@ class Network {
219
218
  if (!fileName)
220
219
  throw new Error("File name is not set");
221
220
  if (!mime)
222
- mime = fileName.split(".").pop() || "";
221
+ mime = fileName.split(".").pop() || "application/octet-stream";
223
222
  let result = yield this.client.requestSendFile(fileName, file.length, mime);
224
223
  let response;
225
224
  let id = result.id;
@@ -267,6 +266,8 @@ class Network {
267
266
  yield new Promise((resolve) => setTimeout(resolve, 5000));
268
267
  }
269
268
  if (response.data.status === "OK" && response.data.status_det === "OK") {
269
+ if (!((_a = response.data.data) === null || _a === void 0 ? void 0 : _a.access_hash_rec))
270
+ throw new Error("Error in upload file!!");
270
271
  return {
271
272
  mime,
272
273
  size: file.length,
@@ -280,5 +281,58 @@ class Network {
280
281
  }
281
282
  });
282
283
  }
284
+ download(dc_id_1, file_id_1, access_hash_1, size_1) {
285
+ return __awaiter(this, arguments, void 0, function* (dc_id, file_id, access_hash, size, chunk = 131072, callback, speed = false) {
286
+ const headers = {
287
+ auth: this.client.auth,
288
+ "access-hash-rec": access_hash,
289
+ "file-id": String(file_id),
290
+ "user-agent": this.client.userAgent,
291
+ };
292
+ const base_url = `https://messenger${dc_id}.iranlms.ir`;
293
+ const fetchChunk = (start_index, last_index) => __awaiter(this, void 0, void 0, function* () {
294
+ const chunk_headers = Object.assign(Object.assign({}, headers), { "start-index": String(start_index), "last-index": String(last_index) });
295
+ try {
296
+ const config = {
297
+ headers: chunk_headers,
298
+ };
299
+ const response = yield axios_1.default.post(`${base_url}/GetFile.ashx`, {}, config);
300
+ return Buffer.from(response.data);
301
+ }
302
+ catch (e) {
303
+ return Buffer.alloc(0);
304
+ }
305
+ });
306
+ if (speed) {
307
+ const tasks = [];
308
+ for (let start_index = 0; start_index < size; start_index += chunk) {
309
+ const last_index = Math.min(start_index + chunk, size) - 1;
310
+ tasks.push(fetchChunk(start_index, last_index));
311
+ }
312
+ const resultChunks = yield Promise.all(tasks);
313
+ const result = Buffer.concat(resultChunks);
314
+ if (callback) {
315
+ yield callback(size, result.length);
316
+ }
317
+ return result;
318
+ }
319
+ else {
320
+ let result = Buffer.alloc(0);
321
+ let start_index = 0;
322
+ while (start_index < size) {
323
+ const last_index = Math.min(start_index + chunk, size) - 1;
324
+ const data = yield fetchChunk(start_index, last_index);
325
+ if (data.length === 0)
326
+ break;
327
+ result = Buffer.concat([result, data]);
328
+ start_index = last_index + 1;
329
+ if (callback) {
330
+ yield callback(size, result.length);
331
+ }
332
+ }
333
+ return result;
334
+ }
335
+ });
336
+ }
283
337
  }
284
338
  exports.default = Network;
@@ -92,10 +92,12 @@ class Markdown {
92
92
  if (!entities.length) {
93
93
  resultText = resultText.trim();
94
94
  }
95
- return {
95
+ let returnData = {
96
96
  text: resultText,
97
- metadata: { meta_data_parts: entities },
98
97
  };
98
+ if (entities.length > 0)
99
+ returnData.metadata = { meta_data_parts: entities };
100
+ return returnData;
99
101
  }
100
102
  }
101
103
  Markdown.markdownRegExp = /(^|\s|\n)(````?)([\s\S]+?)(````?)([\s\n\.,:?!;]|$)|(^|\s)(`|\*\*|__|~~|--|\|\|)([^\n]+?)\7([\s\.,:?!;]|$)|@([a-zA-Z0-9]+)\s*\((.+?)\)|\[(.+?)\]\((.+?)\)/m;
@@ -12,7 +12,14 @@ declare class Message implements MessageUpdate {
12
12
  state: string;
13
13
  client: Client;
14
14
  constructor(client: Client, update: MessageUpdate);
15
- log(): void;
16
- reply(text: string, object_guid?: string, message_id?: string): Promise<import("./messages").SendMessageResult>;
15
+ reply(text?: string, object_guid?: string, message_id?: string, auto_delete?: number, file_inline?: string | Buffer<ArrayBufferLike>, type?: string, is_spoil?: boolean, thumb?: string, audio_info?: boolean): Promise<import("./messages").SendMessageResult>;
16
+ pin(object_guid?: string, message_id?: string, action?: "Pin" | "Unpin"): Promise<import("./messages").SetPinMessage>;
17
+ reply_photo(photo: string | Buffer<ArrayBufferLike>, caption?: string, object_guid?: string, auto_delete?: number, reply_to_message_id?: string, is_spoil?: boolean, thumb?: string): Promise<import("./messages").SendMessageResult>;
18
+ forward(to_object_guid: string): Promise<import("./messages").ForwardMessages>;
19
+ delete(): Promise<import("./messages").DeleteMessage>;
20
+ reaction(reaction_id: number, object_guid?: string, message_id?: string, action?: "Add" | "Remove"): Promise<{
21
+ reactions: import("./messages").Reaction[];
22
+ }>;
23
+ getReplyMessage(object_guid?: string, message_id?: string): Promise<import("./messages").Message>;
17
24
  }
18
25
  export default Message;
@@ -19,12 +19,42 @@ class Message {
19
19
  configurable: true,
20
20
  });
21
21
  }
22
- log() {
23
- console.log(Object.assign({}, this));
22
+ reply(text, object_guid, message_id, auto_delete, file_inline, type, is_spoil, thumb, audio_info) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ return yield this.client.sendMessage(object_guid || this.object_guid, text, message_id || this.message_id, file_inline, type, is_spoil, thumb, audio_info, auto_delete);
25
+ });
26
+ }
27
+ pin(object_guid_1, message_id_1) {
28
+ return __awaiter(this, arguments, void 0, function* (object_guid, message_id, action = "Pin") {
29
+ return yield this.client.setPinMessage(object_guid || this.object_guid, message_id || this.message_id, action);
30
+ });
31
+ }
32
+ reply_photo(photo, caption, object_guid, auto_delete, reply_to_message_id, is_spoil, thumb) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return yield this.reply(caption, object_guid, reply_to_message_id, auto_delete, photo, "Image", is_spoil, thumb);
35
+ });
36
+ }
37
+ forward(to_object_guid) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return yield this.client.forwardMessages(this.object_guid, to_object_guid, [
40
+ this.message_id,
41
+ ]);
42
+ });
43
+ }
44
+ delete() {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return yield this.client.deleteMessages(this.object_guid, [this.message_id]);
47
+ });
48
+ }
49
+ reaction(reaction_id_1, object_guid_1, message_id_1) {
50
+ return __awaiter(this, arguments, void 0, function* (reaction_id, object_guid, message_id, action = "Add") {
51
+ return yield this.client.actionOnMessageReaction(object_guid || this.object_guid, message_id || this.message_id, reaction_id, action);
52
+ });
24
53
  }
25
- reply(text, object_guid, message_id) {
54
+ getReplyMessage(object_guid, message_id) {
26
55
  return __awaiter(this, void 0, void 0, function* () {
27
- return this.client.sendMessage(object_guid || this.object_guid, text, message_id || this.message_id);
56
+ const result = yield this.client.getMessagesByID(object_guid || this.object_guid, message_id || [this.message_id]);
57
+ return result.messages[0];
28
58
  });
29
59
  }
30
60
  }