diff --git a/src/music/PlayerManager.mjs b/src/music/PlayerManager.mjs index 29112a4..992c4e2 100644 --- a/src/music/PlayerManager.mjs +++ b/src/music/PlayerManager.mjs @@ -125,6 +125,49 @@ export class PlayerManager { return null; } + /** + * Check whether a player counts as "busy" — i.e. the bot is actively + * serving that channel: a track is loaded (playing or paused), the queue + * still has songs, a radio stream is running, or the channel is parked in + * 24/7 (stay) mode. Used by {@link getPlayer} to warn users instead of + * silently moving the bot out of a channel where people are listening. + * @param {Player} player - The player to inspect. + * @returns {boolean} True if the player is playing/staying for its channel. + */ + _isPlayerBusy(player) { + if (!player || player._destroyed) return false; + try { + if (player._get247Mode?.() === "on") return true; + if (player.queue?.getCurrent?.()) return true; + if (player.queue && !player.queue.isEmpty()) return true; + if (player._wasRadio) return true; + } catch (e) { + logger.warn("[PlayerManager] _isPlayerBusy check failed:", e?.message); + } + return false; + } + + /** + * Check whether a player is actively playing audio — a track is loaded + * (playing or paused), the queue still has songs, or a radio stream is + * running. Stricter than {@link _isPlayerBusy}, which also counts idle + * 24/7 stays. Picks which of the two "busy elsewhere" warnings to show: + * the "already playing music" one, or the "staying in 24/7 mode" one. + * @param {Player} player - The player to inspect. + * @returns {boolean} True if audio is actively playing (or paused). + */ + _isPlayerActivelyPlaying(player) { + if (!player || player._destroyed) return false; + try { + if (player.queue?.getCurrent?.()) return true; + if (player.queue && !player.queue.isEmpty()) return true; + if (player._wasRadio) return true; + } catch (e) { + logger.warn("[PlayerManager] _isPlayerActivelyPlaying check failed:", e?.message); + } + return false; + } + /** Find a player by its channel ID across all guilds. @param {string} channelId @returns {Player|null} */ getPlayerByChannelId(channelId) { const cId = cleanId(channelId); @@ -199,6 +242,25 @@ export class PlayerManager { } if (shouldJoin) { + const busyPlayers = serverPlayers.filter(([, player]) => this._isPlayerBusy(player)); + if (busyPlayers.length > 0) { + const playingPlayers = busyPlayers.filter(([, player]) => this._isPlayerActivelyPlaying(player)); + const relevantPlayers = playingPlayers.length > 0 ? playingPlayers : busyPlayers; + const busyChannelList = relevantPlayers + .map(([chId, player]) => `<#${getPlayerChannelId(player, chId)}>`) + .join(" or "); + const prefix = this.commands.getPrefix(guildId); + const key = playingPlayers.length > 0 + ? "responses._common.busyPlayingInOtherVoiceChannel" + : "responses._common.busyStayingInOtherVoiceChannel"; + message.reply( + this._t(message, key, { + channels: busyChannelList, + prefix, + }) + ); + return null; + } return this.initPlayer(message, userChannelId); } diff --git a/storage/locales/bot/ar-SA.json b/storage/locales/bot/ar-SA.json index 1349158..0f65e21 100644 --- a/storage/locales/bot/ar-SA.json +++ b/storage/locales/bot/ar-SA.json @@ -202,6 +202,8 @@ "noVoiceChannel": "⚠️ يرجى الانضمام إلى قناة صوتية أولاً.", "noVoiceStrict": "⚠️ يجب عليك الانضمام إلى قناة صوتية لاستخدام هذا الأمر.", "alreadyInChannel": "⚠️ أنا أعزف بالفعل في {{channels}}. انضم إلى تلك القناة أو استخدم `{{prefix}}play` لبدء الموسيقى في قناتك.", + "busyPlayingInOtherVoiceChannel": "🎵 أقوم حاليًا بتشغيل الموسيقى في قناة صوتية أخرى: {{channels}}!\n🎧 **انضم إلى تلك القناة** للاستماع.\n💡 أو استخدم `{{prefix}}join` إذا كنت تريد أن أنتقل إلى قناتك.", + "busyStayingInOtherVoiceChannel": "🤖 أنا حاليًا في قناة صوتية أخرى: {{channels}} (وضع 24/7).\n🎧 انضم إلى تلك القناة لتكون معي، أو استخدم `{{prefix}}join` لنقلي إلى قناتك.", "notInVoice": "أنا لست في قناة صوتية.", "queueEmpty": "📭 قائمة الانتظار فارغة. استخدم `{{prefix}}play` لإضافة أغاني!", "queueEnded": "🎵 قائمة الانتظار انتهت — لا يوجد شيء لتشغيله. أضف المزيد من الأغاني باستخدام `{{prefix}}play`!", diff --git a/storage/locales/bot/ckb.json b/storage/locales/bot/ckb.json index 059750e..54a859d 100644 --- a/storage/locales/bot/ckb.json +++ b/storage/locales/bot/ckb.json @@ -202,6 +202,8 @@ "noVoiceChannel": "⚠️ تکایە سەرەتا بەشداری کەناڵێکی دەنگی بکە.", "noVoiceStrict": "⚠️ پێویستە سەرەتا بەشداری کەناڵێکی دەنگی بکەیت بۆ بەکارهێنانی ئەم فەرمانە.", "alreadyInChannel": "⚠️ من پێشتر لە {{channels}} پەخش دەکەم. بەشداری ئەو کەناڵە بکە یان `{{prefix}}play` بەکاربهێنە بۆ دەستپێکردنی موزیک لە کەناڵەکەت.", + "busyPlayingInOtherVoiceChannel": "🎵 ئێستا لە کەناڵێکی دەنگی دیکە مۆزیک لێدەدەم: {{channels}}!\n🎧 **بەشداری ئەو کەناڵە بکە** بۆ گوێگرتن.\n💡 یان `{{prefix}}join` بەکاربهێنە ئەگەر دەتەوێت بگوازرێمەوە بۆ کەناڵەکەت.", + "busyStayingInOtherVoiceChannel": "🤖 ئێستا لە کەناڵێکی دەنگی دیکە دەمێنمەوە: {{channels}} (دۆخی 24/7).\n🎧 بۆ ئەوەی لەگەڵم بیت بەشداری ئەو کەناڵە بکە، یان `{{prefix}}join` بەکاربهێنە بۆ گواستنەوەم بۆ کەناڵەکەت.", "notInVoice": "من لە کەناڵێکی دەنگیدا نییم.", "queueEmpty": "📭 ڕیزبەندییەکە بەتاڵە. `{{prefix}}play` بەکاربهێنە بۆ زیادکردنی گۆرانی!", "queueEnded": "🎵 ڕیزبەندییەکە تەواو بوو — هیچ شتێک نەماوە بۆ پەخشکردن. گۆرانی زیاتر زیاد بکە بە `{{prefix}}play`!", diff --git a/storage/locales/bot/de-DE.json b/storage/locales/bot/de-DE.json index a1d9a78..8e34268 100644 --- a/storage/locales/bot/de-DE.json +++ b/storage/locales/bot/de-DE.json @@ -202,6 +202,8 @@ "noVoiceChannel": "⚠️ Bitte trete zuerst einem Sprachkanal bei.", "noVoiceStrict": "⚠️ Du musst einem Sprachkanal beitreten, um diesen Befehl zu nutzen.", "alreadyInChannel": "⚠️ Ich spiele bereits in {{channels}}. Trete diesem Kanal bei oder nutze `{{prefix}}play`, um Musik in deinem Kanal zu starten.", + "busyPlayingInOtherVoiceChannel": "🎵 Ich spiele gerade Musik in einem anderen Sprachkanal: {{channels}}!\n🎧 **Tritt diesem Kanal bei**, um mitzuhören.\n💡 Oder benutze `{{prefix}}join`, wenn ich in deinen Kanal wechseln soll.", + "busyStayingInOtherVoiceChannel": "🤖 Ich halte mich gerade in einem anderen Sprachkanal auf: {{channels}} (24/7-Modus).\n🎧 Tritt diesem Kanal bei, um bei mir zu sein, oder benutze `{{prefix}}join`, um mich in deinen Kanal zu holen.", "notInVoice": "Ich bin in keinem Sprachkanal.", "queueEmpty": "📭 Die Warteschlange ist leer. Nutze `{{prefix}}play`, um Songs hinzuzufügen!", "queueEnded": "🎵 Die Warteschlange ist zu Ende — nichts mehr abzuspielen. Füge weitere Songs mit `{{prefix}}play` hinzu!", diff --git a/storage/locales/bot/en.json b/storage/locales/bot/en.json index ca97f8e..8478135 100644 --- a/storage/locales/bot/en.json +++ b/storage/locales/bot/en.json @@ -202,6 +202,8 @@ "noVoiceChannel": "⚠️ I can't find you in a voice channel. Please join one first, or if you're already in one, make sure I have **View Channel** and **Connect** permissions.", "noVoiceStrict": "⚠️ I can't find you in a voice channel. Please join one, or if you're already in one, make sure I have **View Channel** and **Connect** permissions.", "alreadyInChannel": "⚠️ I'm already playing in {{channels}}. Join that channel or use `{{prefix}}play` to start music in your channel.", + "busyPlayingInOtherVoiceChannel": "🎵 I'm already playing music in another voice channel: {{channels}}!\n🎧 **Join that channel** to listen along.\n💡 Or use `{{prefix}}join` if you want me to move to your channel instead.", + "busyStayingInOtherVoiceChannel": "🤖 I'm currently staying in another voice channel: {{channels}} (24/7 mode).\n🎧 Join that channel to hang out with me, or use `{{prefix}}join` to move me to your channel.", "notInVoice": "I'm not in a voice channel.", "queueEmpty": "📭 The queue is empty. Use `{{prefix}}play` to add songs!", "queueEnded": "🎵 The queue has ended — nothing left to play. Add more songs with `{{prefix}}play`!", diff --git a/storage/locales/bot/pt-BR.json b/storage/locales/bot/pt-BR.json index 604f144..e070c04 100644 --- a/storage/locales/bot/pt-BR.json +++ b/storage/locales/bot/pt-BR.json @@ -202,6 +202,8 @@ "noVoiceChannel": "⚠️ Por favor, entre em um canal de voz primeiro.", "noVoiceStrict": "⚠️ Você precisa entrar em um canal de voz para usar este comando.", "alreadyInChannel": "⚠️ Já estou tocando em {{channels}}. Entre nesse canal ou use `{{prefix}}play` para começar a tocar no seu canal.", + "busyPlayingInOtherVoiceChannel": "🎵 Já estou tocando música em outro canal de voz: {{channels}}!\n🎧 **Entre nesse canal** para ouvir junto.\n💡 Ou use `{{prefix}}join` se quiser que eu mude para o seu canal.", + "busyStayingInOtherVoiceChannel": "🤖 No momento estou em outro canal de voz: {{channels}} (modo 24/7).\n🎧 Entre nesse canal para ficar comigo, ou use `{{prefix}}join` para me mover para o seu canal.", "notInVoice": "Não estou em um canal de voz.", "queueEmpty": "📭 A fila está vazia. Use `{{prefix}}play` para adicionar músicas!", "queueEnded": "🎵 A fila acabou — nada mais para tocar. Adicione mais músicas com `{{prefix}}play`!", diff --git a/storage/locales/bot/tr.json b/storage/locales/bot/tr.json index 7a2f5bb..de44ff0 100644 --- a/storage/locales/bot/tr.json +++ b/storage/locales/bot/tr.json @@ -202,6 +202,8 @@ "noVoiceChannel": "⚠️ Lütfen önce bir ses kanalına katılın.", "noVoiceStrict": "⚠️ Bu komutu kullanmak için bir ses kanalına katılmanız gerekiyor.", "alreadyInChannel": "⚠️ Zaten {{channels}} kanalında çalıyorum. O kanala katılın veya kendi kanalınızda müzik başlatmak için `{{prefix}}play` kullanın.", + "busyPlayingInOtherVoiceChannel": "🎵 Şu anda başka bir ses kanalında müzik çalıyorum: {{channels}}!\n🎧 Dinlemek için **o kanala katıl**.\n💡 Benim senin kanalına geçmemi istiyorsan `{{prefix}}join` komutunu kullan.", + "busyStayingInOtherVoiceChannel": "🤖 Şu anda başka bir ses kanalında kalıyorum: {{channels}} (24/7 modu).\n🎧 Benimle vakit geçirmek için o kanala katıl ya da beni taşımak için `{{prefix}}join` komutunu kullan.", "notInVoice": "Bir ses kanalında değilim.", "queueEmpty": "📭 Kuyruk boş. Şarkı eklemek için `{{prefix}}play` kullanın!", "queueEnded": "🎵 Kuyruk bitti — çalacak bir şey kalmadı. Daha fazla şarkı eklemek için `{{prefix}}play` kullanın!",