refactor: make hardcoded values configurable via env vars

This commit is contained in:
MythEclipse
2026-05-13 16:05:19 +07:00
parent 48cc83f624
commit 7a5ac2e34a
6 changed files with 64 additions and 10 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import { EndBehaviorType, type VoiceReceiver } from "@discordjs/voice";
import { config } from "../config";
export interface AudioStreamHandlers {
onPacket: (chunk: Buffer) => void;
@@ -14,7 +15,7 @@ export function subscribeToAudioStream(
const audioStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 3000,
duration: config.audioStreamSilenceDurationMs,
},
});
+6 -1
View File
@@ -1,4 +1,5 @@
import prism from "prism-media";
import { config } from "../config";
export interface OpusDecoderOptions {
cooldownMs: number;
@@ -23,7 +24,11 @@ export class OpusDecoder {
this.createDecoderFn =
options.createDecoder ??
(() =>
new prism.opus.Decoder({ frameSize: 960, channels: 2, rate: 48000 }));
new prism.opus.Decoder({
frameSize: config.opusFrameSize,
channels: config.audioChannels as 1 | 2,
rate: config.audioSampleRate as 8000 | 12000 | 16000 | 24000 | 48000,
}));
}
rotateIfNeeded(): void {
+14 -2
View File
@@ -1,5 +1,6 @@
import path from "node:path";
import type { Client, VoiceChannel } from "discord.js-selfbot-v13";
import { config } from "../config";
import type { SegmentMetadata, SegmentState, UserMetadata } from "../types";
export async function collectUserMetadata(
@@ -30,8 +31,19 @@ export async function collectUserMetadata(
tag: user?.tag ?? "Unknown#0000",
displayName: member?.displayName ?? username,
avatarUrl:
user?.displayAvatarURL({ format: "png", size: 64 }) ??
"https://cdn.discordapp.com/embed/avatars/0.png",
user?.displayAvatarURL({
format: "png",
size: config.avatarSize as
| 16
| 32
| 64
| 128
| 256
| 512
| 1024
| 2048
| 4096,
}) ?? "https://cdn.discordapp.com/embed/avatars/0.png",
bot: user?.bot ?? false,
roles,
highestRole: roles[0] ?? null,