djs-selfbot-v13 3.7.5 → 3.7.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/README.md CHANGED
@@ -29,7 +29,7 @@
29
29
  ### Guild Management
30
30
  - `guild.mute(options?)` - Mute a guild completely (suppress all notifications)
31
31
  - `guild.unmute()` - Unmute a guild (restore all notifications)
32
- - - `guild.markRead(readStates?)` - Mark all channels in a guild as read
32
+ - `guild.markRead(readStates?)` - Mark all channels in a guild as read
33
33
 
34
34
  ### Developer Applications
35
35
  - `client.developers.get(withTeamApplications?)` - Fetch all developer applications owned by the user
@@ -90,6 +90,11 @@
90
90
  - `sortOrder` - Sort order `desc` or `asc`
91
91
  - `offset` - Pagination offset
92
92
  - `limit` - Limit number of results
93
+ - `maxTime` - Search for messages before a specific date/time
94
+
95
+ - `guild.search(options?)` - Search for messages across the entire guild with advanced filters
96
+ - `channelId` - Search in a specific channel within the guild
97
+ - All other options same as `channel.search()`
93
98
 
94
99
 
95
100
  </details>
@@ -152,12 +157,32 @@ const userMessages = await channel.search({
152
157
  // Search for pinned messages
153
158
  const pinnedMessages = await channel.search({ pinned: true });
154
159
 
160
+ // Search for messages before a specific date
161
+ const oldMessages = await channel.search({
162
+ maxTime: '2023-12-01',
163
+ limit: 50
164
+ });
165
+
155
166
  // Search for messages with multiple filters
156
167
  const complexSearch = await channel.search({
157
168
  has: ['link', 'embed'],
158
169
  sortBy: 'timestamp',
159
170
  sortOrder: 'desc',
160
- offset: 20
171
+ offset: 20,
172
+ maxTime: new Date('2023-12-31')
173
+ });
174
+
175
+ // Guild-wide search for messages in a specific channel
176
+ const guildChannelSearch = await guild.search({
177
+ channelId: '123456789012345678',
178
+ authorId: '987654321098765432',
179
+ has: ['image']
180
+ });
181
+
182
+ // Guild-wide search across all channels
183
+ const guildWideSearch = await guild.search({
184
+ has: ['video'],
185
+ limit: 100
161
186
  });
162
187
  ```
163
188
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "djs-selfbot-v13",
3
- "version": "3.7.5",
3
+ "version": "3.7.7",
4
4
  "description": "An unofficial discord.js fork for creating selfbots",
5
5
  "main": "./src/index.js",
6
6
  "types": "./typings/index.d.ts",
@@ -1690,6 +1690,70 @@ class Guild extends AnonymousGuild {
1690
1690
  return data;
1691
1691
  }
1692
1692
 
1693
+ /**
1694
+ * Search for messages in this guild
1695
+ * @param {GuildSearchOptions} [options] Search options
1696
+ * @returns {Promise<Object>} The search results
1697
+ * @example
1698
+ * // Search for messages in a specific channel
1699
+ * guild.search({ channelId: '123456789012345678' });
1700
+ *
1701
+ * // Search for messages by author in a channel
1702
+ * guild.search({
1703
+ * channelId: '123456789012345678',
1704
+ * authorId: '987654321098765432'
1705
+ * });
1706
+ *
1707
+ * // Search for messages with images across the guild
1708
+ * guild.search({ has: ['image'] });
1709
+ */
1710
+ async search(options = {}) {
1711
+ const {
1712
+ channelId,
1713
+ authorId,
1714
+ mentions,
1715
+ has = [],
1716
+ pinned,
1717
+ sortBy = 'timestamp',
1718
+ sortOrder = 'desc',
1719
+ offset = 0,
1720
+ limit,
1721
+ maxTime
1722
+ } = options;
1723
+
1724
+ const query = {
1725
+ sort_by: sortBy,
1726
+ sort_order: sortOrder,
1727
+ offset: offset
1728
+ };
1729
+
1730
+ if (channelId) query.channel_id = channelId;
1731
+ if (authorId) query.author_id = authorId;
1732
+ if (mentions) query.mentions = mentions;
1733
+ if (pinned) query.pinned = true;
1734
+
1735
+ if (maxTime) {
1736
+ const time = new Date(maxTime).getTime();
1737
+ const maxId = (BigInt(time) - 1420070400000n) << 22n;
1738
+ query.max_id = maxId.toString();
1739
+ }
1740
+
1741
+ // Add 'has' parameters
1742
+ for (const hasType of has) {
1743
+ if (!query.has) query.has = [];
1744
+ query.has.push(hasType);
1745
+ }
1746
+
1747
+ const data = await this.client.api.guilds(this.id).messages.search.get({ query });
1748
+
1749
+ if (limit && data.messages) {
1750
+ // data.messages est souvent un tableau de tableaux dans l'API search
1751
+ data.messages = data.messages.flat().slice(0, limit);
1752
+ }
1753
+
1754
+ return data;
1755
+ }
1756
+
1693
1757
  /**
1694
1758
  * Creates a collection of this guild's roles, sorted by their position and ids.
1695
1759
  * @returns {Collection<Snowflake, Role>}
@@ -385,17 +385,7 @@ class TextBasedChannel {
385
385
  return Util.createPromiseInteraction(this.client, nonce, 5000);
386
386
  }
387
387
 
388
- /**
389
- * Search messages in this channel by user
390
- * @param {number} limit Number of messages to return
391
- * @param {UserResolvable} user User whose messages to search for
392
- * @returns {Promise<Object[]|false>} Array of messages or false if failed
393
- * @example
394
- * // Search for messages from a user
395
- * channel.search(10, user)
396
- * .then(messages => console.log(`Found ${messages.length} messages`))
397
- * .catch(console.error);
398
- */
388
+
399
389
  /**
400
390
  * Search for messages in this channel
401
391
  * @param {ChannelSearchOptions} [options] Search options
@@ -419,41 +409,41 @@ class TextBasedChannel {
419
409
  sortBy = 'timestamp',
420
410
  sortOrder = 'desc',
421
411
  offset = 0,
422
- limit
412
+ limit,
413
+ maxTime
423
414
  } = options;
424
415
 
425
- const params = new URLSearchParams({
426
- channel_id: this.id,
416
+ const query = {
427
417
  sort_by: sortBy,
428
418
  sort_order: sortOrder,
429
- offset: offset.toString()
430
- });
419
+ offset: offset
420
+ };
431
421
 
432
- if (authorId) params.append('author_id', authorId);
433
- if (mentions) params.append('mentions', mentions);
434
- if (pinned) params.append('pinned', 'true');
422
+ if (maxTime) {
423
+ const time = new Date(maxTime).getTime();
424
+ const maxId = (BigInt(time) - 1420070400000n) << 22n;
425
+ query.max_id = maxId.toString();
426
+ }
427
+
428
+ if (authorId) query.author_id = authorId;
429
+ if (mentions) query.mentions = mentions;
430
+ if (pinned) query.pinned = true;
435
431
 
436
- // Add 'has' parameters
437
432
  for (const hasType of has) {
438
- params.append('has', hasType);
433
+ if (!query.has) query.has = [];
434
+ query.has.push(hasType);
439
435
  }
440
436
 
441
- const endpoint = this.guild
442
- ? `guilds/${this.guild.id}/messages/search`
443
- : `channels/${this.id}/messages/search`;
437
+ if (this.guild) query.channel_id = this.id;
444
438
 
445
- const res = await fetch(`https://ptb.discord.com/api/v9/${endpoint}?${params}`, {
446
- method: 'GET',
447
- headers: { authorization: this.client.token }
448
- });
449
-
450
- if (!res.ok) return false;
439
+ const endpoint = this.guild
440
+ ? this.client.api.guilds(this.guild.id).messages.search
441
+ : this.client.api.channels(this.id).messages.search;
451
442
 
452
- const data = await res.json();
443
+ const data = await endpoint.get({ query });
453
444
 
454
- if (limit && data.messages) {
455
- data.messages = data.messages.slice(0, limit);
456
- }
445
+ if (limit && data.messages)
446
+ data.messages = data.messages.flat().slice(0, limit);
457
447
 
458
448
  return data;
459
449
  }
@@ -954,6 +954,7 @@ export interface ChannelSearchOptions {
954
954
  sortOrder?: 'desc' | 'asc';
955
955
  offset?: number;
956
956
  limit?: number;
957
+ maxTime?: string | Date;
957
958
  }
958
959
 
959
960
  export interface MarkReadOptions {
@@ -962,6 +963,19 @@ export interface MarkReadOptions {
962
963
  read_state_type?: number;
963
964
  }
964
965
 
966
+ export interface GuildSearchOptions {
967
+ channelId?: Snowflake;
968
+ authorId?: Snowflake;
969
+ mentions?: Snowflake;
970
+ has?: ('image' | 'video' | 'link' | 'embed' | 'sound' | 'poll' | 'sticker' | 'snapshot')[];
971
+ pinned?: boolean;
972
+ sortBy?: 'timestamp' | 'relevance';
973
+ sortOrder?: 'desc' | 'asc';
974
+ offset?: number;
975
+ limit?: number;
976
+ maxTime?: string | Date;
977
+ }
978
+
965
979
  export type OAuth2AuthorizeOptions = {
966
980
  guild_id?: Snowflake;
967
981
  permissions?: string;
@@ -1702,6 +1716,7 @@ export class Guild extends AnonymousGuild {
1702
1716
  public mute(options?: GuildMuteOptions): Promise<any>;
1703
1717
  public unmute(): Promise<any>;
1704
1718
  public markRead(readStates?: MarkReadOptions[]): Promise<any>;
1719
+ public search(options?: GuildSearchOptions): Promise<any>;
1705
1720
  }
1706
1721
 
1707
1722
  export class GuildAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'> {