djs-selfbot-v13 3.7.5 → 3.7.6

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,7 @@
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
93
94
 
94
95
 
95
96
  </details>
@@ -152,12 +153,19 @@ const userMessages = await channel.search({
152
153
  // Search for pinned messages
153
154
  const pinnedMessages = await channel.search({ pinned: true });
154
155
 
156
+ // Search for messages before a specific date
157
+ const oldMessages = await channel.search({
158
+ maxTime: '2023-12-01',
159
+ limit: 50
160
+ });
161
+
155
162
  // Search for messages with multiple filters
156
163
  const complexSearch = await channel.search({
157
164
  has: ['link', 'embed'],
158
165
  sortBy: 'timestamp',
159
166
  sortOrder: 'desc',
160
- offset: 20
167
+ offset: 20,
168
+ maxTime: new Date('2023-12-31')
161
169
  });
162
170
  ```
163
171
 
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.6",
4
4
  "description": "An unofficial discord.js fork for creating selfbots",
5
5
  "main": "./src/index.js",
6
6
  "types": "./typings/index.d.ts",
@@ -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 {