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
98fe502b56
commit
733e14190a
2 files changed
+98
-10
No files matched your search
@@ -1,10 +1,10 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { initLogger, logger } from "./src/constants/Logger.mjs";
|
import { initLogger, logger } from "./src/constants/Logger.mjs";
|
||||||
import { Client, Events } from "@fluxerjs/core";
|
import { Client, Events, EmbedBuilder } from "@fluxerjs/core";
|
||||||
import { get247ChannelMode, remove247ChannelMode } from "./src/constants/Helpers247.mjs";
|
import { get247ChannelMode, remove247ChannelMode } from "./src/constants/Helpers247.mjs";
|
||||||
import { CommandHandler, CommandLoader, PrefixManager } from "./src/CommandHandler.mjs";
|
import { CommandHandler, CommandLoader, PrefixManager } from "./src/CommandHandler.mjs";
|
||||||
import { MessageHandler, PageBuilder, HelpCommand, setGlobalColor } from "./src/MessageHandler.mjs";
|
import { MessageHandler, PageBuilder, HelpCommand, setGlobalColor, getGlobalColor } from "./src/MessageHandler.mjs";
|
||||||
import { RemoteSettingsManager } from "./src/Settings.mjs";
|
import { RemoteSettingsManager } from "./src/Settings.mjs";
|
||||||
import { PlayerManager } from "./src/PlayerManager.mjs";
|
import { PlayerManager } from "./src/PlayerManager.mjs";
|
||||||
import childProcess from "node:child_process";
|
import childProcess from "node:child_process";
|
||||||
@@ -43,6 +43,11 @@ function createBotView(voiceCache) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Helper — build a plain embed payload from a description string */
|
||||||
|
function mkEmbed(desc) {
|
||||||
|
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc)] };
|
||||||
|
}
|
||||||
|
|
||||||
export class Remix {
|
export class Remix {
|
||||||
constructor() {
|
constructor() {
|
||||||
// ── Config ───────────────────────────────────────────────────────────────
|
// ── Config ───────────────────────────────────────────────────────────────
|
||||||
@@ -796,8 +801,55 @@ export class Remix {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle player messages (song announcements etc.)
|
// Handle player messages (song announcements etc.)
|
||||||
player.on("message", (m) => {
|
// On reboot, there's no textChannel from a user command, so we resolve
|
||||||
// No text channel for headless spawns — skip announcements
|
// one from the saved announcementChannelId setting or fall back to the
|
||||||
|
// guild's system channel / first visible text channel.
|
||||||
|
player.on("message", async (m) => {
|
||||||
|
try {
|
||||||
|
// Check if song announcements are disabled for this guild
|
||||||
|
const serverSettings = this.settingsMgr?.getServer?.(cleanGuildId);
|
||||||
|
const raw = serverSettings?.get?.("songAnnouncements");
|
||||||
|
const disabled = raw === false || raw === 0 ||
|
||||||
|
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
|
||||||
|
if (disabled) return;
|
||||||
|
|
||||||
|
// Resolve the text channel: prefer player.textChannel, then saved
|
||||||
|
// announcementChannelId, then guild system channel, then first text channel
|
||||||
|
let ch = player.textChannel;
|
||||||
|
if (!ch || typeof ch.send !== "function") {
|
||||||
|
const savedAnnChId = serverSettings?.get?.("announcementChannelId");
|
||||||
|
if (savedAnnChId) {
|
||||||
|
ch = this.client?.channels?.get?.(String(savedAnnChId).replace(/\D/g, "")) ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ch || typeof ch.send !== "function") {
|
||||||
|
const guild = this.client?.guilds?.get?.(cleanGuildId);
|
||||||
|
if (guild?.systemChannelId) {
|
||||||
|
ch = guild.channels?.get?.(guild.systemChannelId) ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ch || typeof ch.send !== "function") {
|
||||||
|
const guild = this.client?.guilds?.get?.(cleanGuildId);
|
||||||
|
if (guild?.channels) {
|
||||||
|
for (const c of (guild.channels.values?.() ?? [])) {
|
||||||
|
if (c.isTextBased?.() || c.type === 0 || c.type === "GUILD_TEXT") {
|
||||||
|
ch = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ch || typeof ch.send !== "function") return;
|
||||||
|
|
||||||
|
// Cache the resolved channel so future announcements don't need to re-resolve
|
||||||
|
if (!player.textChannel) player.textChannel = ch;
|
||||||
|
|
||||||
|
ch.send(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m)).catch(err => {
|
||||||
|
if (err.code === 'MISSING_PERMISSIONS' || err.statusCode === 403) {
|
||||||
|
logger.warn(`[_spawnPlayer] Cannot send announcement in channel ${ch.id} — missing permissions`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mark as pending join
|
// Mark as pending join
|
||||||
|
|||||||
+42
-6
@@ -968,19 +968,55 @@ export class PlayerManager {
|
|||||||
player.on("leave", () => {});
|
player.on("leave", () => {});
|
||||||
|
|
||||||
player.on("message", (m) => {
|
player.on("message", (m) => {
|
||||||
const ch = player.textChannel;
|
let ch = player.textChannel;
|
||||||
const guildId = cleanId(player._guildId ?? ch?.guildId ?? ch?.guild?.id ?? getMessageGuildId({ channel: ch }));
|
const guildId = cleanId(player._guildId ?? ch?.guildId ?? ch?.guild?.id ?? getMessageGuildId({ channel: ch }));
|
||||||
const raw = this.settings.getServer(guildId)?.get("songAnnouncements");
|
const raw = this.settings.getServer(guildId)?.get("songAnnouncements");
|
||||||
const disabled = raw === false || raw === 0 ||
|
const disabled = raw === false || raw === 0 ||
|
||||||
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
|
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
if (typeof ch?.send === "function") {
|
|
||||||
ch.send(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m)).catch(err => {
|
// If textChannel is not set (e.g. after reboot recovery via _spawnPlayer),
|
||||||
if (err.code === 'MISSING_PERMISSIONS' || err.statusCode === 403) {
|
// resolve it from the saved announcementChannelId or guild channels
|
||||||
logger.warn(`[PlayerManager] Cannot send player message in channel ${ch.id} — missing permissions`);
|
if (!ch || typeof ch.send !== "function") {
|
||||||
|
try {
|
||||||
|
const serverSettings = this.settings.getServer(guildId);
|
||||||
|
const savedAnnChId = serverSettings?.get?.("announcementChannelId");
|
||||||
|
if (savedAnnChId) {
|
||||||
|
ch = this.commands?.client?.channels?.get?.(String(savedAnnChId).replace(/\D/g, "")) ?? null;
|
||||||
}
|
}
|
||||||
});
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
if (!ch || typeof ch.send !== "function") {
|
||||||
|
try {
|
||||||
|
const guild = this.commands?.client?.guilds?.get?.(guildId);
|
||||||
|
if (guild?.systemChannelId) {
|
||||||
|
ch = guild.channels?.get?.(guild.systemChannelId) ?? null;
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
if (!ch || typeof ch.send !== "function") {
|
||||||
|
try {
|
||||||
|
const guild = this.commands?.client?.guilds?.get?.(guildId);
|
||||||
|
if (guild?.channels) {
|
||||||
|
for (const c of (guild.channels.values?.() ?? [])) {
|
||||||
|
if (c.isTextBased?.() || c.type === 0 || c.type === "GUILD_TEXT") {
|
||||||
|
ch = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
if (!ch || typeof ch.send !== "function") return;
|
||||||
|
|
||||||
|
// Cache the resolved channel so future announcements don't need to re-resolve
|
||||||
|
if (!player.textChannel) player.textChannel = ch;
|
||||||
|
|
||||||
|
ch.send(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m)).catch(err => {
|
||||||
|
if (err.code === 'MISSING_PERMISSIONS' || err.statusCode === 403) {
|
||||||
|
logger.warn(`[PlayerManager] Cannot send player message in channel ${ch.id} — missing permissions`);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mark as "pending join" so concurrent getPlayer() / checkVoiceChannels()
|
// Mark as "pending join" so concurrent getPlayer() / checkVoiceChannels()
|
||||||
|
|||||||
Reference in new issue
Block a user