INNER CODE UNIT · JavaScript
sleep
nyxxbit/discord-quest-completer · index.js:169
const sleep = ms => new Promise(r => setTimeout(r, ms));
const rnd = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
// Escape server-controlled strings before they touch innerHTML. Quest and reward names
// come from Discord API fields (questName, reward name) and can carry markup; a crafted
// title like "><img src=x onerror=...> would otherwise inject into the dashboard DOM,
// the exact inline-injection Discord's CSP exists to stop.
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
// expiresAt is occasionally missing/malformed mid-rollout. new Date(undefined) is NaN and
// `NaN > now` is always false, which would silently drop the quest with no log. Treat an
// unparseable expiry as "not expired" so we attempt the quest instead of hiding it.
// Discord keeps its own expiry verdict in QuestStore, refreshed on every user-status update
// and rearmed by a timer, and its default when it has no entry is NOT expired. Ask it first
// and only fall back to reading the timestamp ourselves.
const notExpired = q => {
try {
const store = Mods.QuestStore;