mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
hotfix
This commit is contained in:
1 parent
a78edeaa9a
commit
4a62defe1b
6 files changed
+142
-171
No files matched your search
@@ -28,8 +28,7 @@ export async function run(msg, data) {
|
||||
if (!targetChannel) return msg.reply(embed(this.t(msg, "responses.forceleave.channelNotFound")));
|
||||
if (cleanId(msg.message.guildId) !== cleanId(targetChannel.guildId))
|
||||
return msg.reply(embed(this.t(msg, "responses.forceleave.wrongServer")));
|
||||
const p = this.players.playerMap.get(cid)
|
||||
?? [...this.players.playerMap.values()].find((player) => cleanId(player?._channelId) === cid);
|
||||
const p = this.players.findPlayerEntryByChannelId(cid)?.player ?? null;
|
||||
if (!p) return msg.reply(embed(this.t(msg, "responses.forceleave.playerNotFound")));
|
||||
if (!p.connection) return msg.reply(embed(this.t(msg, "responses.forceleave.playerNotInit")));
|
||||
await this.players.leave(msg, cid);
|
||||
|
||||
+25
-107
@@ -1,5 +1,4 @@
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { get247ChannelMode } from "../src/constants/Helpers247.mjs";
|
||||
@@ -23,22 +22,6 @@ function cleanId(value) {
|
||||
return String(value ?? "").replace(/\D/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the guild ID from a player entry.
|
||||
* Uses _guildId if set (populated after join() completes), otherwise falls
|
||||
* back to the client channel cache. This is necessary because in the
|
||||
* multi-voice scenario _guildId can still be null for a freshly-joined player,
|
||||
* which caused guildPlayers to be empty and leave to report "not in voice".
|
||||
*/
|
||||
function resolvePlayerGuildId(player, mapKey, client) {
|
||||
const direct = cleanId(player?._guildId);
|
||||
if (direct) return direct;
|
||||
const cid = cleanId(player?._channelId ?? mapKey);
|
||||
if (!cid) return "";
|
||||
const ch = client?.channels?.get?.(cid);
|
||||
return cleanId(ch?.guildId ?? ch?.guild?.id ?? ch?.server_id ?? ch?.serverId);
|
||||
}
|
||||
|
||||
export async function run(msg, data) {
|
||||
const guildId = msg.channel?.guild?.id
|
||||
?? msg.channel?.guildId
|
||||
@@ -49,15 +32,7 @@ export async function run(msg, data) {
|
||||
?? msg.message?.serverId;
|
||||
const cleanGuildId = cleanId(guildId);
|
||||
|
||||
// Gather all active players in this guild.
|
||||
// resolvePlayerGuildId handles players whose _guildId is still null by
|
||||
// checking the channel cache — critical for the multi-voice use case where
|
||||
// a player may have been joined before _guildId was written.
|
||||
const client = this.client;
|
||||
const guildPlayers = [...this.players.playerMap.entries()].filter(([mapKey, p]) => {
|
||||
if (p?._destroyed) return false;
|
||||
return resolvePlayerGuildId(p, mapKey, client) === cleanGuildId;
|
||||
});
|
||||
const guildPlayers = this.players.findGuildPlayers(cleanGuildId);
|
||||
|
||||
// Resolve the target channel to leave:
|
||||
// 1. If a channel option was provided, use that
|
||||
@@ -94,11 +69,8 @@ export async function run(msg, data) {
|
||||
// Match against both the map key and _channelId because after a voice-move
|
||||
// these can differ (the map key stays as the original join channel ID while
|
||||
// _channelId updates to the new channel).
|
||||
const player = this.players.playerMap.get(targetChannelId)
|
||||
?? guildPlayers.find(([mapKey, p]) =>
|
||||
cleanId(p._channelId) === targetChannelId || cleanId(mapKey) === targetChannelId
|
||||
)?.[1]
|
||||
?? null;
|
||||
const playerEntry = this.players.findPlayerEntryByChannelId(targetChannelId);
|
||||
const player = playerEntry?.player ?? null;
|
||||
|
||||
if (!player) {
|
||||
// No player in that channel — check if user picked a non-voice channel
|
||||
@@ -142,90 +114,36 @@ export async function run(msg, data) {
|
||||
return mode === "auto";
|
||||
});
|
||||
|
||||
if (ch247.has(activeChannelId) || ch247.has(homeChannelId)) {
|
||||
const matchChannel = ch247.has(homeChannelId) ? homeChannelId
|
||||
: ch247.has(activeChannelId) ? activeChannelId
|
||||
: null;
|
||||
const mode = matchChannel ? get247ChannelMode(set, matchChannel) : "off";
|
||||
const matchChannel = ch247.has(homeChannelId) ? homeChannelId
|
||||
: ch247.has(activeChannelId) ? activeChannelId
|
||||
: null;
|
||||
const mode = matchChannel ? get247ChannelMode(set, matchChannel) : "off";
|
||||
|
||||
if (matchChannel) {
|
||||
this.markIntentionalLeave(activeChannelId);
|
||||
this.players.playerMap.delete(activeChannelId);
|
||||
if (activeChannelId !== targetChannelId) this.players.playerMap.delete(targetChannelId);
|
||||
if (homeChannelId !== activeChannelId) this.players.playerMap.delete(homeChannelId);
|
||||
if (homeChannelId !== activeChannelId) this.markIntentionalLeave(homeChannelId);
|
||||
|
||||
this.players.detachPlayer(player, targetChannelId);
|
||||
await player.leave().catch(() => {});
|
||||
player.destroy();
|
||||
|
||||
const respawnBaseDelay = this.config?.timers?.leave247RejoinDelay ?? 5000;
|
||||
const respawnStagger = this.config?.timers?.rejoin247Delay ?? 3000;
|
||||
|
||||
if (mode === "auto") {
|
||||
msg.reply(embed(this.t(msg, "responses.leave.leftRejoin247", { channel: targetChannelId, prefix: set?.get("prefix") ?? "%" })));
|
||||
const leave247Delay = this.config?.timers?.leave247RejoinDelay ?? 5000;
|
||||
setTimeout(() => {
|
||||
if (this._spawnPlayer) {
|
||||
this._spawnPlayer(guildId, homeChannelId).catch(e =>
|
||||
logger.warn("[leave] 247 rejoin failed for", homeChannelId, e.message)
|
||||
);
|
||||
}
|
||||
}, leave247Delay);
|
||||
|
||||
// ── Rejoin other 24/7 auto channels that may have been disconnected ──
|
||||
// If the gateway sent a guild-level leave, all other 24/7 auto channels
|
||||
// also lost their connections. Schedule a rejoin for each one with a
|
||||
// staggered delay to avoid overloading the global join queue.
|
||||
if (other247AutoChannels.length > 0) {
|
||||
const rejoinBaseDelay = leave247Delay;
|
||||
const rejoinStagger = this.config?.timers?.rejoin247Delay ?? 3000;
|
||||
for (let i = 0; i < other247AutoChannels.length; i++) {
|
||||
const otherChannelId = other247AutoChannels[i];
|
||||
const otherPlayer = this.players.playerMap.get(otherChannelId);
|
||||
// Only rejoin if the player is gone (was collateral-disconnected)
|
||||
if (!otherPlayer || otherPlayer._destroyed) {
|
||||
// Clean up the dead player from the map
|
||||
if (otherPlayer) {
|
||||
this.players.playerMap.delete(otherChannelId);
|
||||
try { otherPlayer.destroy(); } catch (_) {}
|
||||
}
|
||||
const delay = rejoinBaseDelay + (i + 1) * rejoinStagger;
|
||||
logger.recovery(
|
||||
`[leave] Scheduling 247 auto-rejoin for collateral-disconnected channel ${otherChannelId} in ${delay}ms`
|
||||
);
|
||||
setTimeout(() => {
|
||||
if (this._spawnPlayer) {
|
||||
this._spawnPlayer(guildId, otherChannelId).catch(e =>
|
||||
logger.warn("[leave] 247 collateral rejoin failed for", otherChannelId, e.message)
|
||||
);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.players.schedule247Respawns(guildId, [homeChannelId, ...other247AutoChannels], {
|
||||
baseDelay: respawnBaseDelay,
|
||||
stagger: respawnStagger,
|
||||
source: "leave",
|
||||
});
|
||||
} else {
|
||||
// Mode is "on" — bot left, won't rejoin automatically for this channel.
|
||||
// But still check if other 24/7 auto channels need rejoining.
|
||||
msg.reply(embed(this.t(msg, "responses.leave.left247On", { prefix: set?.get("prefix") ?? "%" })));
|
||||
|
||||
if (other247AutoChannels.length > 0) {
|
||||
const rejoinDelay = this.config?.timers?.leave247RejoinDelay ?? 5000;
|
||||
const rejoinStagger = this.config?.timers?.rejoin247Delay ?? 3000;
|
||||
for (let i = 0; i < other247AutoChannels.length; i++) {
|
||||
const otherChannelId = other247AutoChannels[i];
|
||||
const otherPlayer = this.players.playerMap.get(otherChannelId);
|
||||
if (!otherPlayer || otherPlayer._destroyed) {
|
||||
if (otherPlayer) {
|
||||
this.players.playerMap.delete(otherChannelId);
|
||||
try { otherPlayer.destroy(); } catch (_) {}
|
||||
}
|
||||
const delay = rejoinDelay + (i + 1) * rejoinStagger;
|
||||
logger.recovery(
|
||||
`[leave] Scheduling 247 auto-rejoin for collateral-disconnected channel ${otherChannelId} in ${delay}ms`
|
||||
);
|
||||
setTimeout(() => {
|
||||
if (this._spawnPlayer) {
|
||||
this._spawnPlayer(guildId, otherChannelId).catch(e =>
|
||||
logger.warn("[leave] 247 collateral rejoin failed for", otherChannelId, e.message)
|
||||
);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.players.schedule247Respawns(guildId, other247AutoChannels, {
|
||||
baseDelay: respawnBaseDelay,
|
||||
stagger: respawnStagger,
|
||||
source: "leave",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await this.leaveChannel(activeChannelId, guildId, msg);
|
||||
|
||||
Reference in new issue
Block a user