Nightly: CHAOS-Logik angepasst zufällige Wiedergabe alle 13 Minuten via rekursivem setTimeout
This commit is contained in:
parent
d56c4dc0ed
commit
ec71858345
1 changed files with 20 additions and 19 deletions
|
|
@ -28,7 +28,7 @@ export default function App() {
|
||||||
const [totalPlays, setTotalPlays] = useState<number>(0);
|
const [totalPlays, setTotalPlays] = useState<number>(0);
|
||||||
const [mediaUrl, setMediaUrl] = useState<string>('');
|
const [mediaUrl, setMediaUrl] = useState<string>('');
|
||||||
const [chaosMode, setChaosMode] = useState<boolean>(false);
|
const [chaosMode, setChaosMode] = useState<boolean>(false);
|
||||||
const chaosIntervalRef = useRef<number | null>(null);
|
const chaosTimeoutRef = useRef<number | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(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 () => {
|
const startChaosMode = async () => {
|
||||||
if (!selected || !sounds.length) return;
|
if (!selected || !sounds.length) return;
|
||||||
|
|
||||||
const playRandomSound = async () => {
|
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(':');
|
const [guildId, channelId] = selected.split(':');
|
||||||
try {
|
try {
|
||||||
await playSound(randomSound.name, guildId, channelId, volume, randomSound.relativePath);
|
await playSound(randomSound.name, guildId, channelId, volume, randomSound.relativePath);
|
||||||
|
|
@ -181,23 +183,22 @@ export default function App() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sofort ersten Sound abspielen
|
const scheduleNextPlay = async () => {
|
||||||
|
if (!chaosMode) return;
|
||||||
await playRandomSound();
|
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)
|
// ersten Start zufällig zwischen 1-3 Minuten planen
|
||||||
const interval = setInterval(async () => {
|
const firstDelay = 60_000 + Math.floor(Math.random() * 120_000);
|
||||||
if (chaosMode) {
|
chaosTimeoutRef.current = window.setTimeout(scheduleNextPlay, firstDelay);
|
||||||
await playRandomSound();
|
|
||||||
}
|
|
||||||
}, Math.random() * (6 - 2) * 60 * 1000 + 2 * 60 * 1000); // 2-6 Minuten
|
|
||||||
|
|
||||||
chaosIntervalRef.current = interval;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const stopChaosMode = async () => {
|
const stopChaosMode = async () => {
|
||||||
if (chaosIntervalRef.current) {
|
if (chaosTimeoutRef.current) {
|
||||||
clearInterval(chaosIntervalRef.current);
|
clearTimeout(chaosTimeoutRef.current);
|
||||||
chaosIntervalRef.current = null;
|
chaosTimeoutRef.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alle Sounds stoppen (wie Panic Button)
|
// Alle Sounds stoppen (wie Panic Button)
|
||||||
|
|
@ -224,8 +225,8 @@ export default function App() {
|
||||||
// Cleanup bei Komponenten-Unmount
|
// Cleanup bei Komponenten-Unmount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
if (chaosIntervalRef.current) {
|
if (chaosTimeoutRef.current) {
|
||||||
clearInterval(chaosIntervalRef.current);
|
clearTimeout(chaosTimeoutRef.current);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue