Skip to content

Commit

Permalink
[discordPresence] Throttle presence updates (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotForMyCV authored Jul 19, 2024
1 parent bd566a0 commit d6e7243
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion plugins/discordPresence/discordPresence.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const player = () => document.querySelector("#VideoJsPlayer video");

let WAITING_FOR_REFRESH = true;
let SCENE_ID = null;
/** @type {FlattenedSceneData?} */ let cachedSceneData;

Expand Down Expand Up @@ -201,7 +202,16 @@
);
}

async function setDiscordActivity() {
async function setDiscordActivity(event) {
if (event?.type === "timeupdate") {
if (!WAITING_FOR_REFRESH) {
return;
}

WAITING_FOR_REFRESH = false;
setTimeout(() => (WAITING_FOR_REFRESH = true), 5000);
}

const sceneData = await getSceneData(SCENE_ID);
if (!sceneData) return;

Expand Down
2 changes: 1 addition & 1 deletion plugins/discordPresence/discordPresence.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Discord Presence
description: Sets currently playing scene data as your Discord status. See README for prerequisites and config options (blue hyperlink next to enable/disable button)
url: https://github.com/stashapp/CommunityScripts/tree/main/plugins/discordPresence
# requires: CommunityScriptsUILibrary
version: 1.1
version: 1.2
settings:
discordClientId:
displayName: Custom Discord application ID
Expand Down

0 comments on commit d6e7243

Please sign in to comment.