Skip to content

Instantly share code, notes, and snippets.

@Benricheson101
Last active April 26, 2024 20:45
Show Gist options
  • Save Benricheson101/afe5c8f651aac6f83b660f8b50de1294 to your computer and use it in GitHub Desktop.
Save Benricheson101/afe5c8f651aac6f83b660f8b50de1294 to your computer and use it in GitHub Desktop.
Run the script in the Discord dev tools console. Copy the ID (not index) of one of the quests in the table, and run `await completeStreamQuest("18-digit-id-here")`. Do not close the window until it has finished.
const {completeStreamQuest} = (() => {
let wpRequire;
webpackChunkdiscord_app.push([[Date.now()], {}, e => (wpRequire = e)]);
const mods = Object.values(wpRequire.c);
const {Store} = mods.find(m => m?.exports?.Store).exports;
const {ApplicationStreamingStore, QuestsStore, UserStore} =
Store.getAll().reduce((a, c) => ((a[c.getName()] = c), a), {});
const {encodeStreamKey} = mods.find(m => m?.exports?.encodeStreamKey).exports;
const {sendHeartbeat, enrollInQuest} = mods.find(
m => m?.exports?.enrollInQuest
).exports;
const Flux = UserStore._dispatcher;
const printInstructions = () => {
const quests = [...QuestsStore.quests.values()]
.filter(
q =>
new Date(q.config.expiresAt) > new Date() &&
!q.userStatus?.completedAt
)
.map(q => ({id: q.id, game: q.config.applicationName}));
console.log(
'Choose a quest from the list below. Copy the ID (not the index!) and complete it by running `await completeStreamQuest("18-digit-id-here")`'
);
console.table(quests);
};
const completeStreamQuest = async questId => {
const quest = QuestsStore.getQuest(questId);
if (!quest || !quest.config.streamDurationRequirementMinutes) {
throw new Error('That quest does not exist or is invalid.');
}
if (!quest.userStatus) {
console.log('Enrolling you in the quest');
await enrollInQuest(questId, {
questContent: 2,
questContentCTA: 'ACCEPT_QUEST',
});
}
const stream = ApplicationStreamingStore.getAnyStreamForUser(
UserStore.getCurrentUser().id
);
if (!stream) {
throw new Error('You are not streaming!');
}
const streamKey = encodeStreamKey(stream);
console.log(
`Starting the quest. This will take ${quest.config.streamDurationRequirementMinutes} minutes. Do not close this window until it has finished`
);
const progressFn = pl => {
console.log(`Progress: ${pl.userStatus.streamProgressSeconds}/${quest.config.streamDurationRequirementMinutes * 60}`);
};
Flux.subscribe('QUESTS_SEND_HEARTBEAT_SUCCESS', progressFn);
for (let i = 0; i < quest.config.streamDurationRequirementMinutes; i++) {
await sendHeartbeat({questId, streamKey});
await new Promise(r => setTimeout(r, 1000 * 60));
}
console.log('Done! Open your gift inventory to claim the reward.');
Flux.unsubscribe('QUESTS_SEND_HEARTBEAT_SUCCESS', progressFn);
};
printInstructions();
return {completeStreamQuest};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment