mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
fix(voice): fail-fast on missing connect perms and purge un-restorable player snapshots on boot
This commit is contained in:
1 parent
784458f387
commit
af23db1255
3 files changed
+30
-3
No files matched your search
@@ -556,6 +556,7 @@ const BotVoiceMixin = {
|
||||
logger.player(`[Restore] Guild ${guildId}: ${applied.count} track(s) restored, resuming at ${applied.pos}ms.`);
|
||||
} catch (e) {
|
||||
logger.warn(`[Restore] Failed to restore guild ${guildId}:`, e?.message ?? e);
|
||||
await store.clearSnapshot(guildId).catch(() => {});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -11,7 +11,7 @@ import { getVoiceManager } from "@fluxerjs/voice";
|
||||
import { EventEmitter } from "node:events";
|
||||
import http from "node:http";
|
||||
import https from "node:https";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { EmbedBuilder, PermissionFlags } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../../ui/index.mjs";
|
||||
import { Utils, cleanId } from "../../utils/Utils.mjs";
|
||||
import { logger } from "../../core/Logger.mjs";
|
||||
@@ -516,6 +516,24 @@ class Player extends EventEmitter {
|
||||
this._lastConnectedAt = Date.now();
|
||||
this.leaving = false;
|
||||
|
||||
// Fail-fast permission check before initiating gateway voice handshake
|
||||
try {
|
||||
const me = channel.guild?.members?.me ?? (this.client?.user?.id ? channel.guild?.members?.get?.(this.client.user.id) : null);
|
||||
if (me) {
|
||||
const perms = channel.permissionsFor?.(me) ?? me.permissionsIn?.(channel);
|
||||
if (perms && !perms.has?.(PermissionFlags?.Administrator)) {
|
||||
if (PermissionFlags?.ViewChannel && !perms.has(PermissionFlags.ViewChannel)) {
|
||||
throw new Error(`Bot lacks ViewChannel permission in channel ${channelId}`);
|
||||
}
|
||||
if (PermissionFlags?.Connect && !perms.has(PermissionFlags.Connect)) {
|
||||
throw new Error(`Bot lacks Connect permission in channel ${channelId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (permErr) {
|
||||
if (permErr?.message?.includes?.("Bot lacks")) throw permErr;
|
||||
}
|
||||
|
||||
logger.player(`[Player] Joining channel ${channelId} via vm.join() (LiveKit)...`);
|
||||
const vm = getVoiceManager(this.client);
|
||||
if (!vm) {
|
||||
|
||||
@@ -41,14 +41,22 @@ const RejoinManager = {
|
||||
return player;
|
||||
} catch (err) {
|
||||
const errMsg = err?.message ?? String(err);
|
||||
const isTransientError = errMsg.includes("track publication timed out")
|
||||
const isPermissionError = errMsg.includes("permission")
|
||||
|| errMsg.includes("Permission")
|
||||
|| errMsg.includes("Bot lacks")
|
||||
|| errMsg.includes("403")
|
||||
|| errMsg.includes("Unauthorized");
|
||||
|
||||
const isTransientError = !isPermissionError && (
|
||||
errMsg.includes("track publication timed out")
|
||||
|| errMsg.includes("Voice connection timeout")
|
||||
|| errMsg.includes("LiveKit connection timeout")
|
||||
|| errMsg.includes("lavalink player create failed")
|
||||
|| errMsg.includes("Failed to create audio player")
|
||||
|| errMsg.includes("internal error")
|
||||
|| errMsg.includes("ETIMEDOUT")
|
||||
|| errMsg.includes("ECONNRESET");
|
||||
|| errMsg.includes("ECONNRESET")
|
||||
);
|
||||
|
||||
if (isTransientError && attempt < maxRetries) {
|
||||
const backoffMs = baseDelay * Math.pow(2, attempt - 1);
|
||||
|
||||
Reference in new issue
Block a user