diff --git a/web/src/App.tsx b/web/src/App.tsx index a4b9c86..69fb448 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -27,6 +27,8 @@ export default function App() { const [clock, setClock] = useState(() => new Intl.DateTimeFormat('de-DE', { hour: '2-digit', minute: '2-digit', hour12: false, timeZone: 'Europe/Berlin' }).format(new Date())); const [totalPlays, setTotalPlays] = useState(0); const [mediaUrl, setMediaUrl] = useState(''); + const [chaosMode, setChaosMode] = useState(false); + const chaosIntervalRef = useRef(null); useEffect(() => { (async () => { @@ -165,6 +167,69 @@ export default function App() { } } + // CHAOS Mode Funktionen + const startChaosMode = async () => { + if (!selected || !sounds.length) return; + + const playRandomSound = async () => { + const randomSound = sounds[Math.floor(Math.random() * sounds.length)]; + const [guildId, channelId] = selected.split(':'); + try { + await playSound(randomSound.name, guildId, channelId, volume, randomSound.relativePath); + } catch (e: any) { + console.error('Chaos sound play failed:', e); + } + }; + + // Sofort ersten Sound abspielen + await playRandomSound(); + + // 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; + }; + + const stopChaosMode = async () => { + if (chaosIntervalRef.current) { + clearInterval(chaosIntervalRef.current); + chaosIntervalRef.current = null; + } + + // Alle Sounds stoppen (wie Panic Button) + if (selected) { + const [guildId] = selected.split(':'); + try { + await fetch(`/api/stop?guildId=${encodeURIComponent(guildId)}`, { method: 'POST' }); + } catch (e: any) { + console.error('Chaos stop failed:', e); + } + } + }; + + const toggleChaosMode = async () => { + if (chaosMode) { + setChaosMode(false); + await stopChaosMode(); + } else { + setChaosMode(true); + await startChaosMode(); + } + }; + + // Cleanup bei Komponenten-Unmount + useEffect(() => { + return () => { + if (chaosIntervalRef.current) { + clearInterval(chaosIntervalRef.current); + } + }; + }, []); + return (
@@ -204,6 +269,16 @@ export default function App() { +