v1.3.4: 슬래시 명령 무응답 고침 · 녹음 중 봇 상태 메시지
- 원인: 그 서버를 지켜보는 앱이 없으면 discord-source 가 명령을 그냥 무시 → 디스코드 "애플리케이션이 응답하지 않았어요"
→ 1.5초 기다린 뒤(옛 v1.1.0 PC 가 먼저 받았으면 '이미 응답함'으로 빠짐) 이유를 답한다:
앱 없음 / 내 앱이 다른 서버를 녹음 대상으로 정함 / 내 앱이 아직 연결 중. 서버 로그에 남김
- 앱: 지켜보던 중 권한 재확인으로 watch_denied 를 받으면 1분 뒤 다시 지켜보기 요청 (명령 · 음성 상태가 영영 끊기지 않게)
- 상태 메시지: 봇이 어느 서버에서든 음성채널에 있으면 dnd + "🔴 녹음 중", 아니면 online + "🎙️ 대기 중 · /녹음시작"
(겜녹이 봇은 사이트 서버, 다른 봇 모드는 LocalGateway). 테스트 봇으로 실제 디스코드가 형식을 받는 것 확인
- 테스트: 앱 41 · 서버 16 통과
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -302,7 +302,14 @@ export class BotBroker {
|
||||
/** 슬래시 명령을 맞는 앱으로 보내고 첫 응답을 돌려준다 */
|
||||
private async onCommand(cmd: BotCommand): Promise<string> {
|
||||
const here = [...this.conns].filter((c) => c.guildId === cmd.guildId).sort((a, b) => b.at - a.at);
|
||||
if (!here.length) return '지금 이 서버에서 켜져 있는 겜녹이 앱이 없습니다.';
|
||||
if (!here.length) {
|
||||
// 명령한 사람의 앱이 켜져 있는데 다른 서버를 녹음 대상으로 잡아 둔 경우를 알려 준다
|
||||
const own = [...this.conns].filter((c) => c.userId === cmd.user.id);
|
||||
this.log.info({ guild: cmd.guildId, user: cmd.user.id, cmd: cmd.name, apps: this.conns.size, own: own.map((c) => c.guildId) }, '슬래시 명령: 이 서버를 지켜보는 앱 없음');
|
||||
if (own.some((c) => c.guildId)) return '내 겜녹이 앱이 다른 디스코드 서버를 녹음 대상으로 정해 두었습니다. 게임 PC 의 겜녹이 설정 → 디스코드 → "녹음할 서버"를 이 서버로 바꿔 주세요.';
|
||||
if (own.length) return '내 겜녹이 앱이 이 서버에 아직 연결되지 않았습니다. 잠시 뒤 다시 시도하거나, 겜녹이 설정 → 디스코드에서 "녹음할 서버"를 확인해 주세요.';
|
||||
return '지금 이 서버에서 켜져 있는 겜녹이 앱이 없습니다. 게임 PC 에서 겜녹이를 켜고 로그인해 주세요.';
|
||||
}
|
||||
const owner = this.owners.get(cmd.guildId)?.conn;
|
||||
const mine = here.find((c) => c.userId === cmd.user.id);
|
||||
let targets: Conn[];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// 서버의 겜녹이 봇 디스코드 연결 (discord.js). bot-broker.ts 의 BotSource 구현
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { ChannelType, Client, Events, GatewayIntentBits, MessageFlags, PermissionFlagsBits, type Guild, type GuildMember, type VoiceBasedChannel } from 'discord.js';
|
||||
import { ActivityType, ChannelType, Client, Events, GatewayIntentBits, MessageFlags, PermissionFlagsBits, type Guild, type GuildMember, type VoiceBasedChannel } from 'discord.js';
|
||||
import type { BotGwChannel, BotGwGuild, BotGwMember } from '@gvr/shared';
|
||||
import type { BotCommand, BotSource, BotVoiceEvent } from './bot-broker.js';
|
||||
|
||||
@@ -14,6 +14,13 @@ export const COMMANDS = [
|
||||
|
||||
const member = (m: GuildMember): BotGwMember => ({ id: m.id, name: m.displayName, avatar: m.displayAvatarURL({ size: 128 }), bot: m.user.bot });
|
||||
const guild = (g: Guild): BotGwGuild => ({ id: g.id, name: g.name, icon: g.iconURL({ size: 128 }) });
|
||||
/** 봇 상태 메시지: 어느 서버에서든 음성채널에 들어가 있으면(= 녹음 중) 빨간 "녹음 중", 아니면 대기 */
|
||||
export function botPresence(recording: boolean) {
|
||||
return recording
|
||||
? { status: 'dnd' as const, activities: [{ type: ActivityType.Custom, name: 'custom', state: '🔴 녹음 중' }] }
|
||||
: { status: 'online' as const, activities: [{ type: ActivityType.Custom, name: 'custom', state: '🎙️ 대기 중 · /녹음시작' }] };
|
||||
}
|
||||
|
||||
const isVoice = (c: { type: ChannelType } | null | undefined): c is VoiceBasedChannel => !!c && (c.type === ChannelType.GuildVoice || c.type === ChannelType.GuildStageVoice);
|
||||
|
||||
export class DiscordSource extends EventEmitter implements BotSource {
|
||||
@@ -26,6 +33,8 @@ export class DiscordSource extends EventEmitter implements BotSource {
|
||||
this.client = c;
|
||||
c.on(Events.ClientReady, () => {
|
||||
log.info({ bot: c.user?.tag, guilds: c.guilds.cache.size }, '겜녹이 봇 디스코드 연결');
|
||||
this.recording = null;
|
||||
this.updatePresence();
|
||||
this.emit('ready');
|
||||
});
|
||||
c.on(Events.GuildCreate, () => this.emit('guilds'));
|
||||
@@ -41,6 +50,7 @@ export class DiscordSource extends EventEmitter implements BotSource {
|
||||
c.on(Events.GuildDelete, () => this.emit('guilds'));
|
||||
c.on(Events.Error, (e) => log.error(e, '디스코드 오류'));
|
||||
c.on(Events.VoiceStateUpdate, (o, n) => {
|
||||
if (n.id === c.user?.id) this.updatePresence();
|
||||
const m = n.member ?? o.member;
|
||||
if (!m) return;
|
||||
const ch = n.channel;
|
||||
@@ -49,10 +59,14 @@ 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;
|
||||
// 이 서버를 지켜보는 앱이 없으면 1.5초 기다렸다가 응답한다: 봇 토큰을 직접 쓰는 옛 PC(v1.1.0)가 먼저 받았으면
|
||||
// 그쪽 응답을 그대로 두고(아래 deferReply 가 '이미 응답함'으로 실패), 아무도 받지 않았으면 이유를 알려 준다.
|
||||
// (예전에는 그냥 무시해서 디스코드에 "애플리케이션이 응답하지 않았어요"만 떴다)
|
||||
if (this.wants && !this.wants(i.guildId)) await new Promise((r) => setTimeout(r, 1500));
|
||||
try {
|
||||
await i.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
if (e?.code === 40060 || e?.code === 'InteractionAlreadyReplied') return;
|
||||
log.error(e, '명령 응답 실패');
|
||||
return;
|
||||
}
|
||||
@@ -68,6 +82,18 @@ export class DiscordSource extends EventEmitter implements BotSource {
|
||||
});
|
||||
}
|
||||
|
||||
private recording: boolean | null = null;
|
||||
/** 봇이 어느 서버에서든 음성채널에 있으면 녹음 중으로 상태 메시지를 바꾼다 */
|
||||
private updatePresence(): void {
|
||||
const c = this.client;
|
||||
if (!c.isReady()) return;
|
||||
const on = c.guilds.cache.some((g) => !!g.members.me?.voice.channelId);
|
||||
if (on === this.recording) return;
|
||||
this.recording = on;
|
||||
c.user.setPresence(botPresence(on));
|
||||
this.log.info({ recording: on }, '봇 상태 메시지 변경');
|
||||
}
|
||||
|
||||
login(token: string): Promise<string> {
|
||||
return this.client.login(token);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user