mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-08 06:03:03 -04:00
Update & Fix QuestCompleter
This commit is contained in:
parent
87d8bfb374
commit
973148d86d
2 changed files with 17 additions and 19 deletions
|
@ -24,8 +24,6 @@ export const reverseExtensionMap = Object.entries(extensionMap).reduce((acc, [ta
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, string>);
|
}, {} as Record<string, string>);
|
||||||
|
|
||||||
type ExtUpload = Upload & { fixExtension?: boolean; };
|
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "FixFileExtensions",
|
name: "FixFileExtensions",
|
||||||
authors: [EquicordDevs.thororen],
|
authors: [EquicordDevs.thororen],
|
||||||
|
@ -48,7 +46,7 @@ export default definePlugin({
|
||||||
predicate: () => !Settings.plugins.AnonymiseFileNames.enabled,
|
predicate: () => !Settings.plugins.AnonymiseFileNames.enabled,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
fixExt(upload: ExtUpload) {
|
fixExt(upload: Upload) {
|
||||||
const file = upload.filename;
|
const file = upload.filename;
|
||||||
const tarMatch = tarExtMatcher.exec(file);
|
const tarMatch = tarExtMatcher.exec(file);
|
||||||
const extIdx = tarMatch?.index ?? file.lastIndexOf(".");
|
const extIdx = tarMatch?.index ?? file.lastIndexOf(".");
|
||||||
|
|
|
@ -51,26 +51,27 @@ async function openCompleteQuestUI() {
|
||||||
const applicationId = quest.config.application.id;
|
const applicationId = quest.config.application.id;
|
||||||
const applicationName = quest.config.application.name;
|
const applicationName = quest.config.application.name;
|
||||||
const taskName = ["WATCH_VIDEO", "PLAY_ON_DESKTOP", "STREAM_ON_DESKTOP", "PLAY_ACTIVITY"].find(x => quest.config.taskConfig.tasks[x] != null);
|
const taskName = ["WATCH_VIDEO", "PLAY_ON_DESKTOP", "STREAM_ON_DESKTOP", "PLAY_ACTIVITY"].find(x => quest.config.taskConfig.tasks[x] != null);
|
||||||
|
const icon = `https://cdn.discordapp.com/quests/${quest.id}/${theme}/${quest.config.assets.gameTile}`;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const secondsNeeded = quest.config.taskConfig.tasks[taskName].target;
|
const secondsNeeded = quest.config.taskConfig.tasks[taskName].target;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const secondsDone = quest.userStatus?.progress?.[taskName]?.value ?? 0;
|
let secondsDone = quest.userStatus?.progress?.[taskName]?.value ?? 0;
|
||||||
const icon = `https://cdn.discordapp.com/assets/quests/${quest.id}/${theme}/${quest.config.assets.gameTile}`;
|
|
||||||
if (taskName === "WATCH_VIDEO") {
|
if (taskName === "WATCH_VIDEO") {
|
||||||
const tolerance = 2, speed = 10;
|
const maxFuture = 10, speed = 7, interval = 1;
|
||||||
const diff = Math.floor((Date.now() - new Date(quest.userStatus.enrolledAt).getTime()) / 1000);
|
const enrolledAt = new Date(quest.userStatus.enrolledAt).getTime();
|
||||||
const startingPoint = Math.min(Math.max(Math.ceil(secondsDone), diff), secondsNeeded);
|
|
||||||
const fn = async () => {
|
const fn = async () => {
|
||||||
for (let i = startingPoint; i <= secondsNeeded; i += speed) {
|
while (true) {
|
||||||
try {
|
const maxAllowed = Math.floor((Date.now() - enrolledAt) / 1000) + maxFuture;
|
||||||
await RestAPI.post({ url: `/quests/${quest.id}/video-progress`, body: { timestamp: Math.min(secondsNeeded, i + Math.random()) } });
|
const diff = maxAllowed - secondsDone;
|
||||||
} catch (ex) {
|
const timestamp = secondsDone + speed;
|
||||||
console.log("Failed to send increment of", i, ex);
|
if (diff >= speed) {
|
||||||
|
await RestAPI.post({ url: `/quests/${quest.id}/video-progress`, body: { timestamp: Math.min(secondsNeeded, timestamp + Math.random()) } });
|
||||||
|
secondsDone = Math.min(secondsNeeded, timestamp);
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, tolerance * 1000));
|
if (timestamp >= secondsNeeded) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if ((secondsNeeded - secondsDone) % speed !== 0) {
|
await new Promise(resolve => setTimeout(resolve, interval * 1000));
|
||||||
await RestAPI.post({ url: `/quests/${quest.id}/video-progress`, body: { timestamp: secondsNeeded } });
|
|
||||||
showNotification({
|
showNotification({
|
||||||
title: `${applicationName} - Quest Completer`,
|
title: `${applicationName} - Quest Completer`,
|
||||||
body: "Quest Completed.",
|
body: "Quest Completed.",
|
||||||
|
@ -81,10 +82,9 @@ async function openCompleteQuestUI() {
|
||||||
fn();
|
fn();
|
||||||
showNotification({
|
showNotification({
|
||||||
title: `${applicationName} - Quest Completer`,
|
title: `${applicationName} - Quest Completer`,
|
||||||
body: `Wait for ${Math.ceil((secondsNeeded - startingPoint) / speed * tolerance)} more seconds.`,
|
body: `Spoofing video for ${applicationName}.`,
|
||||||
icon: icon,
|
icon: icon,
|
||||||
});
|
});
|
||||||
console.log(`Spoofing video for ${applicationName}.`);
|
|
||||||
} else if (taskName === "PLAY_ON_DESKTOP") {
|
} else if (taskName === "PLAY_ON_DESKTOP") {
|
||||||
RestAPI.get({ url: `/applications/public?application_ids=${applicationId}` }).then(res => {
|
RestAPI.get({ url: `/applications/public?application_ids=${applicationId}` }).then(res => {
|
||||||
const appData = res.body[0];
|
const appData = res.body[0];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue