mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
initial push to remix-bot/fluxer
This commit is contained in:
commit
2820cc881c
63 files changed
+16005
No files matched your search
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Logger — configurable console output for Fluxer.
|
||||
*
|
||||
* Categories (all under config.logging):
|
||||
* enabled — master switch; false silences everything except errors
|
||||
* player — voice connect/disconnect, stream start, volume restore
|
||||
* inactivity — alone-check, inactivity timer, human detection
|
||||
* voice247 — 24/7 rejoin, auto-save channel, intentional leave skip
|
||||
* voiceState — raw VOICE_STATE_UPDATE events (human join/leave detection)
|
||||
* mediaplayer — MediaPlayer publish, LiveKit room state, connection recovery
|
||||
* commands — command load, module load, error IDs
|
||||
* guild — GuildCreate / GuildDelete lifecycle
|
||||
* recovery — session save/restore on reboot
|
||||
* settings — settings DB load, remote update errors
|
||||
* worker — worker URL cleaning, result logging
|
||||
* moonlink — moonlink node events
|
||||
* errors — always on; console.error calls (cannot be disabled)
|
||||
*/
|
||||
|
||||
let _config = null;
|
||||
|
||||
/**
|
||||
* Call once at startup with the loaded config object.
|
||||
* @param {object} config
|
||||
*/
|
||||
export function initLogger(config) {
|
||||
_config = config?.logging ?? {};
|
||||
}
|
||||
|
||||
function isEnabled(category) {
|
||||
if (!_config) return true; // default on if not yet initialised
|
||||
if (_config.enabled === false) return false;
|
||||
// If the category key is missing, default to true
|
||||
return _config[category] !== false;
|
||||
}
|
||||
|
||||
function ts() {
|
||||
return new Date().toISOString().replace("T", " ").slice(0, 19);
|
||||
}
|
||||
|
||||
export const logger = {
|
||||
// ── always-on (errors / warnings critical to operation) ──────────────────
|
||||
error(tag, ...args) {
|
||||
console.error(`[${ts()}] ${tag}`, ...args);
|
||||
},
|
||||
warn(tag, ...args) {
|
||||
// warnings are on unless master switch is off
|
||||
if (_config?.enabled === false) return;
|
||||
console.warn(`[${ts()}] ${tag}`, ...args);
|
||||
},
|
||||
|
||||
// ── categorised logs ─────────────────────────────────────────────────────
|
||||
player(...args) { if (isEnabled("player")) console.log(`[${ts()}]`, ...args); },
|
||||
inactivity(...args) { if (isEnabled("inactivity")) console.log(`[${ts()}]`, ...args); },
|
||||
voice247(...args) { if (isEnabled("voice247")) console.log(`[${ts()}]`, ...args); },
|
||||
voiceState(...args) { if (isEnabled("voiceState")) console.log(`[${ts()}]`, ...args); },
|
||||
mediaplayer(...args) { if (isEnabled("mediaplayer")) console.log(`[${ts()}]`, ...args); },
|
||||
commands(...args) { if (isEnabled("commands")) console.log(`[${ts()}]`, ...args); },
|
||||
guild(...args) { if (isEnabled("guild")) console.log(`[${ts()}]`, ...args); },
|
||||
recovery(...args) { if (isEnabled("recovery")) console.log(`[${ts()}]`, ...args); },
|
||||
settings(...args) { if (isEnabled("settings")) console.log(`[${ts()}]`, ...args); },
|
||||
worker(...args) { if (isEnabled("worker")) console.log(`[${ts()}]`, ...args); },
|
||||
moonlink(...args) { if (isEnabled("moonlink")) console.log(`[${ts()}]`, ...args); },
|
||||
aloneCheck(...args) { if (isEnabled("inactivity")) console.log(`[${ts()}]`, ...args); },
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
import { logger } from "../Logger.mjs";
|
||||
import ffmpeg from "ffmpeg-static";
|
||||
import { Transform } from "node:stream";
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
class StreamMerger extends Transform {
|
||||
ffmpegPath = ffmpeg;
|
||||
ffmpeg = null;
|
||||
streamTree = [];
|
||||
|
||||
constructor(streamOptions) {
|
||||
super(streamOptions);
|
||||
}
|
||||
_transform(chunk, _enc, cb) {
|
||||
if (!this.ffmpeg) { this.push(chunk); return cb(); }
|
||||
this.ffmpeg.stdio[3].write(chunk);
|
||||
cb();
|
||||
}
|
||||
pipe(stream) {
|
||||
return super.pipe(stream);
|
||||
}
|
||||
setupBaseFfmpeg() {
|
||||
this.ffmpeg = this.spawnFfmpeg();
|
||||
this.ffmpeg.stderr.on("data", (chunk) => { logger.mediaplayer("[ffmpeg]", chunk.toString().trim()); });
|
||||
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(" ");
|
||||
return spawn(this.ffmpegPath, args, {
|
||||
windowsHide: true,
|
||||
stdio: ["pipe", "pipe", "pipe", "pipe", "pipe"]
|
||||
});
|
||||
}
|
||||
findOpenNode() {
|
||||
if (this.streamTree.length === 0) {
|
||||
this.streamTree.push({ process: this.ffmpeg, pipes: [4], available: true, children: [] });
|
||||
return this.streamTree[0];
|
||||
}
|
||||
const findChild = (node) => {
|
||||
if (node.available) return node;
|
||||
for (const child of node.children) {
|
||||
const c = findChild(child);
|
||||
if (c) return c;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
for (const node of this.streamTree) {
|
||||
const firstChild = findChild(node);
|
||||
if (firstChild) return firstChild;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
addStream(s) {
|
||||
if (!this.ffmpeg) this.setupBaseFfmpeg();
|
||||
const open = this.findOpenNode();
|
||||
if (!open) throw "Impossible case detected. No free merge node found.";
|
||||
const p = this.spawnFfmpeg();
|
||||
const node = { process: p, pipes: [4], available: true, parent: open, children: [] };
|
||||
open.children.push(node);
|
||||
s.pipe(p.stdio[3]);
|
||||
p.stderr.on("data", (c) => { logger.mediaplayer("[ffmpeg]", c.toString().trim()); });
|
||||
p.stdio[4].write(Buffer.alloc(1024, 0));
|
||||
p.stdout.pipe(open.process.stdio[open.pipes[0]]);
|
||||
const pipeNumber = open.pipes[0].valueOf();
|
||||
open.pipes.splice(0, 1);
|
||||
if (open.pipes.length === 0) open.available = false;
|
||||
p.on("exit", () => {
|
||||
open.pipes.push(pipeNumber);
|
||||
open.available = true;
|
||||
const idx = open.children.findIndex(c => c === node);
|
||||
if (idx === -1) throw "Impossible case detected. Damaged node structure.";
|
||||
open.children.splice(idx, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default StreamMerger;
|
||||
@@ -0,0 +1,57 @@
|
||||
import { https } from "follow-redirects";
|
||||
|
||||
class Tuna {
|
||||
apiKey = null;
|
||||
constructor(auth) {
|
||||
this.apiKey = auth.key;
|
||||
}
|
||||
get(path, params = {}) {
|
||||
return new Promise((resolve, rej) => {
|
||||
var query = "";
|
||||
for (let key in params) {
|
||||
query += ((query.length === 0) ? "?" : "&") + key + "=" + encodeURIComponent(params[key]);
|
||||
}
|
||||
var options = {
|
||||
method: "GET",
|
||||
hostname: "tuna-api.voicemod.net",
|
||||
path: path + query,
|
||||
headers: { "x-api-key": this.apiKey },
|
||||
maxRedirects: 20
|
||||
};
|
||||
var req = https.request(options, function(res) {
|
||||
var chunks = [];
|
||||
res.on("data", (chunk) => { chunks.push(chunk); });
|
||||
res.on("end", () => { resolve(JSON.parse(Buffer.concat(chunks).toString())); });
|
||||
res.on("error", (error) => { rej(error); });
|
||||
});
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
search(query, page = 1, size = 10) {
|
||||
return new Promise(async res => {
|
||||
const results = await this.get("/v1/sounds/search", { size, page, search: query });
|
||||
results.items = results.items.map(s => {
|
||||
s.download = function() {
|
||||
return new Promise(resolve => {
|
||||
https.get(this.oggPath, (r) => { resolve(r); });
|
||||
});
|
||||
};
|
||||
return s;
|
||||
});
|
||||
res(results);
|
||||
});
|
||||
}
|
||||
getSound(id) {
|
||||
return new Promise(async res => {
|
||||
const sound = await this.get("/v1/sounds/" + id);
|
||||
sound.download = function() {
|
||||
return new Promise(res => {
|
||||
https.get(this.oggPath, (result) => { res(result); });
|
||||
});
|
||||
};
|
||||
res(sound);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Tuna;
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* providers.mjs — Single source of truth for all provider data.
|
||||
*
|
||||
* PROVIDERS — full map: { prefix, label } — used by worker.mjs for search
|
||||
* PROVIDER_NAMES — derived label-only map — used by Player.mjs for display
|
||||
* PROVIDER_CHOICES — ordered list of valid keys — used by command option builders
|
||||
*
|
||||
* Edit only here; worker.mjs and Player.mjs import from this file.
|
||||
*/
|
||||
|
||||
export const PROVIDERS = {
|
||||
// ── Standard search ──────────────────────────────────────────────────────
|
||||
yt: { prefix: "ytsearch", label: "YouTube" },
|
||||
ytm: { prefix: "ytmsearch", label: "YouTube Music" },
|
||||
scld: { prefix: "scsearch", label: "SoundCloud" },
|
||||
sc: { prefix: "scsearch", label: "SoundCloud" },
|
||||
sp: { prefix: "spsearch", label: "Spotify" },
|
||||
spotify: { prefix: "spsearch", label: "Spotify" },
|
||||
am: { prefix: "amsearch", label: "Apple Music" },
|
||||
apple: { prefix: "amsearch", label: "Apple Music" },
|
||||
dz: { prefix: "dzsearch", label: "Deezer" },
|
||||
deezer: { prefix: "dzsearch", label: "Deezer" },
|
||||
td: { prefix: "tdsearch", label: "Tidal" },
|
||||
tidal: { prefix: "tdsearch", label: "Tidal" },
|
||||
bc: { prefix: "bcsearch", label: "Bandcamp" },
|
||||
bandcamp: { prefix: "bcsearch", label: "Bandcamp" },
|
||||
adm: { prefix: "admsearch", label: "Audiomack" },
|
||||
audiomack: { prefix: "admsearch", label: "Audiomack" },
|
||||
gaana: { prefix: "gaanasearch", label: "Gaana" },
|
||||
js: { prefix: "jssearch", label: "JioSaavn" },
|
||||
jiosaavn: { prefix: "jssearch", label: "JioSaavn" },
|
||||
lf: { prefix: "lfsearch", label: "Last.fm" },
|
||||
lastfm: { prefix: "lfsearch", label: "Last.fm" },
|
||||
pd: { prefix: "pdsearch", label: "Pandora" },
|
||||
pandora: { prefix: "pdsearch", label: "Pandora" },
|
||||
vk: { prefix: "vksearch", label: "VK Music" },
|
||||
mc: { prefix: "mcsearch", label: "Mixcloud" },
|
||||
mixcloud: { prefix: "mcsearch", label: "Mixcloud" },
|
||||
nc: { prefix: "ncsearch", label: "NicoVideo" },
|
||||
nicovideo: { prefix: "ncsearch", label: "NicoVideo" },
|
||||
bb: { prefix: "bilibili", label: "Bilibili" },
|
||||
bilibili: { prefix: "bilibili", label: "Bilibili" },
|
||||
sh: { prefix: "shsearch", label: "Shazam" },
|
||||
shazam: { prefix: "shsearch", label: "Shazam" },
|
||||
sl: { prefix: "slsearch", label: "Songlink" },
|
||||
songlink: { prefix: "slsearch", label: "Songlink" },
|
||||
qb: { prefix: "qbsearch", label: "Qobuz" },
|
||||
qobuz: { prefix: "qbsearch", label: "Qobuz" },
|
||||
ym: { prefix: "ymsearch", label: "Yandex Music" },
|
||||
yandex: { prefix: "ymsearch", label: "Yandex Music" },
|
||||
au: { prefix: "ausearch", label: "Audius" },
|
||||
audius: { prefix: "ausearch", label: "Audius" },
|
||||
az: { prefix: "azsearch", label: "Amazon Music" },
|
||||
amazon: { prefix: "azsearch", label: "Amazon Music" },
|
||||
ag: { prefix: "agsearch", label: "Anghami" },
|
||||
anghami: { prefix: "agsearch", label: "Anghami" },
|
||||
bk: { prefix: "bksearch", label: "Bluesky" },
|
||||
bluesky: { prefix: "bksearch", label: "Bluesky" },
|
||||
// ── Recommendations ──────────────────────────────────────────────────────
|
||||
ytrec: { prefix: "ytrec", label: "YouTube (recommended)" },
|
||||
sprec: { prefix: "sprec", label: "Spotify (recommended)" },
|
||||
dzrec: { prefix: "dzrec", label: "Deezer (recommended)" },
|
||||
tdrec: { prefix: "tdrec", label: "Tidal (recommended)" },
|
||||
jsrec: { prefix: "jsrec", label: "JioSaavn (recommended)" },
|
||||
vkrec: { prefix: "vkrec", label: "VK Music (recommended)" },
|
||||
// ── TTS ──────────────────────────────────────────────────────────────────
|
||||
gtts: { prefix: "gtts", label: "Google TTS" },
|
||||
tts: { prefix: "gtts", label: "Google TTS" },
|
||||
ftts: { prefix: "ftts", label: "Flowery TTS" },
|
||||
};
|
||||
|
||||
/** Label-only map — convenience alias for display use (e.g. Player.mjs). */
|
||||
export const PROVIDER_NAMES = Object.fromEntries(
|
||||
Object.entries(PROVIDERS).map(([k, v]) => [k, v.label])
|
||||
);
|
||||
|
||||
export const PROVIDER_CHOICES = [
|
||||
"ytm", "yt", "scld", "sc",
|
||||
"sp", "spotify",
|
||||
"am", "apple",
|
||||
"dz", "deezer",
|
||||
"td", "tidal",
|
||||
"bc", "bandcamp",
|
||||
"adm", "audiomack",
|
||||
"gaana",
|
||||
"js", "jiosaavn",
|
||||
"lf", "lastfm",
|
||||
"pd", "pandora",
|
||||
"vk",
|
||||
"mc", "mixcloud",
|
||||
"nc", "nicovideo",
|
||||
"bb", "bilibili",
|
||||
"sh", "shazam",
|
||||
"sl", "songlink",
|
||||
"qb", "qobuz",
|
||||
"ym", "yandex",
|
||||
"au", "audius",
|
||||
"az", "amazon",
|
||||
"ag", "anghami",
|
||||
"bk", "bluesky",
|
||||
"ytrec", "sprec", "dzrec", "tdrec", "jsrec", "vkrec",
|
||||
"gtts", "tts", "ftts",
|
||||
];
|
||||
Reference in new issue
Block a user