rubjs 2.4.2 → 2.5.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubjs",
3
- "version": "2.4.2",
3
+ "version": "2.5.7",
4
4
  "main": "rubjs/index.js",
5
5
  "types": "rubjs/index.d.ts",
6
6
  "keywords": [
package/rubjs/client.d.ts CHANGED
@@ -27,7 +27,7 @@ declare class Client extends Methods {
27
27
  initialize: boolean;
28
28
  eventHandlers: {
29
29
  callback: Function;
30
- filters: ((msg: any) => boolean)[];
30
+ filters: ((msg: any) => boolean)[] | ((msg: any) => boolean)[][];
31
31
  updateType: TypeUpdate;
32
32
  }[];
33
33
  constructor(sessionFile: string, timeout?: number, platform?: PlatformType);
package/rubjs/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import Client from "./client";
2
2
  import Crypto from "./crypto";
3
- import Markdown from "./parser";
4
3
  import * as Types from "./types";
5
4
  import { Filters, Utils } from "./utils";
6
5
  export default Client;
7
- export { Client, Crypto, Markdown, Utils, Filters, Types };
6
+ export { Client, Crypto, Utils, Filters, Types };
package/rubjs/index.js CHANGED
@@ -36,13 +36,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.Types = exports.Filters = exports.Utils = exports.Markdown = exports.Crypto = exports.Client = void 0;
39
+ exports.Types = exports.Filters = exports.Utils = exports.Crypto = exports.Client = void 0;
40
40
  const client_1 = __importDefault(require("./client"));
41
41
  exports.Client = client_1.default;
42
42
  const crypto_1 = __importDefault(require("./crypto"));
43
43
  exports.Crypto = crypto_1.default;
44
- const parser_1 = __importDefault(require("./parser"));
45
- exports.Markdown = parser_1.default;
46
44
  const Types = __importStar(require("./types"));
47
45
  exports.Types = Types;
48
46
  const utils_1 = require("./utils");
@@ -0,0 +1,3 @@
1
+ import Client from "../..";
2
+ declare function deleteMessagebyCount(this: Client, object_guid: string, message_id: string, count: number, sort?: "FromMin" | "FromMax", filter_type?: "Music" | "File" | "Media" | "Voice" | "Gif" | "Groups" | "Channels"): Promise<boolean>;
3
+ export default deleteMessagebyCount;
@@ -0,0 +1,30 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function deleteMessagebyCount(object_guid_1, message_id_1, count_1) {
13
+ return __awaiter(this, arguments, void 0, function* (object_guid, message_id, count, sort = "FromMax", filter_type) {
14
+ const countLoop = Math.ceil(count / 25);
15
+ const tasks = [];
16
+ for (let index = 1; index <= countLoop; index++) {
17
+ const res = yield this.getMessages(object_guid, message_id, "25", sort, filter_type);
18
+ if (!res.has_continue)
19
+ break;
20
+ message_id = res.new_max_id;
21
+ const messagesID = res.messages.map((message) => message.message_id);
22
+ tasks.push(this.deleteMessages(object_guid, index !== countLoop
23
+ ? messagesID
24
+ : messagesID.slice(0, count - (countLoop - 1) * 25)));
25
+ }
26
+ yield Promise.allSettled(tasks);
27
+ return true;
28
+ });
29
+ }
30
+ exports.default = deleteMessagebyCount;
@@ -1,4 +1,5 @@
1
1
  import banMember from "./banMember";
2
+ import deleteMessagebyCount from "./deleteMessagebyCount";
2
3
  import getInfo from "./getInfo";
3
4
  import getObjectByUsername from "./getObjectByUsername";
4
5
  import getProfileLinkItems from "./getProfileLinkItems";
@@ -10,4 +11,4 @@ import reportObject from "./reportObject";
10
11
  import searchGlobalObjects from "./searchGlobalObjects";
11
12
  import transcribeVoice from "./transcribeVoice";
12
13
  import userIsAdmin from "./userIsAdmin";
13
- export { banMember, getInfo, getObjectByUsername, getProfileLinkItems, getRelatedObjects, getTranscription, join, leaveChat, reportObject, searchGlobalObjects, transcribeVoice, userIsAdmin, };
14
+ export { banMember, getInfo, getObjectByUsername, getProfileLinkItems, getRelatedObjects, getTranscription, join, leaveChat, reportObject, searchGlobalObjects, transcribeVoice, userIsAdmin, deleteMessagebyCount };
@@ -3,9 +3,11 @@ 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.userIsAdmin = exports.transcribeVoice = exports.searchGlobalObjects = exports.reportObject = exports.leaveChat = exports.join = exports.getTranscription = exports.getRelatedObjects = exports.getProfileLinkItems = exports.getObjectByUsername = exports.getInfo = exports.banMember = void 0;
6
+ exports.deleteMessagebyCount = exports.userIsAdmin = exports.transcribeVoice = exports.searchGlobalObjects = exports.reportObject = exports.leaveChat = exports.join = exports.getTranscription = exports.getRelatedObjects = exports.getProfileLinkItems = exports.getObjectByUsername = exports.getInfo = exports.banMember = void 0;
7
7
  const banMember_1 = __importDefault(require("./banMember"));
8
8
  exports.banMember = banMember_1.default;
9
+ const deleteMessagebyCount_1 = __importDefault(require("./deleteMessagebyCount"));
10
+ exports.deleteMessagebyCount = deleteMessagebyCount_1.default;
9
11
  const getInfo_1 = __importDefault(require("./getInfo"));
10
12
  exports.getInfo = getInfo_1.default;
11
13
  const getObjectByUsername_1 = __importDefault(require("./getObjectByUsername"));
@@ -99,6 +99,7 @@ declare class Methods {
99
99
  searchGlobalObjects(this: Client, ...args: Parameters<typeof Extras.searchGlobalObjects>): Promise<any>;
100
100
  transcribeVoice(this: Client, ...args: Parameters<typeof Extras.transcribeVoice>): Promise<any>;
101
101
  userIsAdmin(this: Client, ...args: Parameters<typeof Extras.userIsAdmin>): Promise<any>;
102
+ deleteMessagebyCount(this: Client, ...args: Parameters<typeof Extras.deleteMessagebyCount>): Promise<any>;
102
103
  addToMyGifSet(this: Client, ...args: Parameters<typeof Gif.addToMyGifSet>): Promise<any>;
103
104
  getMyGifSet(this: Client, ...args: Parameters<typeof Gif.getMyGifSet>): Promise<any>;
104
105
  removeFromMyGifSet(this: Client, ...args: Parameters<typeof Gif.removeFromMyGifSet>): Promise<any>;
@@ -111,11 +112,11 @@ declare class Methods {
111
112
  editGroupInfo(this: Client, ...args: Parameters<typeof Groups.editGroupInfo>): Promise<any>;
112
113
  getBannedGroupMembers(this: Client, ...args: Parameters<typeof Groups.getBannedGroupMembers>): Promise<GroupTypes.GetBannedGroupMembers>;
113
114
  getGroupAdminAccessList(this: Client, ...args: Parameters<typeof Groups.getGroupAdminAccessList>): Promise<any>;
114
- getGroupAdminMembers(this: Client, ...args: Parameters<typeof Groups.getGroupAdminMembers>): Promise<any>;
115
+ getGroupAdminMembers(this: Client, ...args: Parameters<typeof Groups.getGroupAdminMembers>): Promise<GroupTypes.GetGroupAdminMembers>;
115
116
  getGroupOnlineCount(this: Client, ...args: Parameters<typeof Groups.getGroupOnlineCount>): Promise<any>;
116
117
  getGroupAllMembers(this: Client, ...args: Parameters<typeof Groups.getGroupAllMembers>): Promise<any>;
117
118
  getGroupDefaultAccess(this: Client, ...args: Parameters<typeof Groups.getGroupDefaultAccess>): Promise<any>;
118
- getGroupInfo(this: Client, ...args: Parameters<typeof Groups.getGroupInfo>): Promise<any>;
119
+ getGroupInfo(this: Client, ...args: Parameters<typeof Groups.getGroupInfo>): Promise<GroupTypes.GetGroupInfo>;
119
120
  getGroupLink(this: Client, ...args: Parameters<typeof Groups.getGroupLink>): Promise<any>;
120
121
  getGroupMentionList(this: Client, ...args: Parameters<typeof Groups.getGroupMentionList>): Promise<any>;
121
122
  getGroupVoiceChatUpdates(this: Client, ...args: Parameters<typeof Groups.getGroupVoiceChatUpdates>): Promise<any>;
@@ -462,6 +462,11 @@ class Methods {
462
462
  return Extras.userIsAdmin.apply(this, args);
463
463
  });
464
464
  }
465
+ deleteMessagebyCount(...args) {
466
+ return __awaiter(this, void 0, void 0, function* () {
467
+ return Extras.deleteMessagebyCount.apply(this, args);
468
+ });
469
+ }
465
470
  // gif
466
471
  addToMyGifSet(...args) {
467
472
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,3 +1,3 @@
1
1
  import Client from "../..";
2
- declare function getMessages(this: Client, object_guid: string, filter_type: string, max_id: string, limit: string, sort?: "FromMin" | "FromMax"): Promise<any>;
2
+ declare function getMessages(this: Client, object_guid: string, max_id: string, limit: string, sort?: "FromMin" | "FromMax", filter_type?: "Music" | "File" | "Media" | "Voice" | "Gif" | "Groups" | "Channels"): Promise<any>;
3
3
  export default getMessages;
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function getMessages(object_guid_1, filter_type_1, max_id_1, limit_1) {
13
- return __awaiter(this, arguments, void 0, function* (object_guid, filter_type, max_id, limit, sort = "FromMax") {
12
+ function getMessages(object_guid_1, max_id_1, limit_1) {
13
+ return __awaiter(this, arguments, void 0, function* (object_guid, max_id, limit, sort = "FromMax", filter_type) {
14
14
  return yield this.builder("getMessages", {
15
15
  object_guid,
16
16
  filter_type,
@@ -186,15 +186,26 @@ class Network {
186
186
  return;
187
187
  const update = JSON.parse(crypto_1.default.decrypt(data_enc, this.client.key));
188
188
  this.client.eventHandlers.forEach((_a) => __awaiter(this, [_a], void 0, function* ({ callback, filters = [], updateType }) {
189
- var _b;
190
- const messageData = (_b = update[updateType]) === null || _b === void 0 ? void 0 : _b[0];
191
- if (!messageData)
192
- return;
193
- const isValid = filters.length === 0 ||
194
- filters.every((filter) => filter(messageData));
195
- const dataMessage = new types_1.Message(this.client, messageData);
196
- if (isValid) {
197
- yield callback(dataMessage);
189
+ if (update[updateType].length > 0) {
190
+ for (let messageData of update[updateType]) {
191
+ if (!messageData)
192
+ return;
193
+ const isValid = filters.length === 0 ||
194
+ filters.every((filter) => {
195
+ if (typeof filter === "function")
196
+ return filter(messageData);
197
+ for (let filterCriteria of filter) {
198
+ let isMatch = filterCriteria(messageData);
199
+ if (isMatch === true)
200
+ return true;
201
+ }
202
+ return false;
203
+ });
204
+ const dataMessage = new types_1.Message(this.client, messageData);
205
+ if (isValid) {
206
+ yield callback(dataMessage);
207
+ }
208
+ }
198
209
  }
199
210
  }));
200
211
  }
@@ -100,7 +100,7 @@ class Markdown {
100
100
  return returnData;
101
101
  }
102
102
  }
103
- Markdown.markdownRegExp = /(^|\s|\n)(````?)([\s\S]+?)(````?)([\s\n\.,:?!;]|$)|(^|\s)(`|\*\*|__|~~|--|\|\|)([^\n]+?)\7([\s\.,:?!;]|$)|@([a-zA-Z0-9]+)\s*\((.+?)\)|\[(.+?)\]\((.+?)\)/m;
103
+ Markdown.markdownRegExp = /(^|\s|\n)(````?)([\s\S]+?)(````?)([\s\n\.,:?!;]|$)|(^|\s)(`|\*\*|__|~~|--|\|\||\^\^)([^\n]+?)\7([\s\.,:?!;]|$)|@([a-zA-Z0-9]+)\s*\((.+?)\)|\[(.+?)\]\((.+?)\)/m;
104
104
  Markdown.markdownEntities = {
105
105
  "`": "Mono",
106
106
  "**": "Bold",
@@ -108,5 +108,6 @@ Markdown.markdownEntities = {
108
108
  "||": "Spoiler",
109
109
  "~~": "Strike",
110
110
  "--": "Underline",
111
+ "^^": "Quote",
111
112
  };
112
113
  exports.default = Markdown;
@@ -2,6 +2,16 @@ import MessageUpdate, { ChatUpdates } from "./decorators";
2
2
  interface ChatReactionSetting {
3
3
  reaction_type: string;
4
4
  }
5
+ interface AvatarThumbnail {
6
+ file_id: string;
7
+ mime: string;
8
+ dc_id: string;
9
+ access_hash_rec: string;
10
+ }
11
+ interface OnlineTime {
12
+ type: string;
13
+ exact_time: number;
14
+ }
5
15
  interface Group {
6
16
  group_guid: string;
7
17
  group_title: string;
@@ -75,21 +85,13 @@ interface GroupMember {
75
85
  member_guid: string;
76
86
  first_name: string;
77
87
  last_name: string;
78
- avatar_thumbnail: {
79
- file_id: string;
80
- mime: string;
81
- dc_id: string;
82
- access_hash_rec: string;
83
- };
88
+ avatar_thumbnail: AvatarThumbnail;
84
89
  is_verified: boolean;
85
90
  is_deleted: boolean;
86
91
  last_online: number;
87
92
  join_type: string;
88
93
  username: string;
89
- online_time: {
90
- type: string;
91
- exact_time: number;
92
- };
94
+ online_time: OnlineTime;
93
95
  }
94
96
  interface AddGroup {
95
97
  group: Group;
@@ -122,8 +124,32 @@ interface BanGroupMember {
122
124
  }
123
125
  interface GetBannedGroupMembers {
124
126
  in_chat_members: GroupMember[];
125
- next_start_id: "67b0e8bc1b50d7bec6fc950b";
126
- has_continue: false;
127
- timestamp: "1739888215";
127
+ next_start_id: string;
128
+ has_continue: boolean;
129
+ timestamp: string;
130
+ }
131
+ interface GetGroupInfo {
132
+ group: Group;
133
+ chat: Chat;
134
+ timestamp: string;
135
+ }
136
+ interface GetGroupAdminMembers {
137
+ in_chat_members: {
138
+ member_type: string;
139
+ member_guid: string;
140
+ first_name: string;
141
+ avatar_thumbnail: AvatarThumbnail;
142
+ is_verified: boolean;
143
+ is_deleted: boolean;
144
+ last_online: number;
145
+ promoted_by_object_guid: string;
146
+ promoted_by_object_type: string;
147
+ join_type: string;
148
+ username: string;
149
+ online_time: OnlineTime;
150
+ }[];
151
+ next_start_id: string;
152
+ has_continue: boolean;
153
+ timestamp: string;
128
154
  }
129
- export { AddGroup, DeleteNoAccessGroupChat, CreateGroupVoiceChat, AddGroupMembers, BanGroupMember, GetBannedGroupMembers };
155
+ export { AddGroup, DeleteNoAccessGroupChat, CreateGroupVoiceChat, AddGroupMembers, BanGroupMember, GetBannedGroupMembers, GetGroupInfo, GetGroupAdminMembers, };
@@ -11,6 +11,7 @@ declare class Message implements MessageUpdate {
11
11
  type: string;
12
12
  state: string;
13
13
  client: Client;
14
+ originalType: string;
14
15
  constructor(client: Client, update: MessageUpdate);
15
16
  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
17
  pin(object_guid?: string, message_id?: string, action?: "Pin" | "Unpin"): Promise<import("./messages").SetPinMessage>;
@@ -9,6 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const getOriginalType = (message) => {
13
+ if (message.message.type.includes("FileInline")) {
14
+ return message.message.file_inline.type;
15
+ }
16
+ if (message.message.type === "Event") {
17
+ return message.message.event_data.type;
18
+ }
19
+ return message.message.type;
20
+ };
12
21
  class Message {
13
22
  constructor(client, update) {
14
23
  Object.assign(this, update);
@@ -18,6 +27,12 @@ class Message {
18
27
  writable: true,
19
28
  configurable: true,
20
29
  });
30
+ Object.defineProperty(this, "originalType", {
31
+ value: getOriginalType(update),
32
+ enumerable: false,
33
+ writable: true,
34
+ configurable: true,
35
+ });
21
36
  }
22
37
  reply(text, object_guid, message_id, auto_delete, file_inline, type, is_spoil, thumb, audio_info) {
23
38
  return __awaiter(this, void 0, void 0, function* () {
@@ -43,7 +58,9 @@ class Message {
43
58
  }
44
59
  delete() {
45
60
  return __awaiter(this, void 0, void 0, function* () {
46
- return yield this.client.deleteMessages(this.object_guid, [this.message_id]);
61
+ return yield this.client.deleteMessages(this.object_guid, [
62
+ this.message_id,
63
+ ]);
47
64
  });
48
65
  }
49
66
  reaction(reaction_id_1, object_guid_1, message_id_1) {
@@ -3,6 +3,7 @@ declare class Filters {
3
3
  static findKey(message: any, key: string): any;
4
4
  static guidType(message: MessageUpdate, startWith: string): boolean;
5
5
  static isMention(message: MessageUpdate): boolean;
6
+ static isMarkdown(message: MessageUpdate): boolean;
6
7
  static isReply(message: MessageUpdate): boolean;
7
8
  static isEdited(message: MessageUpdate): boolean;
8
9
  static isLink(message: MessageUpdate): boolean;
@@ -37,6 +37,9 @@ class Filters {
37
37
  var _a, _b;
38
38
  return !!Filters.findKey((_b = (_a = message.message) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.meta_data_parts, "link");
39
39
  }
40
+ static isMarkdown(message) {
41
+ return !!Filters.findKey(message.message, "metadata");
42
+ }
40
43
  static isReply(message) {
41
44
  return !!Filters.findKey(message, "reply_to_message_id");
42
45
  }
@@ -5,6 +5,7 @@ declare class Utils {
5
5
  static Spoiler: (text: string) => string;
6
6
  static Strike: (text: string) => string;
7
7
  static Underline: (text: string) => string;
8
+ static Quote: (text: string) => string;
8
9
  static HyperLink: (text: string, link: string) => string;
9
10
  }
10
11
  export default Utils;
@@ -8,5 +8,6 @@ Utils.Italic = (text) => `__${text.trim()}__`;
8
8
  Utils.Spoiler = (text) => `||${text.trim()}||`;
9
9
  Utils.Strike = (text) => `~~${text.trim()}~~`;
10
10
  Utils.Underline = (text) => `--${text.trim()}--`;
11
+ Utils.Quote = (text) => `^^${text.trim()}^^`;
11
12
  Utils.HyperLink = (text, link) => `[${text.trim()}](${link.trim()})`;
12
13
  exports.default = Utils;