From ec71858345295074aec8845d00edf85a366b70eb Mon Sep 17 00:00:00 2001 From: vibe-bot Date: Sat, 9 Aug 2025 14:58:55 +0200 Subject: [PATCH] =?UTF-8?q?Nightly:=20CHAOS-Logik=20angepasst=20=20zuf?= =?UTF-8?q?=C3=A4llige=20Wiedergabe=20alle=2013=20Minuten=20via=20rekursiv?= =?UTF-8?q?em=20setTimeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/App.tsx | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 4f92371..f56774e 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -28,7 +28,7 @@ export default function App() { const [totalPlays, setTotalPlays] = useState(0); const [mediaUrl, setMediaUrl] = useState(''); const [chaosMode, setChaosMode] = useState(false); - const chaosIntervalRef = useRef(null); + const chaosTimeoutRef = useRef(null); useEffect(() => { (async () => { @@ -167,12 +167,14 @@ export default function App() { } } - // CHAOS Mode Funktionen + // CHAOS Mode Funktionen (zufällige Wiedergabe alle 1-3 Minuten) const startChaosMode = async () => { if (!selected || !sounds.length) return; - + const playRandomSound = async () => { - const randomSound = sounds[Math.floor(Math.random() * sounds.length)]; + const pool = sounds; + if (!pool.length || !selected) return; + const randomSound = pool[Math.floor(Math.random() * pool.length)]; const [guildId, channelId] = selected.split(':'); try { await playSound(randomSound.name, guildId, channelId, volume, randomSound.relativePath); @@ -181,23 +183,22 @@ export default function App() { } }; - // Sofort ersten Sound abspielen - await playRandomSound(); + const scheduleNextPlay = async () => { + if (!chaosMode) return; + await playRandomSound(); + const delay = 60_000 + Math.floor(Math.random() * 120_000); // 1-3 Minuten + chaosTimeoutRef.current = window.setTimeout(scheduleNextPlay, delay); + }; - // Interval für weitere zufällige Sounds (2-6 Minuten) - const interval = setInterval(async () => { - if (chaosMode) { - await playRandomSound(); - } - }, Math.random() * (6 - 2) * 60 * 1000 + 2 * 60 * 1000); // 2-6 Minuten - - chaosIntervalRef.current = interval; + // ersten Start zufällig zwischen 1-3 Minuten planen + const firstDelay = 60_000 + Math.floor(Math.random() * 120_000); + chaosTimeoutRef.current = window.setTimeout(scheduleNextPlay, firstDelay); }; const stopChaosMode = async () => { - if (chaosIntervalRef.current) { - clearInterval(chaosIntervalRef.current); - chaosIntervalRef.current = null; + if (chaosTimeoutRef.current) { + clearTimeout(chaosTimeoutRef.current); + chaosTimeoutRef.current = null; } // Alle Sounds stoppen (wie Panic Button) @@ -224,8 +225,8 @@ export default function App() { // Cleanup bei Komponenten-Unmount useEffect(() => { return () => { - if (chaosIntervalRef.current) { - clearInterval(chaosIntervalRef.current); + if (chaosTimeoutRef.current) { + clearTimeout(chaosTimeoutRef.current); } }; }, []);