mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
fix(music): resolve ghost players on channel/guild delete and fix clear command NaN range
This commit is contained in:
1 parent
a780ec22c8
commit
618ecb1a0b
9 files changed
+94
-13
No files matched your search
+6
-4
@@ -39,13 +39,15 @@ export async function run(msg, data) {
|
||||
const p = await this.getPlayer(msg, false, false, false);
|
||||
if (!p) return;
|
||||
|
||||
const fromVal = data?.get?.("from")?.value;
|
||||
const toVal = data?.get?.("to")?.value;
|
||||
const rawFrom = data?.get?.("from")?.value;
|
||||
const rawTo = data?.get?.("to")?.value;
|
||||
const fromVal = (typeof rawFrom === "number" && Number.isFinite(rawFrom)) ? rawFrom : null;
|
||||
const toVal = (typeof rawTo === "number" && Number.isFinite(rawTo)) ? rawTo : null;
|
||||
|
||||
if (fromVal != null && fromVal !== undefined) {
|
||||
if (fromVal !== null) {
|
||||
if (fromVal < 1) return msg.replyEmbed("Queue position must be 1 or greater.").catch(() => {});
|
||||
const startIdx = Math.floor(fromVal) - 1;
|
||||
const endIdx = (toVal != null && toVal !== undefined && toVal >= 1) ? Math.floor(toVal) - 1 : startIdx;
|
||||
const endIdx = (toVal !== null && toVal >= 1) ? Math.floor(toVal) - 1 : startIdx;
|
||||
const res = p.removeRange(startIdx, endIdx);
|
||||
return msg.replyEmbed(res).catch(() => {});
|
||||
}
|
||||
|
||||
@@ -412,7 +412,10 @@ export class CommandHandler extends EventEmitter {
|
||||
const e = this._optionTypeError(errGuildId2, o, value, previous);
|
||||
return { opts, error: (!external) ? (this.replyHandler(e, msg) ?? true) : e };
|
||||
}
|
||||
if (o.empty(value)) value = o.defaultValue;
|
||||
if (o.empty(value)) {
|
||||
if (o.defaultValue === undefined) continue;
|
||||
value = o.defaultValue;
|
||||
}
|
||||
opts.push({ value: o.formatInput(value, this.client, msg.message), name: o.name, id: o.id, uid: o.uid });
|
||||
usedOptions.push(o.uid);
|
||||
previous += " " + value;
|
||||
|
||||
@@ -211,8 +211,11 @@ export class Option {
|
||||
case "text":
|
||||
case "string":
|
||||
return i;
|
||||
case "number":
|
||||
return parseFloat(i);
|
||||
case "number": {
|
||||
if (i === undefined || i === null || i === "") return null;
|
||||
const parsed = parseFloat(i);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
case "boolean":
|
||||
return i?.toLowerCase() === "true" || i === "1";
|
||||
case "choice":
|
||||
|
||||
@@ -151,7 +151,7 @@ export class PlayerManager {
|
||||
* @returns {boolean} True if the player is playing/staying for its channel.
|
||||
*/
|
||||
_isPlayerBusy(player) {
|
||||
if (!player || player._destroyed) return false;
|
||||
if (!player || player._destroyed || isPlayerConnectionDead(player)) return false;
|
||||
try {
|
||||
if (player._get247Mode?.() === "on") return true;
|
||||
if (player.queue?.getCurrent?.()) return true;
|
||||
@@ -173,7 +173,7 @@ export class PlayerManager {
|
||||
* @returns {boolean} True if audio is actively playing (or paused).
|
||||
*/
|
||||
_isPlayerActivelyPlaying(player) {
|
||||
if (!player || player._destroyed) return false;
|
||||
if (!player || player._destroyed || isPlayerConnectionDead(player)) return false;
|
||||
try {
|
||||
if (player.queue?.getCurrent?.()) return true;
|
||||
if (player.queue && !player.queue.isEmpty()) return true;
|
||||
|
||||
@@ -263,6 +263,7 @@ const DisplayMixin = {
|
||||
*/
|
||||
announceSong(s) {
|
||||
if (!s) return;
|
||||
if (this._destroyed || this.leaving || (!this._voiceConn && !this.connection)) return;
|
||||
|
||||
if (s.type === "radio") {
|
||||
this.emit("message", { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(this._t("responses.radio.nowPlaying", {
|
||||
|
||||
@@ -720,6 +720,7 @@ class Player extends EventEmitter {
|
||||
this._onLavalinkPlayerDisconnect = null;
|
||||
}
|
||||
}
|
||||
this.queue?.reset();
|
||||
this.leaving = true;
|
||||
this._stopInactivityTimer();
|
||||
this._autoplay = false;
|
||||
@@ -747,6 +748,7 @@ class Player extends EventEmitter {
|
||||
vm.leaveChannel(this._channelId);
|
||||
} catch(e) { /* best effort */ }
|
||||
}
|
||||
this.removeAllListeners();
|
||||
} catch (e) {
|
||||
logger.error("[Player] destroy error:", e.message);
|
||||
}
|
||||
|
||||
@@ -84,10 +84,14 @@ export class Queue extends EventEmitter {
|
||||
*/
|
||||
removeRange(from, to) {
|
||||
if (this.isEmpty()) return "The queue is empty.";
|
||||
if (typeof from !== "number" || typeof to !== "number" || !Number.isFinite(from) || !Number.isFinite(to)) {
|
||||
return "Invalid range.";
|
||||
}
|
||||
const start = Math.max(0, Math.min(from, to));
|
||||
const end = Math.min(this.data.length - 1, Math.max(from, to));
|
||||
if (start >= this.data.length) return "Index out of bounds";
|
||||
if (start >= this.data.length || end < start) return "Index out of bounds";
|
||||
const deleteCount = (end - start) + 1;
|
||||
if (deleteCount <= 0) return "Invalid range.";
|
||||
const removed = this.data.splice(start, deleteCount);
|
||||
this.emit("queue", { type: "removeRange", data: { start, end, count: removed.length, old: this.data.slice(), removed, new: this.data } });
|
||||
return { count: removed.length, removed };
|
||||
|
||||
@@ -416,6 +416,48 @@ class GatewayHandler {
|
||||
client.on(Events.VoiceStatesSync, (data) => {
|
||||
this._handleVoiceStatesSync(data);
|
||||
});
|
||||
|
||||
client.on(Events.ChannelDelete ?? "channelDelete", (channel) => {
|
||||
this._handleChannelDelete(channel);
|
||||
});
|
||||
}
|
||||
|
||||
_handleChannelDelete(channel) {
|
||||
const channelId = cleanId(channel?.id ?? channel?._id);
|
||||
if (!channelId) return;
|
||||
|
||||
const { remix } = this;
|
||||
const guildId = cleanId(channel?.guildId ?? channel?.guild?.id ?? "");
|
||||
|
||||
const player = remix?.players?.playerMap?.get?.(channelId)
|
||||
?? [...(remix?.players?.playerMap?.values?.() ?? [])].find(p => cleanId(p?._channelId) === channelId || cleanId(p?._home247Channel) === channelId);
|
||||
|
||||
if (player) {
|
||||
logger.voice(`[ChannelDelete] Voice channel ${channelId} deleted — destroying associated player.`);
|
||||
remix.players.playerMap.delete(channelId);
|
||||
const homeCh = cleanId(player._home247Channel ?? "");
|
||||
if (homeCh && homeCh !== channelId) remix.players.playerMap.delete(homeCh);
|
||||
remix.players._unindexPlayer?.(player._guildId, channelId);
|
||||
|
||||
const pendingScrobble = remix.players._pendingScrobbleTimers?.get?.(channelId);
|
||||
if (pendingScrobble) {
|
||||
clearTimeout(pendingScrobble.timer);
|
||||
remix.players._pendingScrobbleTimers.delete(channelId);
|
||||
}
|
||||
|
||||
try {
|
||||
player.queue?.reset?.();
|
||||
player.destroy();
|
||||
} catch (e) {
|
||||
logger.warn("[ChannelDelete] Player destroy error:", e?.message);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (guildId) {
|
||||
remix.voiceCache?.removeChannel?.(guildId, channelId);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -373,11 +373,35 @@ const GuildSync = {
|
||||
|
||||
logger.guild(
|
||||
`[GuildDelete] Received GuildDelete for server ${guildId} — ` +
|
||||
`skipping removal (24/7 removal system disabled). ` +
|
||||
`Settings and players are preserved. If the server truly removed the bot, ` +
|
||||
`the GuildCreate handler will re-initialise on re-invite.`
|
||||
`cleaning up active players while preserving settings for potential re-invite.`
|
||||
);
|
||||
|
||||
const guildChannels = remix.players?._guildPlayerIndex?.get?.(cleanGuildId);
|
||||
if (guildChannels) {
|
||||
for (const channelId of [...guildChannels]) {
|
||||
const p = remix.players.playerMap.get(channelId);
|
||||
if (p) {
|
||||
remix.players.playerMap.delete(channelId);
|
||||
const homeCh = cleanId(p._home247Channel ?? "");
|
||||
if (homeCh && homeCh !== channelId) remix.players.playerMap.delete(homeCh);
|
||||
try {
|
||||
p.queue?.reset?.();
|
||||
p.destroy();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
remix.players._guildPlayerIndex.delete(cleanGuildId);
|
||||
}
|
||||
for (const [key, p] of [...(remix.players?.playerMap?.entries?.() ?? [])]) {
|
||||
if (cleanId(p?._guildId) === cleanGuildId) {
|
||||
remix.players.playerMap.delete(key);
|
||||
try {
|
||||
p.queue?.reset?.();
|
||||
p.destroy();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
remix.voiceCache.removeGuild(cleanGuildId);
|
||||
for (const [stateKey, info] of [...this._prevVoiceState]) {
|
||||
if (cleanId(info.guildId) === cleanGuildId)
|
||||
|
||||
Reference in new issue
Block a user