// M0 검증: 겜녹이 봇이 DAVE(E2EE) 음성채널에 실제로 붙는지, TTS 안내를 재생하는지, (말하는 사람이 있으면) 유저별 수신이 되는지. // node --import tsx scripts/voice-smoke.mts [seconds] import { Client, GatewayIntentBits } from 'discord.js'; import { joinVoiceChannel, entersState, VoiceConnectionStatus, createAudioPlayer, createAudioResource, StreamType, AudioPlayerStatus, EndBehaviorType } from '@discordjs/voice'; import fs from 'node:fs'; import path from 'node:path'; import { OggOpusWriter } from '../src/core/discord/ogg.ts'; const chId = process.argv[2]; const secs = Number(process.argv[3] || 10); const outDir = process.env.OUT_DIR || path.resolve('.voice-smoke'); fs.mkdirSync(outDir, { recursive: true }); const token = process.env.GVR_BOT_TOKEN || JSON.parse(fs.readFileSync('/home/claude/.config/ejclaw/secrets.json', 'utf8')).credentials['discord.com/bot/game-voice-recorder'].token; const c = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] }); c.once('clientReady', async () => { const ch: any = await c.channels.fetch(chId); console.log('channel', ch.name); const t0 = Date.now(); const conn = joinVoiceChannel({ channelId: ch.id, guildId: ch.guild.id, adapterCreator: ch.guild.voiceAdapterCreator, selfDeaf: false, selfMute: false, daveEncryption: true }); conn.on('stateChange', (o, n) => console.log(`state ${o.status} -> ${n.status} (+${Date.now() - t0}ms)`)); try { await entersState(conn, VoiceConnectionStatus.Ready, 20000); } catch (e) { console.log('FAIL: not ready', e); process.exit(2); } const net: any = (conn.state as any).networking?.state; console.log('READY in', Date.now() - t0, 'ms; encryption mode:', net?.connectionData?.encryptionMode, '; DAVE protocol:', net?.dave?.protocolVersion ?? net?.dave?.session?.protocolVersion ?? 'n/a'); const player = createAudioPlayer(); conn.subscribe(player); player.play(createAudioResource(fs.createReadStream(path.resolve('resources/tts/announce-default.webm')), { inputType: StreamType.WebmOpus })); await entersState(player, AudioPlayerStatus.Playing, 5000).then(() => console.log('TTS playing')).catch(() => console.log('TTS did not start')); const got: Record = {}; conn.receiver.speaking.on('start', (uid) => { if (conn.receiver.subscriptions.has(uid)) return; const w = new OggOpusWriter(path.join(outDir, `${uid}-${Date.now()}.ogg`)); const s = conn.receiver.subscribe(uid, { end: { behavior: EndBehaviorType.AfterSilence, duration: 800 } }); s.on('data', (p: Buffer) => { got[uid] = (got[uid] || 0) + 1; w.write(p); }); s.once('end', () => w.close()); }); await new Promise((r) => setTimeout(r, secs * 1000)); console.log('received packets per user:', JSON.stringify(got)); conn.destroy(); await c.destroy(); process.exit(0); }); await c.login(token);