mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
cleannnn
This commit is contained in:
1 parent
05fb38aabd
commit
bc1fe82919
43 files changed
+122
-1784
No files matched your search
@@ -49,19 +49,12 @@ 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;
|
||||
});
|
||||
|
||||
// Resolve the target channel to leave:
|
||||
// 1. If a channel option was provided, use that
|
||||
// 2. Otherwise, use the user's current voice channel
|
||||
const specifiedChannel = data?.get("channel")?.value;
|
||||
let targetChannelId = null;
|
||||
|
||||
@@ -72,12 +65,10 @@ export async function run(msg, data) {
|
||||
if (userChannelId) targetChannelId = cleanId(userChannelId);
|
||||
}
|
||||
|
||||
// If we still don't have a target channel
|
||||
if (!targetChannelId) {
|
||||
if (guildPlayers.length === 0) {
|
||||
return msg.reply(embed(this.t(msg, "responses.leave.notInVoice")));
|
||||
}
|
||||
// User not in voice and no channel specified — list all channels the bot is in
|
||||
const channelList = guildPlayers.map(([mapKey, p]) => {
|
||||
const id = cleanId(p._channelId ?? mapKey);
|
||||
return id ? `<#${id}>` : "`unknown`";
|
||||
@@ -90,10 +81,6 @@ export async function run(msg, data) {
|
||||
));
|
||||
}
|
||||
|
||||
// Find the player for the target channel.
|
||||
// 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
|
||||
@@ -101,7 +88,6 @@ export async function run(msg, data) {
|
||||
?? null;
|
||||
|
||||
if (!player) {
|
||||
// No player in that channel — check if user picked a non-voice channel
|
||||
if (guildPlayers.length === 0) {
|
||||
return msg.reply(embed(this.t(msg, "responses.leave.notInVoice")));
|
||||
}
|
||||
@@ -122,7 +108,6 @@ export async function run(msg, data) {
|
||||
const activeChannelId = cleanId(player._channelId) || targetChannelId;
|
||||
const homeChannelId = cleanId(player._home247Channel) || activeChannelId;
|
||||
|
||||
// ── 24/7 handling ────────────────────────────────────────────────────────
|
||||
const set = this.getSettings(msg);
|
||||
const raw = set?.get("stay_247");
|
||||
const ch247 = (!raw || raw === "none")
|
||||
@@ -131,11 +116,6 @@ export async function run(msg, data) {
|
||||
? new Set(raw.map(id => cleanId(id)).filter(Boolean))
|
||||
: new Set([cleanId(raw)]);
|
||||
|
||||
// ── Snapshot all 247 auto channels in this guild BEFORE leaving ────────
|
||||
// When the bot leaves one channel, the gateway may send a guild-level
|
||||
// disconnect that kills ALL voice connections in the guild (not just the
|
||||
// target). By snapshotting beforehand, we can schedule rejoins for every
|
||||
// 24/7 auto channel that was collateral-disconnected.
|
||||
const other247AutoChannels = [...ch247].filter(id => {
|
||||
if (id === activeChannelId || id === homeChannelId || id === targetChannelId) return false;
|
||||
const mode = get247ChannelMode(set, id);
|
||||
@@ -165,19 +145,13 @@ export async function run(msg, data) {
|
||||
}
|
||||
}, 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 (_) {}
|
||||
@@ -197,8 +171,6 @@ export async function run(msg, data) {
|
||||
}
|
||||
}
|
||||
} 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) {
|
||||
|
||||
Reference in new issue
Block a user