// 실제 디스코드: DiscordSource(사이트 서버 코드)로 봇을 음성채널에 넣었다 빼며 상태 메시지가 바뀌는지 본다 import { Client, GatewayIntentBits } from 'discord.js'; import { DiscordSource } from '../src/discord-source.ts'; // 사용: TB=<봇 토큰> GUILD=<서버 아이디> VC=<빈 음성채널 아이디> node --import tsx scripts/presence-e2e.mts const G = process.env.GUILD!, VC = process.env.VC!; const t0 = Date.now(); const at = () => `${((Date.now() - t0) / 1000).toFixed(1)}s`; const log = { info: (o: any, m?: string) => console.log(at(), 'LOG', m, JSON.stringify(o)), error: (o: any, m?: string) => console.log(at(), 'ERR', m, o?.message ?? o) }; const src = new DiscordSource(log); // 관찰자: 같은 서버의 다른 세션이 디스코드에서 받은 봇 상태 (presence intent 가 있으면) const obs = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMembers] }); obs.on('presenceUpdate', (_o, n) => n.userId === src.client.user?.id && console.log(at(), 'OBSERVED', n.status, JSON.stringify(n.activities.map((a) => a.state)))); await src.login(process.env.TB!); await new Promise((r) => src.once('ready', r)); await obs.login(process.env.TB!).catch((e) => console.log('observer off:', e.message)); await new Promise((r) => setTimeout(r, 3000)); const send = (ch: string | null) => src.voiceAdapter(G, { server: () => undefined, state: () => undefined }).send({ op: 4, d: { guild_id: G, channel_id: ch, self_mute: true, self_deaf: true } }); console.log(at(), 'JOIN'); send(VC); await new Promise((r) => setTimeout(r, 5000)); console.log(at(), 'presence now', src.client.user!.presence.status, JSON.stringify(src.client.user!.presence.activities.map((a) => a.state)), 'inVoice', !!src.client.guilds.cache.get(G)!.members.me!.voice.channelId); console.log(at(), 'LEAVE'); send(null); await new Promise((r) => setTimeout(r, 5000)); console.log(at(), 'presence now', src.client.user!.presence.status, JSON.stringify(src.client.user!.presence.activities.map((a) => a.state)), 'inVoice', !!src.client.guilds.cache.get(G)!.members.me!.voice.channelId); await obs.destroy().catch(() => undefined); await src.destroy();