djs-selfbot-v13 3.7.28 → 3.7.30

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": "djs-selfbot-v13",
3
- "version": "3.7.28",
3
+ "version": "3.7.30",
4
4
  "description": "An unofficial discord.js fork for creating selfbots",
5
5
  "main": "./src/index.js",
6
6
  "types": "./typings/index.d.ts",
@@ -18,6 +18,7 @@ const ClientUserSettingManager = require('../managers/ClientUserSettingManager')
18
18
  const DeveloperManager = require('../managers/DeveloperManager');
19
19
  const GuildManager = require('../managers/GuildManager');
20
20
  const PresenceManager = require('../managers/PresenceManager');
21
+ const BackupManager = require('../managers/BackupManager');
21
22
  const QuestManager = require('../managers/QuestManager');
22
23
  const RelationshipManager = require('../managers/RelationshipManager');
23
24
  const SessionManager = require('../managers/SessionManager');
@@ -172,6 +173,12 @@ class Client extends BaseClient {
172
173
  */
173
174
  this.quests = new QuestManager(this);
174
175
 
176
+ /**
177
+ * Manages guild backup operations
178
+ * @type {BackupManager}
179
+ */
180
+ this.backups = new BackupManager(this);
181
+
175
182
  /**
176
183
  * All of the sessions of the client
177
184
  * @type {SessionManager}
package/src/index.js CHANGED
@@ -75,6 +75,9 @@ exports.WebSocketManager = require('./client/websocket/WebSocketManager');
75
75
  exports.WebSocketShard = require('./client/websocket/WebSocketShard');
76
76
  exports.RelationshipManager = require('./managers/RelationshipManager');
77
77
  exports.UserNoteManager = require('./managers/UserNoteManager');
78
+ exports.QuestManager = require('./managers/QuestManager');
79
+ exports.Quest = require('./managers/QuestManager').Quest;
80
+ exports.BackupManager = require('./managers/BackupManager');
78
81
 
79
82
  // Structures
80
83
  exports.Activity = require('./structures/Presence').Activity;
@@ -0,0 +1,141 @@
1
+ 'use strict';
2
+
3
+ const { Collection } = require('@discordjs/collection');
4
+ const BaseManager = require('./BaseManager');
5
+ const backup = require('../util/backup');
6
+
7
+ /**
8
+ * Manages in-memory guild backups
9
+ */
10
+ class BackupCacheManager {
11
+ /**
12
+ * @param {BackupManager} manager Parent backup manager
13
+ */
14
+ constructor(manager) {
15
+ /**
16
+ * @type {BackupManager}
17
+ * @private
18
+ */
19
+ this._manager = manager;
20
+
21
+ /**
22
+ * Cached backup data
23
+ * @type {Collection<string, Object>}
24
+ * @private
25
+ */
26
+ this._storage = new Collection();
27
+ }
28
+
29
+ /**
30
+ * The client that instantiated this manager
31
+ * @type {import('../client/Client')}
32
+ */
33
+ get client() {
34
+ return this._manager.client;
35
+ }
36
+
37
+ /**
38
+ * Resolve a guild from an ID
39
+ * @param {import('../util/SnowflakeUtil').Snowflake} guildId Guild ID
40
+ * @returns {import('../structures/Guild').Guild}
41
+ * @private
42
+ */
43
+ _resolveGuild(guildId) {
44
+ const guild = this.client.guilds.resolve(guildId);
45
+ if (!guild) {
46
+ throw new Error(`Guild "${guildId}" could not be resolved.`);
47
+ }
48
+ return guild;
49
+ }
50
+
51
+ /**
52
+ * Create a backup from a guild and store it in cache
53
+ * @param {import('../util/SnowflakeUtil').Snowflake} guildId Guild ID to backup
54
+ * @param {Object} [options] Backup creation options
55
+ * @returns {Promise<Object>} Backup data
56
+ */
57
+ async create(guildId, options = {}) {
58
+ const guild = this._resolveGuild(guildId);
59
+ const backupData = await backup.create(guild, options);
60
+ this._storage.set(backupData.id, backupData);
61
+ return backupData;
62
+ }
63
+
64
+ /**
65
+ * Delete a backup from cache
66
+ * @param {string} backupId Backup ID
67
+ * @returns {boolean} Whether the backup existed
68
+ */
69
+ delete(backupId) {
70
+ return this._storage.delete(backupId);
71
+ }
72
+
73
+ /**
74
+ * Clear all cached backups
75
+ */
76
+ clearAll() {
77
+ this._storage.clear();
78
+ }
79
+
80
+ /**
81
+ * Load a cached backup into a guild
82
+ * @param {import('../util/SnowflakeUtil').Snowflake} guildId Target guild ID
83
+ * @param {string} backupId Backup ID
84
+ * @param {Object} [options] Load options
85
+ * @returns {Promise<Object>} Restored backup data
86
+ */
87
+ async load(guildId, backupId, options = {}) {
88
+ const guild = this._resolveGuild(guildId);
89
+ const backupData = this._storage.get(backupId);
90
+
91
+ if (!backupData) {
92
+ throw new Error(`Backup "${backupId}" was not found in cache.`);
93
+ }
94
+
95
+ return backup.load(backupData, guild, options);
96
+ }
97
+
98
+ /**
99
+ * Get a cached backup
100
+ * @param {string} backupId Backup ID
101
+ * @returns {Object|undefined} Backup info with data, id and size
102
+ */
103
+ get(backupId) {
104
+ const backupData = this._storage.get(backupId);
105
+ if (!backupData) return undefined;
106
+
107
+ const size = Number((Buffer.byteLength(JSON.stringify(backupData), 'utf8') / 1024).toFixed(2));
108
+
109
+ return {
110
+ id: backupId,
111
+ data: backupData,
112
+ size,
113
+ };
114
+ }
115
+
116
+ /**
117
+ * List all cached backup IDs
118
+ * @returns {string[]}
119
+ */
120
+ list() {
121
+ return [...this._storage.keys()];
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Manages guild backup operations
127
+ * @extends {BaseManager}
128
+ */
129
+ class BackupManager extends BaseManager {
130
+ constructor(client) {
131
+ super(client);
132
+
133
+ /**
134
+ * In-memory backup cache
135
+ * @type {BackupCacheManager}
136
+ */
137
+ this.cache = new BackupCacheManager(this);
138
+ }
139
+ }
140
+
141
+ module.exports = BackupManager;