앱 v1.1.0: 겜녹이 봇 기본 연결 + '다른 봇으로 진행하기'

- 설정 discord.botMode (builtin 기본 / custom). 겜녹이 봇은 토큰 입력 없이 연결
- 겜녹이 봇 토큰은 저장소에 두지 않고 빌드 때 GVR_BUILTIN_BOT_TOKEN 에서 읽어 감춘 값으로 박는다
- 마법사·디스코드 탭에 봇 선택 카드, 다른 봇일 때만 토큰 입력. 오가도 넣은 토큰 유지
- v1.0.0 에서 토큰을 넣어 쓰던 설치는 custom 으로 이어짐
- win-ci full 빌드가 서버 비밀 저장소에서 토큰을 넣고, smoke 에 기본 봇 로그인 결과 기록
- 테스트 6개 추가 (기본·다른 봇·전환·이전 설치·기본 봇 없는 빌드·개발 env)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-15 04:54:48 +09:00
parent 0635294c55
commit 35d2cab792
18 changed files with 301 additions and 55 deletions

View File

@@ -0,0 +1,32 @@
// 기본(겜녹이) 봇 토큰. 저장소에는 넣지 않는다.
// 빌드할 때 build.mjs 가 GVR_BUILTIN_BOT_TOKEN 환경변수를 읽어 encodeBuiltinToken() 결과를
// __GVR_BUILTIN_BOT__ 상수로 박는다 (esbuild define). 평문이 바이너리에 그대로 보이지 않게
// XOR + base64 로 감출 뿐, 암호화는 아니다 - exe 를 풀면 꺼낼 수 있다.
declare const __GVR_BUILTIN_BOT__: string | undefined;
const KEY = Buffer.from('gvr-gemnoki-builtin-bot', 'utf8');
function xor(b: Buffer): Buffer {
const out = Buffer.alloc(b.length);
for (let i = 0; i < b.length; i++) out[i] = b[i]! ^ KEY[i % KEY.length]! ^ ((i * 31) & 0xff);
return out;
}
export function encodeBuiltinToken(token: string): string {
return xor(Buffer.from(token, 'utf8')).reverse().toString('base64');
}
export function decodeBuiltinToken(blob: string): string {
return xor(Buffer.from(blob, 'base64').reverse()).toString('utf8');
}
/** 이 빌드에 들어 있는 겜녹이 봇 토큰. 개발 실행(tsx)이나 토큰 없이 만든 빌드는 null */
export function builtinBotToken(): string | null {
const blob = typeof __GVR_BUILTIN_BOT__ === 'string' ? __GVR_BUILTIN_BOT__ : '';
if (!blob) return null;
try {
return decodeBuiltinToken(blob) || null;
} catch {
return null;
}
}

View File

@@ -111,9 +111,9 @@ export async function startCore(opts: CoreOptions) {
if (opts.apiPort) await api.listen({ host: '127.0.0.1', port: opts.apiPort });
const startBot = async () => {
const token = settings.getSecret('botToken');
const token = settings.activeBotToken();
if (!token) {
log.warn('봇 토큰이 없습니다. 설정에서 입력해 주세요.');
log.warn(S().discord.botMode === 'builtin' ? '이 빌드에는 겜녹이 기본 봇이 없습니다. 설정에서 다른 봇 토큰을 넣어 주세요.' : '봇 토큰이 없습니다. 설정에서 입력해 주세요.');
return;
}
try {

View File

@@ -1,10 +1,13 @@
import fs from 'node:fs';
import path from 'node:path';
import { builtinBotToken } from './builtin-bot.js';
export interface Settings {
version: 1;
firstRunDone: boolean;
discord: {
/** builtin = 앱에 들어 있는 겜녹이 봇, custom = 사용자가 넣은 다른 봇 토큰 */
botMode: 'builtin' | 'custom';
guildId: string | null;
/** 따라갈 유저 (보통 게임 PC 주인) */
followUserId: string | null;
@@ -76,6 +79,7 @@ export function defaultSettings(): Settings {
version: 1,
firstRunDone: false,
discord: {
botMode: 'builtin',
guildId: null,
followUserId: null,
followEnabled: true,
@@ -144,15 +148,22 @@ export class SettingsStore {
private secrets: Secrets;
private listeners = new Set<(s: Settings) => void>();
private builtinBot: string | null;
private envBotToken: string | null;
constructor(
private dataDir: string,
private codec: SecretCodec = plainCodec,
opts: { builtinBotToken?: string | null } = {},
) {
this.file = path.join(dataDir, 'settings.json');
this.secretFile = path.join(dataDir, 'secrets.bin');
this.builtinBot = opts.builtinBotToken !== undefined ? opts.builtinBotToken : builtinBotToken();
this.cur = defaultSettings();
let saved: any = null;
try {
this.cur = deepMerge(defaultSettings(), JSON.parse(fs.readFileSync(this.file, 'utf8')));
saved = JSON.parse(fs.readFileSync(this.file, 'utf8'));
this.cur = deepMerge(defaultSettings(), saved);
} catch {
/* 첫 실행 */
}
@@ -162,8 +173,20 @@ export class SettingsStore {
} catch {
/* 없음 */
}
// 개발/헤드리스: 환경변수로 비밀값 주입
if (process.env.GVR_BOT_TOKEN) this.secrets.botToken = process.env.GVR_BOT_TOKEN;
// v1.0.0 에서 직접 토큰을 넣어 쓰던 설치는 그 봇을 계속 쓴다
if (saved && !saved.discord?.botMode && this.secrets.botToken) this.cur.discord.botMode = 'custom';
// 개발/헤드리스: 환경변수 토큰이 있으면 모드와 상관없이 그것을 쓴다
this.envBotToken = process.env.GVR_BOT_TOKEN || null;
}
/** 이 빌드에 겜녹이 기본 봇이 들어 있는지 */
get hasBuiltinBot(): boolean {
return !!this.builtinBot;
}
/** 지금 모드에서 봇이 로그인할 토큰 (없으면 null) */
activeBotToken(): string | null {
if (this.envBotToken) return this.envBotToken;
return this.cur.discord.botMode === 'builtin' ? this.builtinBot : this.secrets.botToken || null;
}
get(): Settings {