rubjs 2.4.2 → 2.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubjs",
3
- "version": "2.4.2",
3
+ "version": "2.5.4",
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);
@@ -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,33 @@
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 = 0; index < countLoop; index++) {
17
+ try {
18
+ const res = yield this.getMessages(object_guid, message_id, "25", sort, filter_type);
19
+ if (!res.has_continue)
20
+ break;
21
+ message_id = res.new_max_id;
22
+ const messagesID = res.messages.map((message) => message.message_id);
23
+ tasks.push(this.deleteMessages(object_guid, messagesID));
24
+ }
25
+ catch (error) {
26
+ console.error(`Error fetching messages: ${error}`);
27
+ }
28
+ }
29
+ yield Promise.allSettled(tasks);
30
+ return true;
31
+ });
32
+ }
33
+ 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>;
@@ -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,
@@ -191,7 +191,16 @@ class Network {
191
191
  if (!messageData)
192
192
  return;
193
193
  const isValid = filters.length === 0 ||
194
- filters.every((filter) => filter(messageData));
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
+ });
195
204
  const dataMessage = new types_1.Message(this.client, messageData);
196
205
  if (isValid) {
197
206
  yield callback(dataMessage);
@@ -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;
@@ -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;