Files
game_voice_recorder/site/server/scripts/presence-e2e.mts
EJClaw 3f7bf1cb86 v1.3.5: 표시 이름 빈틈 — 이름 바꾼 뒤 도착한 범인 분석에도 예전 이름이 남지 않게
- 가린 예전 이름을 meta.hidden_names 에 기억, 분석 저장(Culprit.save) · 이름 다시 받기(setDisplayNames, 건너뛰기 없이 전체)에서 바꿈
- 회귀 테스트: 이름을 바꾼 뒤 예전 이름이 든 분석 저장 → DB 에 예전 이름 0건 (예전 코드에서 실패 확인)
- site/server/scripts/presence-e2e.mts: 실제 디스코드에서 봇 음성 입장/퇴장 → 상태 메시지 녹음 중/대기 중 전환 확인

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 03:14:00 +09:00

26 lines
2.2 KiB
TypeScript

// 실제 디스코드: 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();