const queues = new Map(); const history = new Map(); // ✅ repeatAll snapshot — full queue saved when repeat all starts const repeatAllSnapshots = new Map(); function getQueue(guildId) { if (!queues.has(guildId)) queues.set(guildId, []); return queues.get(guildId); } function add(guildId, song) { getQueue(guildId).push(song); } function next(guildId) { const q = getQueue(guildId); const song = q.shift(); if (song) { if (!history.has(guildId)) history.set(guildId, []); history.get(guildId).push(song); if (history.get(guildId).length > 50) history.get(guildId).shift(); } return song || null; } function getPrev(guildId) { const h = history.get(guildId) || []; if (h.length < 2) return null; return h[h.length - 2]; } function clear(guildId) { queues.set(guildId, []); repeatAllSnapshots.delete(guildId); } function removeAt(guildId, index) { const q = getQueue(guildId); if (index < 0 || index >= q.length) return null; return q.splice(index, 1)[0]; } function removeDuplicates(guildId) { const q = getQueue(guildId); const seen = new Set(); const deduped = []; let removed = 0; for (const song of q) { if (!seen.has(song.url)) { seen.add(song.url); deduped.push(song); } else { removed++; } } queues.set(guildId, deduped); return removed; } // ✅ Save full queue snapshot for repeat all function saveRepeatAllSnapshot(guildId, allSongs) { repeatAllSnapshots.set(guildId, allSongs.map(s => ({ ...s }))); } // ✅ Restore snapshot when queue runs out in repeat all mode function restoreRepeatAllSnapshot(guildId) { const snap = repeatAllSnapshots.get(guildId); if (!snap || snap.length === 0) return false; queues.set(guildId, snap.map(s => ({ ...s }))); return true; } module.exports = { getQueue, add, next, getPrev, clear, removeAt, removeDuplicates, saveRepeatAllSnapshot, restoreRepeatAllSnapshot };