mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
perf: reduce alone-check
This commit is contained in:
1 parent
4cf6952704
commit
9262b31b25
1 file changed
+7
-19
@@ -91,7 +91,7 @@ export class Remix {
|
|||||||
|
|
||||||
const timers = config.timers ?? {};
|
const timers = config.timers ?? {};
|
||||||
this.T = {
|
this.T = {
|
||||||
aloneCheckInterval: timers.aloneCheckInterval ?? 30_000,
|
aloneCheckInterval: timers.aloneCheckInterval ?? 60_000,
|
||||||
aloneCheckDebounce: timers.aloneCheckDebounce ?? 500,
|
aloneCheckDebounce: timers.aloneCheckDebounce ?? 500,
|
||||||
rejoin247Delay: timers.rejoin247Delay ?? 3_000,
|
rejoin247Delay: timers.rejoin247Delay ?? 3_000,
|
||||||
leave247RejoinDelay: timers.leave247RejoinDelay ?? 5_000,
|
leave247RejoinDelay: timers.leave247RejoinDelay ?? 5_000,
|
||||||
@@ -324,30 +324,26 @@ export class Remix {
|
|||||||
|
|
||||||
const ALONE_CHECK_INTERVAL = this.T.aloneCheckInterval;
|
const ALONE_CHECK_INTERVAL = this.T.aloneCheckInterval;
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
if (this.players.playerMap.size === 0) return;
|
||||||
|
|
||||||
for (const [mapKey, player] of this.players.playerMap) {
|
for (const [mapKey, player] of this.players.playerMap) {
|
||||||
let channelId;
|
let channelId;
|
||||||
try {
|
try {
|
||||||
|
if (player._destroyed || player._isJoining) continue;
|
||||||
|
|
||||||
const guildId = player._guildId;
|
const guildId = player._guildId;
|
||||||
if (!guildId) continue;
|
if (!guildId) continue;
|
||||||
|
|
||||||
if (player._isJoining) continue;
|
|
||||||
|
|
||||||
channelId = player._channelId ?? mapKey;
|
channelId = player._channelId ?? mapKey;
|
||||||
const cleanChanId = cleanId(channelId);
|
const cleanChanId = cleanId(channelId);
|
||||||
if (!cleanChanId) continue;
|
if (!cleanChanId) continue;
|
||||||
|
|
||||||
const cleanGuildId = cleanId(guildId);
|
const cleanGuildId = cleanId(guildId);
|
||||||
const channelGuildId = cleanId(
|
|
||||||
this.client?.channels?.get?.(channelId)?.guildId ??
|
|
||||||
this.client?.channels?.get?.(channelId)?.guild_id
|
|
||||||
);
|
|
||||||
if (channelGuildId && channelGuildId !== cleanGuildId) {
|
|
||||||
logger.warn(`[AloneCheck] Skipping inconsistent player state channel=${channelId} playerGuild=${guildId} channelGuild=${channelGuildId}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player._is247Enabled()) continue;
|
if (player._is247Enabled()) continue;
|
||||||
|
|
||||||
|
if (!player.connection) continue;
|
||||||
|
|
||||||
let hasHuman = this.voiceCache.hasHumansInChannel(cleanGuildId, cleanChanId);
|
let hasHuman = this.voiceCache.hasHumansInChannel(cleanGuildId, cleanChanId);
|
||||||
|
|
||||||
if (!hasHuman) {
|
if (!hasHuman) {
|
||||||
@@ -368,9 +364,6 @@ export class Remix {
|
|||||||
const isBot = member?.user?.bot ?? state?.member?.user?.bot ?? false;
|
const isBot = member?.user?.bot ?? state?.member?.user?.bot ?? false;
|
||||||
if (!isBot) {
|
if (!isBot) {
|
||||||
hasHuman = true;
|
hasHuman = true;
|
||||||
if (stateUserId) {
|
|
||||||
this.voiceCache.updateUser({ guildId: cleanGuildId, userId: stateUserId, channelId: cleanChanId, isBot: false });
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,19 +377,14 @@ export class Remix {
|
|||||||
const room = player.connection?.room;
|
const room = player.connection?.room;
|
||||||
if (room?.isConnected && room.remoteParticipants && room.remoteParticipants.size > 0) {
|
if (room?.isConnected && room.remoteParticipants && room.remoteParticipants.size > 0) {
|
||||||
hasHuman = true;
|
hasHuman = true;
|
||||||
logger.aloneCheck(`[AloneCheck] Found ${room.remoteParticipants.size} LiveKit remote participant(s) in ${channelId}`);
|
|
||||||
}
|
}
|
||||||
} catch(e) { logger.warn("[AloneCheck] LiveKit check error:", e?.message); }
|
} catch(e) { logger.warn("[AloneCheck] LiveKit check error:", e?.message); }
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.aloneCheck(`[AloneCheck] channel=${channelId} guild=${guildId} hasHuman=${hasHuman} paused=${player._paused}`);
|
|
||||||
|
|
||||||
if (!hasHuman && !player._paused) {
|
if (!hasHuman && !player._paused) {
|
||||||
if (player.queue?.getCurrent() || !player.queue?.isEmpty()) {
|
if (player.queue?.getCurrent() || !player.queue?.isEmpty()) {
|
||||||
logger.aloneCheck(`[AloneCheck] Bot alone in ${channelId} (guild ${guildId}) with songs in queue — starting inactivity timer.`);
|
|
||||||
player._startInactivityTimer?.();
|
player._startInactivityTimer?.();
|
||||||
} else {
|
} else {
|
||||||
logger.aloneCheck(`[AloneCheck] Bot alone in ${channelId} (guild ${guildId}), leaving.`);
|
|
||||||
player._stopInactivityTimer?.();
|
player._stopInactivityTimer?.();
|
||||||
player.emit("autoleave");
|
player.emit("autoleave");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user