rubika 1.2.1 → 1.2.4

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 (77) hide show
  1. package/bot/bot.ts +34 -28
  2. package/bot/contexts/inline.ts +15 -14
  3. package/bot/contexts/update.ts +20 -21
  4. package/bot/filters.ts +32 -30
  5. package/bot/index.ts +4 -2
  6. package/bot/methods/advanced/builder.ts +8 -13
  7. package/bot/methods/files/_sendFile.ts +5 -2
  8. package/bot/methods/files/uploadFile.ts +5 -2
  9. package/bot/methods/index.ts +10 -10
  10. package/bot/methods/messages/deleteMessage.ts +6 -10
  11. package/bot/methods/messages/sendContact.ts +5 -3
  12. package/bot/methods/messages/sendFile.ts +1 -1
  13. package/bot/methods/messages/sendGif.ts +23 -23
  14. package/bot/methods/messages/sendImage.ts +23 -23
  15. package/bot/methods/messages/sendLocation.ts +6 -3
  16. package/bot/methods/messages/sendMessage.ts +6 -2
  17. package/bot/methods/messages/sendMusic.ts +23 -23
  18. package/bot/methods/messages/sendPoll.ts +6 -3
  19. package/bot/methods/messages/sendSticker.ts +8 -4
  20. package/bot/methods/messages/sendVideo.ts +23 -23
  21. package/bot/methods/messages/sendVoice.ts +23 -23
  22. package/bot/methods/utilities/getUpdates.ts +1 -1
  23. package/bot/methods/utilities/handleUpdates.ts +14 -14
  24. package/bot/methods/utilities/polling.ts +57 -32
  25. package/bot/methods/utilities/run.ts +2 -2
  26. package/bot/methods/utilities/start.ts +5 -2
  27. package/bot/methods/utilities/webhook.ts +4 -3
  28. package/bot/network.ts +43 -15
  29. package/bot/types/handlers.ts +3 -3
  30. package/bot/types/interfaces.ts +44 -4
  31. package/bot/types/utils.ts +6 -1
  32. package/bot/utils/antiSpam.ts +1 -1
  33. package/client/client.ts +35 -33
  34. package/client/contexts/activities.type.ts +2 -2
  35. package/client/contexts/chat.type.ts +2 -2
  36. package/client/contexts/message.type.ts +10 -3
  37. package/client/contexts/notifications.type.ts +2 -2
  38. package/client/crypto.ts +2 -2
  39. package/client/filters.ts +31 -31
  40. package/client/index.ts +5 -1
  41. package/client/methods/advanced/builder.ts +3 -1
  42. package/client/methods/auth/registerDevice.ts +8 -6
  43. package/client/methods/channels/addChannel.ts +1 -1
  44. package/client/methods/channels/editChannelInfo.ts +3 -3
  45. package/client/methods/channels/setChannelVoiceChatSetting.ts +1 -1
  46. package/client/methods/chats/editJoinLink.ts +1 -1
  47. package/client/methods/chats/seenChats.ts +1 -1
  48. package/client/methods/extras/deleteMessagebyCount.ts +40 -38
  49. package/client/methods/extras/onEditMessages.ts +1 -1
  50. package/client/methods/extras/userIsAdmin.ts +2 -2
  51. package/client/methods/groups/editGroupInfo.ts +13 -1
  52. package/client/methods/groups/setGroupVoiceChatSetting.ts +1 -1
  53. package/client/methods/messages/sendDocument.ts +3 -2
  54. package/client/methods/messages/sendFileInline.ts +1 -1
  55. package/client/methods/messages/sendGif.ts +4 -3
  56. package/client/methods/messages/sendMessage.ts +8 -6
  57. package/client/methods/messages/sendMessageAPICall.ts +18 -0
  58. package/client/methods/messages/sendMusic.ts +3 -2
  59. package/client/methods/messages/sendPhoto.ts +3 -2
  60. package/client/methods/messages/sendText.ts +4 -2
  61. package/client/methods/messages/sendVideo.ts +3 -2
  62. package/client/methods/messages/sendVideoMessage.ts +3 -2
  63. package/client/methods/messages/sendVoice.ts +3 -2
  64. package/client/methods/settings/updateProfile.ts +1 -1
  65. package/client/methods/utilities/start.ts +7 -4
  66. package/client/network/api.ts +1 -1
  67. package/client/network/file.ts +13 -7
  68. package/client/network/websocket.ts +32 -15
  69. package/client/types/client.type.ts +10 -10
  70. package/client/utils/session.ts +1 -1
  71. package/index.ts +1 -0
  72. package/package.json +1 -7
  73. package/utils/formater.ts +1 -1
  74. package/utils/index.ts +2 -1
  75. package/utils/logger.ts +28 -0
  76. package/utils/parser.ts +120 -156
  77. package/utils/errors.ts +0 -26
@@ -39,7 +39,7 @@ export default class Methods {
39
39
  async requestSendFile(
40
40
  this: Bot,
41
41
  ...args: Parameters<typeof Files.requestSendFile>
42
- ): Promise<{ upload_url: string }> {
42
+ ): Promise<Types.REQUEST_SEND_FILE> {
43
43
  return Files.requestSendFile.apply(this, args);
44
44
  }
45
45
 
@@ -209,35 +209,35 @@ export default class Methods {
209
209
  async start(
210
210
  this: Bot,
211
211
  ...args: Parameters<typeof Utilities.start>
212
- ): Promise<any> {
212
+ ): Promise<unknown> {
213
213
  return Utilities.start.apply(this, args);
214
214
  }
215
215
 
216
216
  async run(
217
217
  this: Bot,
218
218
  ...args: Parameters<typeof Utilities.run>
219
- ): Promise<any> {
219
+ ): Promise<unknown> {
220
220
  return Utilities.run.apply(this, args);
221
221
  }
222
222
 
223
223
  async getUpdates(
224
224
  this: Bot,
225
225
  ...args: Parameters<typeof Utilities.getUpdates>
226
- ): Promise<any> {
226
+ ): Promise<Types.GetUpdates> {
227
227
  return Utilities.getUpdates.apply(this, args);
228
228
  }
229
229
 
230
- async __setupWebhook(
230
+ async setupWebhook(
231
231
  this: Bot,
232
232
  ...args: Parameters<typeof Utilities.setupWebhook>
233
- ): Promise<any> {
233
+ ): Promise<unknown> {
234
234
  return Utilities.setupWebhook.apply(this, args);
235
235
  }
236
236
 
237
- async __polling(
237
+ async polling(
238
238
  this: Bot,
239
239
  ...args: Parameters<typeof Utilities.polling>
240
- ): Promise<any> {
240
+ ): Promise<unknown> {
241
241
  return Utilities.polling.apply(this, args);
242
242
  }
243
243
 
@@ -245,14 +245,14 @@ export default class Methods {
245
245
  async setCommands(
246
246
  this: Bot,
247
247
  ...args: Parameters<typeof Settings.setCommands>
248
- ): Promise<any> {
248
+ ): Promise<unknown> {
249
249
  return Settings.setCommands.apply(this, args);
250
250
  }
251
251
 
252
252
  async updateBotEndpoints(
253
253
  this: Bot,
254
254
  ...args: Parameters<typeof Settings.updateBotEndpoints>
255
- ): Promise<any> {
255
+ ): Promise<Types.UpdateBotEndpoints> {
256
256
  return Settings.updateBotEndpoints.apply(this, args);
257
257
  }
258
258
  }
@@ -1,14 +1,10 @@
1
- import Bot from '../..';
1
+ import Bot from "../..";
2
2
 
3
- async function deleteMessage(
4
- this: Bot,
5
- chat_id: string,
6
- message_id: string,
7
- ) {
8
- return await this.builder('deleteMessage', {
9
- chat_id,
10
- message_id,
11
- });
3
+ async function deleteMessage(this: Bot, chat_id: string, message_id: string) {
4
+ return await this.builder("deleteMessage", {
5
+ chat_id,
6
+ message_id,
7
+ });
12
8
  }
13
9
 
14
10
  export default deleteMessage;
@@ -13,7 +13,7 @@ async function sendContact(
13
13
  disable_notification = false,
14
14
  reply_to_message_id?: string,
15
15
  chat_keypad_type?: ChatKeypadTypeEnum,
16
- auto_delete: number | boolean = false,
16
+ auto_delete: number | false = false,
17
17
  ) {
18
18
  const data = {
19
19
  chat_id,
@@ -37,8 +37,10 @@ async function sendContact(
37
37
 
38
38
  const res = await this.builder("sendContact", data);
39
39
 
40
- if (auto_delete !== false) await this.deleteMessage(chat_id, res.message_id);
41
-
40
+ if (auto_delete !== false)
41
+ setTimeout(async () => {
42
+ await this.deleteMessage(chat_id, res.message_id);
43
+ }, auto_delete);
42
44
  return res;
43
45
  }
44
46
 
@@ -13,7 +13,7 @@ async function sendFile(
13
13
  disable_notification = false,
14
14
  reply_to_message_id?: string,
15
15
  chat_keypad_type?: ChatKeypadTypeEnum,
16
- auto_delete: number | boolean = false,
16
+ auto_delete: number | false = false,
17
17
  ) {
18
18
  return await this._sendFile(
19
19
  chat_id,
@@ -1,32 +1,32 @@
1
- import Bot from '../..';
1
+ import Bot from "../..";
2
2
  import { InlineKeypad, Keypad } from "../../types/interfaces";
3
3
  import { ChatKeypadTypeEnum, FileTypeEnum } from "../../types/enums";
4
4
  import { FileSource } from "../../types/methods";
5
5
 
6
6
  async function sendGif(
7
- this: Bot,
8
- chat_id: string,
9
- file: FileSource,
10
- text?: string,
11
- chat_keypad?: Keypad,
12
- inline_keypad?: InlineKeypad,
13
- disable_notification = false,
14
- reply_to_message_id?: string,
15
- chat_keypad_type?: ChatKeypadTypeEnum,
16
- auto_delete: number | boolean = false,
7
+ this: Bot,
8
+ chat_id: string,
9
+ file: FileSource,
10
+ text?: string,
11
+ chat_keypad?: Keypad,
12
+ inline_keypad?: InlineKeypad,
13
+ disable_notification = false,
14
+ reply_to_message_id?: string,
15
+ chat_keypad_type?: ChatKeypadTypeEnum,
16
+ auto_delete: number | false = false,
17
17
  ) {
18
- return await this._sendFile(
19
- chat_id,
20
- file,
21
- text,
22
- FileTypeEnum.Gif,
23
- chat_keypad,
24
- inline_keypad,
25
- disable_notification,
26
- reply_to_message_id,
27
- chat_keypad_type,
28
- auto_delete
29
- );
18
+ return await this._sendFile(
19
+ chat_id,
20
+ file,
21
+ text,
22
+ FileTypeEnum.Gif,
23
+ chat_keypad,
24
+ inline_keypad,
25
+ disable_notification,
26
+ reply_to_message_id,
27
+ chat_keypad_type,
28
+ auto_delete,
29
+ );
30
30
  }
31
31
 
32
32
  export default sendGif;
@@ -1,32 +1,32 @@
1
- import Bot from '../..';
1
+ import Bot from "../..";
2
2
  import { InlineKeypad, Keypad } from "../../types/interfaces";
3
3
  import { ChatKeypadTypeEnum, FileTypeEnum } from "../../types/enums";
4
4
  import { FileSource } from "../../types/methods";
5
5
 
6
6
  async function sendImage(
7
- this: Bot,
8
- chat_id: string,
9
- file: FileSource,
10
- text?: string,
11
- chat_keypad?: Keypad,
12
- inline_keypad?: InlineKeypad,
13
- disable_notification = false,
14
- reply_to_message_id?: string,
15
- chat_keypad_type?: ChatKeypadTypeEnum,
16
- auto_delete: number | boolean = false,
7
+ this: Bot,
8
+ chat_id: string,
9
+ file: FileSource,
10
+ text?: string,
11
+ chat_keypad?: Keypad,
12
+ inline_keypad?: InlineKeypad,
13
+ disable_notification = false,
14
+ reply_to_message_id?: string,
15
+ chat_keypad_type?: ChatKeypadTypeEnum,
16
+ auto_delete: number | false = false,
17
17
  ) {
18
- return await this._sendFile(
19
- chat_id,
20
- file,
21
- text,
22
- FileTypeEnum.Image,
23
- chat_keypad,
24
- inline_keypad,
25
- disable_notification,
26
- reply_to_message_id,
27
- chat_keypad_type,
28
- auto_delete
29
- );
18
+ return await this._sendFile(
19
+ chat_id,
20
+ file,
21
+ text,
22
+ FileTypeEnum.Image,
23
+ chat_keypad,
24
+ inline_keypad,
25
+ disable_notification,
26
+ reply_to_message_id,
27
+ chat_keypad_type,
28
+ auto_delete,
29
+ );
30
30
  }
31
31
 
32
32
  export default sendImage;
@@ -12,7 +12,7 @@ async function sendLocation(
12
12
  disable_notification = false,
13
13
  reply_to_message_id?: string,
14
14
  chat_keypad_type?: ChatKeypadTypeEnum,
15
- auto_delete: number | boolean = false,
15
+ auto_delete: number | false = false,
16
16
  ) {
17
17
  const data = {
18
18
  chat_id,
@@ -32,10 +32,13 @@ async function sendLocation(
32
32
  if (inline_keypad && chat_keypad_type) {
33
33
  data.chat_keypad_type = ChatKeypadTypeEnum.None;
34
34
  }
35
-
35
+
36
36
  const res = await this.builder("sendLocation", data);
37
37
 
38
- if (auto_delete !== false) await this.deleteMessage(chat_id, res.message_id);
38
+ if (auto_delete !== false)
39
+ setTimeout(async () => {
40
+ await this.deleteMessage(chat_id, res.message_id);
41
+ }, auto_delete);
39
42
 
40
43
  return res;
41
44
  }
@@ -13,7 +13,7 @@ async function sendMessage(
13
13
  disable_notification = false,
14
14
  reply_to_message_id?: string,
15
15
  chat_keypad_type?: ChatKeypadTypeEnum,
16
- auto_delete: number | boolean = false,
16
+ auto_delete: number | false = false,
17
17
  ) {
18
18
  let data: SendType = {
19
19
  chat_id,
@@ -36,7 +36,11 @@ async function sendMessage(
36
36
 
37
37
  const res = await this.builder("sendMessage", data);
38
38
 
39
- if (auto_delete !== false) await this.deleteMessage(chat_id, res.message_id);
39
+ if (auto_delete !== false) {
40
+ setTimeout(async () => {
41
+ await this.deleteMessage(chat_id, res.message_id);
42
+ }, auto_delete);
43
+ }
40
44
 
41
45
  return res;
42
46
  }
@@ -1,32 +1,32 @@
1
- import Bot from '../..';
1
+ import Bot from "../..";
2
2
  import { InlineKeypad, Keypad } from "../../types/interfaces";
3
3
  import { ChatKeypadTypeEnum, FileTypeEnum } from "../../types/enums";
4
4
  import { FileSource } from "../../types/methods";
5
5
 
6
6
  async function sendMusic(
7
- this: Bot,
8
- chat_id: string,
9
- file: FileSource,
10
- text?: string,
11
- chat_keypad?: Keypad,
12
- inline_keypad?: InlineKeypad,
13
- disable_notification = false,
14
- reply_to_message_id?: string,
15
- chat_keypad_type?: ChatKeypadTypeEnum,
16
- auto_delete: number | boolean = false,
7
+ this: Bot,
8
+ chat_id: string,
9
+ file: FileSource,
10
+ text?: string,
11
+ chat_keypad?: Keypad,
12
+ inline_keypad?: InlineKeypad,
13
+ disable_notification = false,
14
+ reply_to_message_id?: string,
15
+ chat_keypad_type?: ChatKeypadTypeEnum,
16
+ auto_delete: number | false = false,
17
17
  ) {
18
- return await this._sendFile(
19
- chat_id,
20
- file,
21
- text,
22
- FileTypeEnum.Music,
23
- chat_keypad,
24
- inline_keypad,
25
- disable_notification,
26
- reply_to_message_id,
27
- chat_keypad_type,
28
- auto_delete
29
- );
18
+ return await this._sendFile(
19
+ chat_id,
20
+ file,
21
+ text,
22
+ FileTypeEnum.Music,
23
+ chat_keypad,
24
+ inline_keypad,
25
+ disable_notification,
26
+ reply_to_message_id,
27
+ chat_keypad_type,
28
+ auto_delete,
29
+ );
30
30
  }
31
31
 
32
32
  export default sendMusic;
@@ -5,12 +5,15 @@ async function sendPoll(
5
5
  chat_id: string,
6
6
  question: string,
7
7
  options: string[],
8
- auto_delete: number | boolean = false,
8
+ auto_delete: number | false = false,
9
9
  ) {
10
10
  const res = await this.builder("sendPoll", { chat_id, question, options });
11
11
 
12
- if (auto_delete !== false) await this.deleteMessage(chat_id, res.message_id);
13
-
12
+ if (auto_delete !== false)
13
+ setTimeout(async () => {
14
+ await this.deleteMessage(chat_id, res.message_id);
15
+ }, auto_delete);
16
+
14
17
  return res;
15
18
  }
16
19
 
@@ -12,9 +12,9 @@ async function sendSticker(
12
12
  disable_notification = false,
13
13
  reply_to_message_id?: string,
14
14
  chat_keypad_type?: ChatKeypadTypeEnum,
15
- auto_delete: number | boolean = false,
15
+ auto_delete: number | false = false,
16
16
  ) {
17
- let data: SendType = {
17
+ const data: SendType = {
18
18
  chat_id,
19
19
  sticker_id,
20
20
  disable_notification,
@@ -34,8 +34,12 @@ async function sendSticker(
34
34
  }
35
35
 
36
36
  const res = await this.builder("sendSticker", data);
37
- if (auto_delete !== false) await this.deleteMessage(chat_id, res.message_id);
38
-
37
+
38
+ if (auto_delete !== false)
39
+ setTimeout(async () => {
40
+ await this.deleteMessage(chat_id, res.message_id);
41
+ }, auto_delete);
42
+
39
43
  return res;
40
44
  }
41
45
 
@@ -1,32 +1,32 @@
1
- import Bot from '../..';
1
+ import Bot from "../..";
2
2
  import { InlineKeypad, Keypad } from "../../types/interfaces";
3
3
  import { ChatKeypadTypeEnum, FileTypeEnum } from "../../types/enums";
4
4
  import { FileSource } from "../../types/methods";
5
5
 
6
6
  async function sendVideo(
7
- this: Bot,
8
- chat_id: string,
9
- file: FileSource,
10
- text?: string,
11
- chat_keypad?: Keypad,
12
- inline_keypad?: InlineKeypad,
13
- disable_notification = false,
14
- reply_to_message_id?: string,
15
- chat_keypad_type?: ChatKeypadTypeEnum,
16
- auto_delete: number | boolean = false,
7
+ this: Bot,
8
+ chat_id: string,
9
+ file: FileSource,
10
+ text?: string,
11
+ chat_keypad?: Keypad,
12
+ inline_keypad?: InlineKeypad,
13
+ disable_notification = false,
14
+ reply_to_message_id?: string,
15
+ chat_keypad_type?: ChatKeypadTypeEnum,
16
+ auto_delete: number | false = false,
17
17
  ) {
18
- return await this._sendFile(
19
- chat_id,
20
- file,
21
- text,
22
- FileTypeEnum.Video,
23
- chat_keypad,
24
- inline_keypad,
25
- disable_notification,
26
- reply_to_message_id,
27
- chat_keypad_type,
28
- auto_delete
29
- );
18
+ return await this._sendFile(
19
+ chat_id,
20
+ file,
21
+ text,
22
+ FileTypeEnum.Video,
23
+ chat_keypad,
24
+ inline_keypad,
25
+ disable_notification,
26
+ reply_to_message_id,
27
+ chat_keypad_type,
28
+ auto_delete,
29
+ );
30
30
  }
31
31
 
32
32
  export default sendVideo;
@@ -1,32 +1,32 @@
1
- import Bot from '../..';
1
+ import Bot from "../..";
2
2
  import { InlineKeypad, Keypad } from "../../types/interfaces";
3
3
  import { ChatKeypadTypeEnum, FileTypeEnum } from "../../types/enums";
4
4
  import { FileSource } from "../../types/methods";
5
5
 
6
6
  async function sendVoice(
7
- this: Bot,
8
- chat_id: string,
9
- file: FileSource,
10
- text?: string,
11
- chat_keypad?: Keypad,
12
- inline_keypad?: InlineKeypad,
13
- disable_notification = false,
14
- reply_to_message_id?: string,
15
- chat_keypad_type?: ChatKeypadTypeEnum,
16
- auto_delete: number | boolean = false,
7
+ this: Bot,
8
+ chat_id: string,
9
+ file: FileSource,
10
+ text?: string,
11
+ chat_keypad?: Keypad,
12
+ inline_keypad?: InlineKeypad,
13
+ disable_notification = false,
14
+ reply_to_message_id?: string,
15
+ chat_keypad_type?: ChatKeypadTypeEnum,
16
+ auto_delete: number | false = false,
17
17
  ) {
18
- return await this._sendFile(
19
- chat_id,
20
- file,
21
- text,
22
- FileTypeEnum.Voice,
23
- chat_keypad,
24
- inline_keypad,
25
- disable_notification,
26
- reply_to_message_id,
27
- chat_keypad_type,
28
- auto_delete
29
- );
18
+ return await this._sendFile(
19
+ chat_id,
20
+ file,
21
+ text,
22
+ FileTypeEnum.Voice,
23
+ chat_keypad,
24
+ inline_keypad,
25
+ disable_notification,
26
+ reply_to_message_id,
27
+ chat_keypad_type,
28
+ auto_delete,
29
+ );
30
30
  }
31
31
 
32
32
  export default sendVoice;
@@ -1,6 +1,6 @@
1
1
  import Bot from "../..";
2
2
 
3
- async function getUpdates(this: Bot, offset_id?: string, limit: number = 10) {
3
+ async function getUpdates(this: Bot, offset_id?: string, limit: number = 100) {
4
4
  return await this.builder("getUpdates", { offset_id, limit });
5
5
  }
6
6
 
@@ -3,25 +3,23 @@ import Inline from "../../contexts/inline";
3
3
  import Update from "../../contexts/update";
4
4
  import { UpdateTypeEnum } from "../../types/enums";
5
5
  import { checkFilters } from "../../../utils";
6
+ import { InlineMessage, UpdateMessage } from "../../types/interfaces";
6
7
 
8
+ type UpdateResult = { inline_message: InlineMessage; update: UpdateMessage };
7
9
  const checkTypes = [UpdateTypeEnum.UpdatedMessage, UpdateTypeEnum.NewMessage];
8
10
 
9
11
  async function handleUpdates(this: Bot, req: Request) {
10
- let responseData = null;
12
+ let data: UpdateResult;
11
13
  try {
12
- responseData = await req.json();
13
- } catch {}
14
-
15
- if (!responseData) return;
14
+ data = (await req.json()) as UpdateResult;
15
+ } catch {
16
+ return;
17
+ }
16
18
 
17
- const data = JSON.parse(
18
- JSON.stringify(responseData, (_, v) =>
19
- typeof v === "bigint" ? v.toString() : v,
20
- ),
21
- );
19
+ if (!data) return;
22
20
 
23
- if (data?.update) {
24
- for (let { prefix, filters, handler } of this.handlers.update) {
21
+ if ("update" in data) {
22
+ for (const { prefix, filters, handler } of this.handlers.update) {
25
23
  const ctx = new Update(data.update, this);
26
24
  const passed = await checkFilters(ctx, filters);
27
25
 
@@ -38,8 +36,10 @@ async function handleUpdates(this: Bot, req: Request) {
38
36
  await handler(ctx);
39
37
  }
40
38
  }
41
- } else if (data?.inline_message) {
42
- for (let { filters, handler } of this.handlers.inline) {
39
+ }
40
+
41
+ if ("inline_message" in data) {
42
+ for (const { filters, handler } of this.handlers.inline) {
43
43
  const ctx = new Inline(data.inline_message, this);
44
44
  const passed = await checkFilters(ctx, filters);
45
45