discord-sb.js 1.0.2 → 1.0.3
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 +1 -1
- package/src/managers/QuestManager.js +22 -7
package/package.json
CHANGED
|
@@ -91,6 +91,14 @@ class QuestManager extends BaseManager {
|
|
|
91
91
|
return data;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Refresh the quest cache from the API
|
|
96
|
+
* @returns {Promise<Object>} Latest quest data
|
|
97
|
+
*/
|
|
98
|
+
async refreshCache() {
|
|
99
|
+
return this.get();
|
|
100
|
+
}
|
|
101
|
+
|
|
94
102
|
/**
|
|
95
103
|
* Get user's orb balance (virtual currency)
|
|
96
104
|
* @returns {Promise<Object>} Balance data
|
|
@@ -198,19 +206,22 @@ class QuestManager extends BaseManager {
|
|
|
198
206
|
quest.updateUserStatus(data);
|
|
199
207
|
}
|
|
200
208
|
|
|
201
|
-
|
|
209
|
+
await this.refreshCache();
|
|
210
|
+
return this.getQuest(questId);
|
|
202
211
|
}
|
|
203
212
|
|
|
204
213
|
/**
|
|
205
214
|
* Update progress for a video quest
|
|
206
215
|
* @param {string} questId The quest ID
|
|
207
216
|
* @param {number} timestamp Current progress timestamp
|
|
217
|
+
* @param {boolean} [refresh=true] Whether to refresh the quest cache after the update
|
|
208
218
|
* @returns {Promise<Object>} Progress update result
|
|
209
219
|
*/
|
|
210
|
-
async videoProgress(questId, timestamp) {
|
|
220
|
+
async videoProgress(questId, timestamp, refresh = true) {
|
|
211
221
|
const data = await this.client.api.quests(questId)['video-progress'].post({
|
|
212
222
|
data: { timestamp },
|
|
213
223
|
});
|
|
224
|
+
if (refresh) await this.refreshCache();
|
|
214
225
|
return data;
|
|
215
226
|
}
|
|
216
227
|
|
|
@@ -219,15 +230,17 @@ class QuestManager extends BaseManager {
|
|
|
219
230
|
* @param {string} questId The quest ID
|
|
220
231
|
* @param {string} applicationId Application ID
|
|
221
232
|
* @param {boolean} [terminal=false] Whether this is a terminal heartbeat
|
|
233
|
+
* @param {boolean} [refresh=true] Whether to refresh the quest cache after the update
|
|
222
234
|
* @returns {Promise<Object>} Heartbeat result
|
|
223
235
|
*/
|
|
224
|
-
async heartbeat(questId, applicationId, terminal = false) {
|
|
236
|
+
async heartbeat(questId, applicationId, terminal = false, refresh = true) {
|
|
225
237
|
const data = await this.client.api.quests(questId).heartbeat.post({
|
|
226
238
|
data: {
|
|
227
239
|
application_id: applicationId,
|
|
228
240
|
terminal,
|
|
229
241
|
},
|
|
230
242
|
});
|
|
243
|
+
if (refresh) await this.refreshCache();
|
|
231
244
|
return data;
|
|
232
245
|
}
|
|
233
246
|
|
|
@@ -282,7 +295,7 @@ class QuestManager extends BaseManager {
|
|
|
282
295
|
const timestamp = secondsDone + speed;
|
|
283
296
|
|
|
284
297
|
if (diff >= speed) {
|
|
285
|
-
const res = await this.videoProgress(quest.id, Math.min(secondsNeeded, timestamp + Math.random()));
|
|
298
|
+
const res = await this.videoProgress(quest.id, Math.min(secondsNeeded, timestamp + Math.random()), false);
|
|
286
299
|
completed = res.completed_at != null;
|
|
287
300
|
secondsDone = Math.min(secondsNeeded, timestamp);
|
|
288
301
|
}
|
|
@@ -295,21 +308,23 @@ class QuestManager extends BaseManager {
|
|
|
295
308
|
}
|
|
296
309
|
|
|
297
310
|
if (!completed) {
|
|
298
|
-
await this.videoProgress(quest.id, secondsNeeded);
|
|
311
|
+
await this.videoProgress(quest.id, secondsNeeded, false);
|
|
299
312
|
}
|
|
300
313
|
} else if (taskName === 'PLAY_ON_DESKTOP') {
|
|
301
314
|
const interval = 60;
|
|
302
315
|
|
|
303
316
|
while (!quest.isCompleted()) {
|
|
304
|
-
const res = await this.heartbeat(quest.id, quest.config.application.id, false);
|
|
317
|
+
const res = await this.heartbeat(quest.id, quest.config.application.id, false, false);
|
|
305
318
|
quest.updateUserStatus(res);
|
|
306
319
|
|
|
307
320
|
await this.timeout(interval * 1000);
|
|
308
321
|
}
|
|
309
322
|
|
|
310
|
-
const res = await this.heartbeat(quest.id, quest.config.application.id, true);
|
|
323
|
+
const res = await this.heartbeat(quest.id, quest.config.application.id, true, false);
|
|
311
324
|
quest.updateUserStatus(res);
|
|
312
325
|
}
|
|
326
|
+
|
|
327
|
+
await this.refreshCache();
|
|
313
328
|
}
|
|
314
329
|
|
|
315
330
|
/**
|