From 68e0b43b772f3652bf4f247d24938ef18f9406cd Mon Sep 17 00:00:00 2001 From: EJClaw Date: Thu, 15 Oct 2026 10:42:06 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B4=87=20=EC=A4=91=EA=B3=84:=20=EC=A7=80?= =?UTF-8?q?=EC=BC=9C=EB=B3=B4=EB=8A=94=20=EC=95=B1=EC=9D=B4=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=84=9C=EB=B2=84=EC=9D=98=20=EC=8A=AC=EB=9E=98?= =?UTF-8?q?=EC=8B=9C=20=EB=AA=85=EB=A0=B9=EC=9D=80=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=EA=B0=80=20=EB=B0=9B=EC=A7=80=20=EC=95=8A=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 봇 토큰을 직접 쓰는 v1.1.0 PC 가 아직 켜져 있으면 같은 명령을 서버와 PC 가 함께 받는다. 서버가 먼저 응답(defer)하면 PC 의 응답이 실패해 /녹음시작 이 동작하지 않으므로, 그 서버를 지켜보는 v1.2.1 앱이 있을 때만 받는다. Co-Authored-By: Claude Opus 5.5 --- app/test/bot-gateway.test.ts | 5 +++++ site/server/src/bot-broker.ts | 3 +++ site/server/src/discord-source.ts | 2 ++ 3 files changed, 10 insertions(+) diff --git a/app/test/bot-gateway.test.ts b/app/test/bot-gateway.test.ts index 6086ca3..d371886 100644 --- a/app/test/bot-gateway.test.ts +++ b/app/test/bot-gateway.test.ts @@ -32,6 +32,7 @@ class FakeSource extends EventEmitter implements BotSource { sent: { guildId: string; payload: any }[] = []; handlers = new Map void; state: (d: any) => void }>(); commands: string[] = []; + wants?: (guildId: string) => boolean; me() { return ME; } @@ -274,9 +275,13 @@ test('봇 중계: 슬래시 명령은 그 서버를 지켜보는 앱으로 가 new Promise((resolve) => s.source.emit('command', { name, guildId: G, user: m(user, user), voiceChannel: { id: VC1, name: '일반' } } satisfies BotCommand, resolve)); try { assert.equal(await cmd('녹음시작', SUPER), '지금 이 서버에서 켜져 있는 겜녹이 앱이 없습니다.'); + // 지켜보는 앱이 없는 서버의 명령은 서버가 받지 않는다 (봇 토큰을 직접 쓰는 v1.1.0 PC 가 응답하게) + assert.equal(s.source.wants?.(G), false); await a.gw.start(); await b.gw.start(); await a.gw.watch(G, { commands: false }); + assert.equal(s.source.wants?.(G), true); + assert.equal(s.source.wants?.(OTHER_G), false); await b.gw.watch(G, { commands: false }); const seenBy: string[] = []; a.gw.on('command', (c, respond) => (seenBy.push(`a:${c.name}`), respond(`A 가 ${c.name}`))); diff --git a/site/server/src/bot-broker.ts b/site/server/src/bot-broker.ts index 6af9072..3cf831c 100644 --- a/site/server/src/bot-broker.ts +++ b/site/server/src/bot-broker.ts @@ -29,6 +29,8 @@ export interface BotCommand { * 이벤트: 'ready', 'guilds', 'voiceState' (BotVoiceEvent), 'command' (BotCommand, respond(content)) */ export interface BotSource extends EventEmitter { + /** 이 서버의 슬래시 명령을 받을지 (지켜보는 앱이 없으면 응답하지 않는다: 아직 봇 토큰을 직접 쓰는 v1.1.0 PC 의 응답을 가로채지 않게) */ + wants?: (guildId: string) => boolean; me(): BotGwMember | null; guilds(): BotGwGuild[]; /** 음성채널 목록과 음성채널에 있는 사람 */ @@ -76,6 +78,7 @@ export class BotBroker { source.on('voiceState', (e: BotVoiceEvent) => { for (const c of this.conns) if (c.guildId === e.guildId) this.send(c, { t: 'voiceState', ...e }); }); + source.wants = (guildId) => [...this.conns].some((c) => c.guildId === guildId); source.on('command', (cmd: BotCommand, respond: (content: string) => void) => void this.onCommand(cmd).then(respond)); // 등록 해제 · 로그아웃된 연결은 30초 안에 끊는다 (해제 · 로그아웃 API 는 kick 으로 바로 끊는다) this.timer = setInterval(() => { diff --git a/site/server/src/discord-source.ts b/site/server/src/discord-source.ts index 192355b..8bdcd2c 100644 --- a/site/server/src/discord-source.ts +++ b/site/server/src/discord-source.ts @@ -18,6 +18,7 @@ const isVoice = (c: { type: ChannelType } | null | undefined): c is VoiceBasedCh export class DiscordSource extends EventEmitter implements BotSource { readonly client: Client; + wants?: (guildId: string) => boolean; constructor(private log: { info: (o: any, m?: string) => void; error: (o: any, m?: string) => void }) { super(); @@ -39,6 +40,7 @@ export class DiscordSource extends EventEmitter implements BotSource { }); c.on(Events.InteractionCreate, async (i) => { if (!i.isChatInputCommand() || !i.guildId || !COMMANDS.some((x) => x.name === i.commandName)) return; + if (this.wants && !this.wants(i.guildId)) return; try { await i.deferReply({ flags: MessageFlags.Ephemeral }); } catch (e) {