little changes

This commit is contained in:
NoLogicAlan committed 2026-06-16 22:34:11 +03:00
1 parent 862f326996
commit b7252fccaf
41 files changed
+261 -228

No files matched your search

+3 -4
View File
@@ -176,8 +176,6 @@ export class Option {
const results = this.channelRegex.exec(i) ?? this.idRegex.exec(i);
const guildId = msg?.channel?.guildId ?? msg?.guildId;
if (guildId === "eval") return (results) ? results.groups["id"] : i;
const voiceTypes = [2, 13];
const byName = msg?.guild?.channels?.find(c => c.name === i && voiceTypes.includes(c.type));
const cObj = results
@@ -573,7 +571,7 @@ export class CommandHandler extends EventEmitter {
try {
const names = botPermResult.missing.map(k => REQUIRED_BOT_PERMISSIONS.get(k)?.name ?? k);
msg.message?.reply?.("I'm missing critical permissions: **" + names.join("**, **") + "**. Ask an admin to fix this.", { ping: false });
} catch (__) { }
} catch (__) { logger.warn("[CommandHandler] Fallback perm reply failed"); }
}
return;
}
@@ -639,7 +637,8 @@ export class CommandHandler extends EventEmitter {
const data = collectArguments(argIndex, value, [value]);
if (!data) { const twGuildId = msg.channel?.channel?.guildId ?? msg.message?.guildId; return this.replyHandler(this._textWrapErrorMsg(twGuildId, args.slice(argIndex).join(" "), args[argIndex].charAt(0)), msg); }
argIndex += data.index - argIndex;
value = data.args.join(" ").slice(1, data.args.join(" ").length - 1);
const _joined = data.args.join(" ");
value = _joined.slice(1, _joined.length - 1);
}
argIndex++;
i--;
+1 -1
View File
@@ -102,7 +102,7 @@ export class GatewayHandler {
if (guild.members && !guild.members.me) {
await guild.members.fetchMe();
}
} catch (_) { }
} catch (_) { logger.warn("[GatewayHandler] fetchMe failed"); }
const channels = guild.channels;
if (!channels) return;
+67 -74
View File
@@ -233,7 +233,8 @@ export class LastFmManager {
try {
await pool.execute("ALTER TABLE \`lastfm_users\` ADD COLUMN \`scrobble_count\` BIGINT NOT NULL DEFAULT 0 AFTER \`scrobble\`");
} catch {
} catch (e) {
logger.warn("[LastFm] Migration warning:", e?.message);
}
await pool.execute(`
@@ -296,7 +297,8 @@ export class LastFmManager {
`UPDATE lastfm_stats SET linked_users = linked_users + 1 WHERE id = 1${f.where} AND NOT EXISTS (SELECT 1 FROM (SELECT 1 FROM lastfm_users WHERE user_id = ?${f.where} AND linked_at < NOW()) AS tmp)`,
[...f.params, String(userId), ...f.params]
);
} catch {
} catch (e) {
logger.warn("[LastFm] Migration warning:", e?.message);
}
return data;
@@ -520,8 +522,9 @@ export class LastFmManager {
try {
const data = await apiCall(params, this.apiSecret);
return data.track;
} catch {
return null;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return null;
}
}
@@ -729,9 +732,7 @@ export class LastFmManager {
url: t.url ?? "",
match: parseFloat(t.match ?? 0),
})).filter(t => t.match > 0.1);
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -776,8 +777,9 @@ export class LastFmManager {
})),
userplaycount: a.stats?.userplaycount ? Number(a.stats.userplaycount) : null,
};
} catch {
return null;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return null;
}
}
@@ -822,8 +824,9 @@ export class LastFmManager {
})),
userplaycount: a.userplaycount ? Number(a.userplaycount) : null,
};
} catch {
return null;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return null;
}
}
@@ -854,9 +857,7 @@ export class LastFmManager {
playcount: Number(t.playcount ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -886,9 +887,7 @@ export class LastFmManager {
playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -917,9 +916,7 @@ export class LastFmManager {
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
match: parseFloat(a.match ?? 0),
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -950,9 +947,7 @@ export class LastFmManager {
url: t.url ?? "",
count: Number(t.count ?? 0),
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -983,8 +978,9 @@ export class LastFmManager {
count: Number(t.taggings?.total ?? t.total ?? 0),
summary: t.wiki?.summary ?? "",
};
} catch {
return null;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return null;
}
}
@@ -1015,9 +1011,7 @@ export class LastFmManager {
playcount: Number(t.playcount ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1046,9 +1040,7 @@ export class LastFmManager {
playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1082,8 +1074,9 @@ export class LastFmManager {
username: user.username,
playcount,
};
} catch {
return {
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return {
userId: uid,
username: user.username,
playcount: 0,
@@ -1151,8 +1144,9 @@ export class LastFmManager {
commonArtists,
matchPercentage,
};
} catch {
return null;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return null;
}
}
@@ -1181,9 +1175,7 @@ export class LastFmManager {
from: Number(c.from ?? 0),
to: Number(c.to ?? 0),
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1219,9 +1211,7 @@ export class LastFmManager {
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
listeners: Number(a.listeners ?? 0),
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1257,9 +1247,7 @@ export class LastFmManager {
url: a.url ?? "",
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1296,8 +1284,9 @@ export class LastFmManager {
}
return { artist, track, album, url };
} catch {
return null;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return null;
}
}
@@ -1311,8 +1300,9 @@ export class LastFmManager {
try {
const u = new URL(str);
return /^(?:www\.)?last\.fm$/i.test(u.hostname) && /^\/music\//.test(u.pathname);
} catch {
return false;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return false;
}
}
@@ -1604,9 +1594,7 @@ export class LastFmManager {
query: `${t.name} ${t.artist ?? ar.name}`,
image: t.image ?? ar.image ?? "",
}));
} catch {
return [];
}
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
})
);
for (const r of artistResults) {
@@ -1716,8 +1704,9 @@ export class LastFmManager {
[...f.params]
);
return Number(rows[0]?.linked_users ?? 0);
} catch {
return 0;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return 0;
}
}
@@ -1776,8 +1765,9 @@ export class LastFmManager {
[String(playcount), String(userId), ...f.params]
);
return playcount;
} catch {
return 0;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return 0;
}
}
@@ -1805,7 +1795,7 @@ export class LastFmManager {
realname: f.realname ?? "",
country: f.country ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1834,7 +1824,7 @@ export class LastFmManager {
playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1864,7 +1854,7 @@ export class LastFmManager {
playcount: Number(t.playcount ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1894,7 +1884,7 @@ export class LastFmManager {
playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1917,7 +1907,7 @@ export class LastFmManager {
url: t.url ?? "",
count: Number(t.count ?? 0),
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1942,7 +1932,7 @@ export class LastFmManager {
url: t.url ?? "",
count: Number(t.count ?? 0),
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1967,7 +1957,7 @@ export class LastFmManager {
url: t.url ?? "",
count: Number(t.count ?? 0),
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -1992,7 +1982,7 @@ export class LastFmManager {
playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -2016,7 +2006,7 @@ export class LastFmManager {
listeners: Number(a.listeners ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -2041,7 +2031,7 @@ export class LastFmManager {
listeners: Number(t.listeners ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -2065,7 +2055,7 @@ export class LastFmManager {
playcount: Number(t.playcount ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -2088,7 +2078,7 @@ export class LastFmManager {
playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
}));
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
/**
@@ -2121,8 +2111,9 @@ export class LastFmManager {
username: user.username,
playcount,
};
} catch {
return {
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return {
userId: uid,
username: user.username,
playcount: 0,
@@ -2172,8 +2163,9 @@ export class LastFmManager {
username: user.username,
playcount,
};
} catch {
return {
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return {
userId: uid,
username: user.username,
playcount: 0,
@@ -2216,8 +2208,9 @@ export class LastFmManager {
try {
const artists = await this.getTopArtists(uid, "overall", 50);
return { uid, username: user.username, artists };
} catch {
return null;
} catch (e) {
logger.warn("[LastFm] Error:", e?.message);
return null;
}
})
);
@@ -2295,7 +2288,7 @@ export class LastFmManager {
crowns.sort((a, b) => b.userPlaycount - a.userPlaycount);
return crowns;
} catch { return []; }
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; }
}
_assertEnabled() {
+4 -4
View File
@@ -245,7 +245,7 @@ export class MessageHandler {
async assertPermissions(permissions, message) {
const guild = message.guild ?? await message.client?.guilds?.resolve?.(message.guildId);
if (guild && !guild.members?.me) {
try { await guild.members.fetchMe(); } catch (_) { }
try { await guild.members.fetchMe(); } catch (_) { logger.warn("[MessageHandler] fetchMe failed"); }
}
const missing = this.checkPermissions(permissions, message.channel ?? message.channel?.channel);
if (missing.length === 0) return true;
@@ -270,7 +270,7 @@ export class MessageHandler {
try {
const names = missing.map(k => REQUIRED_BOT_PERMISSIONS.get(k)?.name ?? k);
await message.reply(this.t(message.guildId, "responses.messages.needPermsFallback", { perms: names.join("** **") }), { ping: false });
} catch (_) { }
} catch (_) { logger.warn("[MessageHandler] Fallback permission reply failed"); }
}
return false;
}
@@ -991,7 +991,7 @@ export class RichPaginator {
for (const emoji of allReactions) {
try {
await rawMsg.removeReaction(emoji);
} catch(e) { }
} catch(e) { logger.warn("[MessageHandler] Error:", e?.message); }
}
};
@@ -1090,7 +1090,7 @@ export class QueuePaginator {
for (const emoji of [prev, next]) {
try {
await rawMsg.removeReaction(emoji);
} catch(e) { }
} catch(e) { logger.warn("[MessageHandler] Error:", e?.message); }
}
}
};
+11 -13
View File
@@ -17,8 +17,7 @@
* that occurs when a Fluxer bot token is sent to an incompatible API.
*/
import Revoicejs from "revoice.js";
const { MediaPlayer } = Revoicejs;
import { MediaPlayer } from "revoice.js";
import { ConnectionState, LKRoomEvent } from "./constants/FluxerRevoice.mjs";
import { getVoiceManager } from "@fluxerjs/voice";
@@ -33,7 +32,6 @@ import { getGlobalColor } from "./MessageHandler.mjs";
import { logger } from "./constants/Logger.mjs";
import { get247ChannelMode } from "./constants/Helpers247.mjs";
import { PROVIDER_NAMES } from "./constants/providers.mjs";
import { cleanId } from "./Utils.mjs";
import { hasHumansInChannel } from "./constants/VoiceStateResolver.mjs";
@@ -587,7 +585,7 @@ export default class Player extends EventEmitter {
logger.mediaplayer("[Player] Existing MediaPlayer unhealthy, cleaning up...");
try {
if (this._mediaPlayer.fProc) {
try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { }
try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { logger.warn("[Player] Error removing listeners:", e?.message); }
}
await this._mediaPlayer.stop();
} catch(e) { logger.warn("[Player] MediaPlayer stop error:", e?.message); }
@@ -674,7 +672,7 @@ export default class Player extends EventEmitter {
if (this._mediaPlayer) {
try {
if (this._mediaPlayer.fProc) {
try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { }
try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { logger.warn("[Player] Error removing listeners:", e?.message); }
}
await this._mediaPlayer.stop();
@@ -720,7 +718,7 @@ export default class Player extends EventEmitter {
if (_redirects >= 5) return reject(new Error("Too many redirects"));
const redirectUrl = new URL(loc);
if (redirectUrl.host !== urlObj.host) {
delete options.headers?.Authorization;
if (options.headers) delete options.headers.Authorization;
}
return fetchUrl(loc, _redirects + 1);
}
@@ -801,7 +799,7 @@ export default class Player extends EventEmitter {
try {
if (typeof audioStream.unpipe === "function") audioStream.unpipe();
if (typeof audioStream.destroy === "function") audioStream.destroy();
} catch (e) { }
} catch (e) { logger.warn("[Player] Error:", e?.message); }
}
this._currentPassthrough = null;
};
@@ -885,10 +883,9 @@ export default class Player extends EventEmitter {
this._mediaPlayer.once("finish", onFinish);
this._mediaPlayer.once("error", onError);
});
} catch (e) {
if (audioStream && !audioStream.destroyed) {
try { audioStream.destroy(); } catch (e2) { }
try { audioStream.destroy(); } catch (e2) { logger.warn("[Player] Error destroying stream:", e2?.message); }
}
this._currentPassthrough = null;
if (isIgnorableMediaStateError(e)) {
@@ -1266,7 +1263,7 @@ export default class Player extends EventEmitter {
}
this._stopMediaPlayer().catch(() => {}).then(() => {
if (connToDestroy) {
try { connToDestroy.removeAllListeners?.(); } catch(e) { }
try { connToDestroy.removeAllListeners?.(); } catch(e) { logger.warn("[Player] Error removing listeners:", e?.message); }
const disconnectPromise = connToDestroy.disconnect?.();
if (disconnectPromise instanceof Promise) {
disconnectPromise.catch((err) => {
@@ -1779,8 +1776,9 @@ export default class Player extends EventEmitter {
msg: `${vcLine}📻 **[${current.title}](${current.author?.url || current.url})**\n${current.description || ""}\n\n🎵 Now playing: ${data?.title || "Unknown"}\n\n🔉 ${vol} │ ${loopqueue} Queue │ ${songloop} Song │ ${autoplay} Autoplay`,
image: current.thumbnail
};
} catch {
return {
} catch (e) {
logger.warn("[Player] Error:", e?.message);
return {
msg: `${vcLine}📻 **[${current.title}](${current.author?.url || current.url})**\n\n🔉 ${vol} │ ${loopqueue} Queue │ ${songloop} Song │ ${autoplay} Autoplay`,
image: current.thumbnail
};
@@ -2036,7 +2034,7 @@ export default class Player extends EventEmitter {
if (this._mediaPlayer) {
try {
if (this._mediaPlayer.fProc) {
try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { }
try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { logger.warn("[Player] Error removing listeners:", e?.message); }
}
await this._mediaPlayer.stop();
} catch(e) { logger.warn("[Player] MediaPlayer stop on next track:", e?.message); }
+3 -2
View File
@@ -107,8 +107,9 @@ export class TrackOptionsManager {
try {
const u = new URL(track.url);
return `${u.hostname}${u.pathname}`.replace(/\/+$/, "").toLowerCase().trim();
} catch {
return track.url.toLowerCase().trim();
} catch (e) {
logger.warn("[TrackOptions] Error:", e?.message);
return track.url.toLowerCase().trim();
}
}
const artist = track.artist || track.author?.name || "";
+3 -2
View File
@@ -216,8 +216,9 @@ export class Utils {
try {
new URL(str);
return true;
} catch {
return false;
} catch (e) {
logger.warn("[Utils] Error:", e?.message);
return false;
}
}
+3 -3
View File
@@ -62,7 +62,7 @@ function isLiveKitLogMessage(...args) {
try {
const parsed = JSON.parse(args[0]);
if (parsed.name === "lk-rtc") return true;
} catch (_e) { }
} catch (_e) { logger.warn("[FluxerRevoice] Error parsing livekit args"); }
}
if (LIVEKIT_LOG_PREFIXES.some(p => args[0].includes(p))) return true;
}
@@ -370,7 +370,7 @@ export class FluxerRevoice extends EventEmitter {
existing._destroyed = true;
existing._connected = false;
try { existing.removeAllListeners(); } catch (e) { }
try { existing.removeAllListeners(); } catch (e) { logger.warn("[FluxerRevoice] Error removing listeners:", e?.message); }
}
/**
@@ -474,7 +474,7 @@ export class FluxerRevoice extends EventEmitter {
warn: (...args) => { if (!isLiveKitLogMessage(...args)) logger.warn("[LiveKit]", ...args); },
error: (...args) => logger.error("[LiveKit]", ...args),
});
} catch (_e) { }
} catch (_e) { logger.warn("[FluxerRevoice] Error creating LiveKit logger adapter"); }
}
if (!room) {
+7 -8
View File
@@ -6,6 +6,7 @@
import { readFileSync, readdirSync, existsSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { logger } from "./Logger.mjs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const LOCALES_DIR = path.resolve(__dirname, "../../storage/locales/bot");
@@ -53,7 +54,7 @@ export class Locale {
this._resolved.clear();
if (!existsSync(LOCALES_DIR)) {
console.warn(`[Locale] Locales directory not found: ${LOCALES_DIR}`);
logger.warn("[Locale] Locales directory not found:", LOCALES_DIR);
return;
}
@@ -61,7 +62,7 @@ export class Locale {
try {
files = readdirSync(LOCALES_DIR).filter(f => f.endsWith(".json"));
} catch (e) {
console.warn(`[Locale] Failed to read locales directory: ${e.message}`);
logger.warn("[Locale] Failed to read locales directory:", e.message);
return;
}
@@ -72,13 +73,11 @@ export class Locale {
const data = JSON.parse(readFileSync(filePath, "utf8"));
this.locales.set(code, data);
} catch (e) {
console.warn(`[Locale] Failed to load ${file}: ${e.message}`);
logger.warn("[Locale] Failed to load " + file + ":", e.message);
}
}
console.log(
`[Locale] Loaded ${this.locales.size} locale(s): ${[...this.locales.keys()].join(", ")}`
);
logger.info("[Locale] Loaded " + this.locales.size + " locale(s): " + [...this.locales.keys()].join(", "));
}
/**
@@ -113,7 +112,7 @@ export class Locale {
code = setting;
}
}
} catch(e) { }
} catch(e) { logger.warn("[Locale] Error:", e?.message); }
const data = this.locales.get(code) ?? this.locales.get(this.defaultLocale) ?? {};
this._resolved.set(guildId, data);
@@ -161,7 +160,7 @@ export class Locale {
const prefix = serverSettings.get("prefix");
if (prefix) return prefix;
}
} catch(e) { }
} catch(e) { logger.warn("[Locale] Error:", e?.message); }
return this._defaultPrefix || "!";
}
+19 -1
View File
@@ -1,3 +1,13 @@
/**
* @file StreamMerger.mjs — StreamMerger — Transform stream that mixes multiple audio inputs through FFmpeg amix filter
* @module src.constants.audio.StreamMerger
*/
/**
* StreamMerger extends Transform to mix multiple audio streams into one
* using FFmpeg’s amix filter. Supports dynamic stream addition with
* a tree-based node structure for managing merge slots.
*/
import { logger } from "../Logger.mjs";
import ffmpeg from "ffmpeg-static";
import { Transform } from "node:stream";
@@ -26,7 +36,14 @@ class StreamMerger extends Transform {
this.ffmpeg.stdout.on("data", (chunk) => { this.push(chunk); });
}
spawnFfmpeg() {
const args = "-i pipe:3 -re -i pipe:4 -vn -fflags nobuffer -filter_complex amix=inputs=2:duration=longest pipe:1".split(" ");
const args = [
"-i", "pipe:3",
"-re", "-i", "pipe:4",
"-vn",
"-fflags", "nobuffer",
"-filter_complex", "amix=inputs=2:duration=longest",
"pipe:1",
];
return spawn(this.ffmpegPath, args, {
windowsHide: true,
stdio: ["pipe", "pipe", "pipe", "pipe", "pipe"]
@@ -60,6 +77,7 @@ class StreamMerger extends Transform {
open.children.push(node);
s.pipe(p.stdio[3]);
p.stderr.on("data", (c) => { logger.mediaplayer("[ffmpeg]", c.toString().trim()); });
/** Write initial silence to prime the ffmpeg stdin pipe (required for amix to detect the input). */
p.stdio[4].write(Buffer.alloc(1024, 0));
p.stdout.pipe(open.process.stdio[open.pipes[0]]);
const pipeNumber = open.pipes[0];
+22 -13
View File
@@ -1,3 +1,12 @@
/**
* @file Tuna.mjs — Tuna — Voicemod Tuna API client for sound effect search and download
* @module src.constants.audio.Tuna
*/
/**
* Tuna API client for searching and downloading sound effects
* from the Voicemod Tuna service (tuna-api.voicemod.net).
*/
import pkg from "follow-redirects";
const { https } = pkg;
@@ -7,11 +16,9 @@ class Tuna {
this.apiKey = auth.key;
}
get(path, params = {}) {
return new Promise((resolve, rej) => {
let query = "";
for (let key in params) {
query += ((query.length === 0) ? "?" : "&") + key + "=" + encodeURIComponent(params[key]);
}
return new Promise((resolve, reject) => {
const qs = new URLSearchParams(params).toString();
const query = qs ? "?" + qs : "";
const options = {
method: "GET",
hostname: "tuna-api.voicemod.net",
@@ -19,21 +26,21 @@ class Tuna {
headers: { "x-api-key": this.apiKey },
maxRedirects: 20
};
const req = https.request(options, function(res) {
const req = https.request(options, (res) => {
const chunks = [];
res.on("data", (chunk) => { chunks.push(chunk); });
res.on("end", () => {
try {
resolve(JSON.parse(Buffer.concat(chunks).toString()));
} catch (e) {
rej(new Error(`Tuna API JSON parse error: ${e.message}`));
reject(new Error(`Tuna API JSON parse error: ${e.message}`));
}
});
});
req.on("error", (error) => { rej(error); });
req.on("error", (error) => { reject(error); });
req.setTimeout(15_000, () => {
req.destroy();
rej(new Error("Tuna API request timeout"));
reject(new Error("Tuna API request timeout"));
});
req.end();
});
@@ -41,9 +48,10 @@ class Tuna {
search(query, page = 1, size = 10) {
return this.get("/v1/sounds/search", { size, page, search: query }).then(results => {
results.items = results.items.map(s => {
s.download = function() {
const oggPath = s.oggPath;
s.download = () => {
return new Promise((resolve, reject) => {
const req = https.get(this.oggPath, { maxRedirects: 20 }, (r) => { resolve(r); });
const req = https.get(oggPath, { maxRedirects: 20 }, (r) => { resolve(r); });
req.on("error", (err) => { reject(err); });
req.setTimeout(15_000, () => { req.destroy(); reject(new Error("Tuna download timeout")); });
});
@@ -55,9 +63,10 @@ class Tuna {
}
getSound(id) {
return this.get("/v1/sounds/" + id).then(sound => {
sound.download = function() {
const oggPath = sound.oggPath;
sound.download = () => {
return new Promise((resolve, reject) => {
const req = https.get(this.oggPath, { maxRedirects: 20 }, (result) => { resolve(result); });
const req = https.get(oggPath, { maxRedirects: 20 }, (result) => { resolve(result); });
req.on("error", (err) => { reject(err); });
req.setTimeout(15_000, () => { req.destroy(); reject(new Error("Tuna download timeout")); });
});
+8 -8
View File
@@ -42,7 +42,7 @@ export class Dashboard {
case "fetchPlayers":
return [...this.remix.players.playerMap.values()]
.filter(p => !p._destroyed)
.map(p => { try { return Dashboard.convertPlayer(p); } catch(_) { return null; } })
.map(p => { try { return Dashboard.convertPlayer(p); } catch(e) { logger.warn("[Dashboard] convertPlayer error:", e?.message); return null; } })
.filter(Boolean);
case "user": {
@@ -209,7 +209,7 @@ export class Dashboard {
data: String(user.id)
}));
}
} catch (_) { }
} catch (_) { logger.warn("[Dashboard] Error:", _.message); }
}
return { message: "Already Connected" };
}
@@ -349,7 +349,7 @@ export class Dashboard {
data: String(user.id)
}));
}
} catch (_) { }
} catch (_) { logger.warn("[Dashboard] Error:", _.message); }
return { message: "Left channel" };
}
try {
@@ -465,7 +465,7 @@ export class Dashboard {
if (!vid) return null;
const durationMs =
typeof vid.duration === "number" ? vid.duration :
typeof vid.duration === "object" && vid.duration?.seconds != null ? vid.duration.seconds * 1000 :
typeof vid.duration === "object" && vid.duration?.seconds !== null ? vid.duration.seconds * 1000 :
0;
return {
title: vid.title,
@@ -542,7 +542,7 @@ export class Dashboard {
if (guild.icon) {
iconUrl = `https://fluxerusercontent.com/icons/${guild.id}/${guild.icon}.webp`;
} else if (typeof guild.iconURL === "function") {
try { iconUrl = guild.iconURL() ?? null; } catch (_) { iconUrl = null; }
try { iconUrl = guild.iconURL() ?? null; } catch (e) { logger.warn("[Dashboard] iconURL error:", e?.message); iconUrl = null; }
}
return {
@@ -566,7 +566,7 @@ export class Dashboard {
if (guild.icon) {
iconUrl = `https://fluxerusercontent.com/icons/${guild.id}/${guild.icon}.webp`;
} else if (typeof guild.iconURL === "function") {
try { iconUrl = guild.iconURL() ?? null; } catch (_) { iconUrl = null; }
try { iconUrl = guild.iconURL() ?? null; } catch (e) { logger.warn("[Dashboard] iconURL error:", e?.message); iconUrl = null; }
}
return {
name: guild.name,
@@ -625,7 +625,7 @@ export class Dashboard {
for (const [mapUserId, info] of vc) {
if (seen.has(mapUserId)) continue;
const infoCh = cleanId(info.channelId);
const infoG = cleanId(info.guildId);
const infoG = cleanId(info.guildId);
if (infoCh === cleanChannelId && infoG === cleanGuildId) {
const botId = player.client?.user?.id;
if (botId && String(mapUserId) === String(botId)) continue;
@@ -800,7 +800,7 @@ export class Dashboard {
let res;
try {
res = await this.db.execute("SELECT * FROM login_codes WHERE user=? AND (verified IS NULL OR verified != true)", [user]);
res = await this.db.execute("SELECT * FROM login_codes WHERE user=? AND (verified IS NULL OR verified !== true)", [user]);
} catch (e) {
const id = Utils.uid();
logger.dashboard("[Dashboard] MySQL error, id:", id, e);
+1 -1
View File
@@ -24,7 +24,7 @@ export default function probe(file) {
const cleanup = () => {
settled = true;
clearTimeout(timeoutHandle);
try { proc.kill(); } catch(e) { }
try { proc.kill(); } catch(e) { /* process already exited */ }
};
const timeoutHandle = setTimeout(() => {