From 28891e2f901cfd30ef4cacd68c00e1b120ac3c33 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Fri, 8 May 2026 01:15:30 +0300 Subject: [PATCH] dashboard works --- index.mjs | 3 +- src/PlayerManager.mjs | 20 +++++++++++-- src/dashboard/Dashboard.mjs | 57 +++++++++++++++++++++++++++++++------ 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/index.mjs b/index.mjs index 8d51ad2..f148958 100644 --- a/index.mjs +++ b/index.mjs @@ -239,13 +239,14 @@ export class Remix { const ALONE_CHECK_INTERVAL = this.T.aloneCheckInterval; setInterval(() => { for (const [mapKey, player] of this.players.playerMap) { + let channelId = mapKey; try { const guildId = player._guildId; if (!guildId) continue; if (player._isJoining || player._isRecovering) continue; - const channelId = player._channelId ?? mapKey; + channelId = player._channelId ?? mapKey; const cleanChanId = String(channelId).replace(/\D/g, ""); if (!cleanChanId) continue; diff --git a/src/PlayerManager.mjs b/src/PlayerManager.mjs index 7f61d69..6ff18b2 100644 --- a/src/PlayerManager.mjs +++ b/src/PlayerManager.mjs @@ -765,10 +765,19 @@ export class PlayerManager { this.playerMap.set(cleanChannelId, player); (async () => { - const statusMsg = await message.reply(mkEmbed(this._t(message, "responses.join.joining"))); + let statusMsg = null; + try { + statusMsg = await message.reply(mkEmbed(this._t(message, "responses.join.joining"))); + } catch (_) { + // reply() may fail or return a non-standard object (e.g. dashboard fakeMsg) + } + const canEdit = typeof statusMsg?.edit === "function"; + try { await player.join(cid); - await statusMsg.edit(mkEmbed(this._t(message, "responses.join.joined", { channel: cid }))); + if (canEdit) { + await statusMsg.edit(mkEmbed(this._t(message, "responses.join.joined", { channel: cid }))).catch(() => {}); + } const guildId = cleanId(channel.guildId ?? getMessageGuildId(message)); if (guildId) { @@ -792,7 +801,12 @@ export class PlayerManager { } else { errorMsg = this._t(message, "responses.join.joinFailed", { error: err.message }); } - await statusMsg.edit(mkEmbed(errorMsg)).catch(() => {}); + if (canEdit) { + await statusMsg.edit(mkEmbed(errorMsg)).catch(() => {}); + } else { + // Can't edit the status message — send a new reply instead + try { await message.reply(mkEmbed(errorMsg)); } catch (_) {} + } this.playerMap.delete(cleanChannelId); player.destroy(); } diff --git a/src/dashboard/Dashboard.mjs b/src/dashboard/Dashboard.mjs index ac2ff4e..efec02f 100644 --- a/src/dashboard/Dashboard.mjs +++ b/src/dashboard/Dashboard.mjs @@ -84,7 +84,20 @@ export class Dashboard { if (member) { server.channels = server.channels.filter(c => { const ch = guild.channels.get(c.id); - return ch ? ch.permissionsFor(member)?.has("ViewChannel") : false; + if (!ch) return false; + // @fluxerjs/core GuildChannel objects do NOT expose a + // permissionsFor() method like discord.js does. If the method + // exists, use it; otherwise the user is already verified as a + // guild member so showing all channels is safe. + if (typeof ch.permissionsFor === "function") { + try { + const perms = ch.permissionsFor(member); + return perms ? perms.has("ViewChannel") : false; + } catch (_) { + return true; // permission check failed — show channel anyway + } + } + return true; }); } return server; @@ -146,10 +159,12 @@ export class Dashboard { if (authErr) return { error: authErr }; if (this.remix.players.playerMap.has(voiceChannel.id)) return { message: "Already Connected" }; // Build a minimal fake message that satisfies PlayerManager.initPlayer(). + // The reply() returns a mock with edit() so initPlayer's statusMsg.edit + // calls don't crash (Fluxer doesn't expose message edit from dashboards). const fakeMsg = { channel: { channel: textChannel, guildId: voiceChannel.guildId }, message: { guildId: voiceChannel.guildId }, - reply: async () => ({ catch: () => {} }), + reply: async () => ({ edit: async () => {}, catch: () => {} }), }; this.remix.players.initPlayer(fakeMsg, voiceChannel.id); return { message: "Joining" }; @@ -307,13 +322,29 @@ export class Dashboard { * @param {import("@fluxerjs/core").User} user */ static convertUser(user) { + // Build avatar URL — @fluxerjs/core may expose displayAvatarURL() or + // may just have a raw hash in user.avatar. Handle both cases. + let avatarUrl = null; + try { + if (typeof user.displayAvatarURL === "function") { + avatarUrl = user.displayAvatarURL(); + } + } catch (_) { /* not available */ } + if (!avatarUrl && user.avatar) { + const hash = String(typeof user.avatar === "object" ? (user.avatar.hash ?? user.avatar) : user.avatar); + if (hash && hash !== "[object Object]") { + const ext = hash.startsWith("a_") ? ".gif" : ".webp"; + avatarUrl = `https://cdn.fluxer.app/avatars/${user.id}/${hash}${ext}?size=128`; + } + } + if (!avatarUrl && typeof user.defaultAvatarURL === "string") { + avatarUrl = user.defaultAvatarURL; + } return { id: user.id, username: user.username, displayName: user.displayName ?? user.globalName ?? user.username, - avatar: { - url: user.displayAvatarURL() ?? user.defaultAvatarURL, - }, + avatar: { url: avatarUrl }, }; } @@ -345,7 +376,17 @@ export class Dashboard { * @param {import("@fluxerjs/core").GuildChannel} channel */ static convertChannel(channel) { - const isVoice = channel.isVoiceBased?.() ?? false; + // Same voice-detection logic as convertServerForList — @fluxerjs/core may + // not expose isVoiceBased(), so fall back to the type field. + let isVoice = false; + if (typeof channel.isVoiceBased === "function") { + isVoice = channel.isVoiceBased(); + } else if (channel.isVoiceBased === true) { + isVoice = true; + } else { + const t = channel.type; + isVoice = t === 2 || t === 13 || t === "GUILD_VOICE" || t === "GUILD_STAGE_VOICE"; + } let voiceParticipants = []; if (isVoice) { const guild = channel?.guild ?? channel?.client?.guilds?.get(channel?.guildId); @@ -383,12 +424,12 @@ export class Dashboard { * @param {import("@fluxerjs/core").Guild} guild * @returns {string|null} */ - static guildIconURL(guild) { + static guildIconURL(guild, size = 128) { if (!guild?.icon) return null; // guild.icon may be "hash" or "a_hash" (animated prefix) const hash = String(guild.icon); const ext = hash.startsWith("a_") ? ".gif" : ".webp"; - return `https://cdn.fluxer.app/icons/${guild.id}/${hash}${ext}`; + return `https://cdn.fluxer.app/icons/${guild.id}/${hash}${ext}?size=${size}`; } /**