v1.3.3: 따라갈 사람 목록 · 롤 채팅 OCR 제거 · 표시 이름(실명 숨기기)
- 따라갈 사람: 봇이 서버를 지켜보기 전 멤버 요청을 사이트 서버가 forbidden 으로 거절하고 앱이 오류를 숨겨 빈 목록이 됐다 → 가입한 서버면 지켜보기 전에도 응답(source.members 가 멤버 확인), 앱은 오류 · 다시 불러오기 표시 → 내 계정 → 관리자(GET /app/admins) → 이름순, 녹음할 서버를 바꾸면 봇을 다시 붙여 새 서버를 지켜봄 - 롤 채팅 OCR 제거: 앱 설정 · 마법사 · 진단 · lol.ts · 워커 ocr.py/ocr_* op · pywinrt/mss/Pillow · win-ci ocr_lang 롤은 게임 중 전체/팀 채팅 API 가 없어 LCU(챔피언 선택 · 게임 후) + r3dlog(남아 있을 때, LCU 채팅을 지우지 않고 추가) - 표시 이름: 서버 store.displayNames (세션 · 앱 유저 · 접속 기록 이름까지 바꿈), GET /app/names, PUT /app/admin/names, cli name. 앱은 받아서 users · 지난 범인 분석 이름을 바꾸고 이후 디스코드 이름 대신 저장. 관리자 탭에 편집 UI - 저장소 시연 · 테스트 데이터 · 화면 캡처 · 계획서 PDF 의 실제 이름을 가짜 이름으로 교체 - 테스트: 앱 41 · 서버 16 · 워커 39 통과 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -203,6 +203,21 @@ export class AppAuth extends EventEmitter {
|
||||
if (token) await this.call('POST', '/auth/app/logout', {}, token).catch(() => undefined);
|
||||
}
|
||||
|
||||
/** 관리자 · 최고 관리자 아이디 (따라갈 사람 목록 정렬용) */
|
||||
async adminIds(): Promise<string[]> {
|
||||
const r = await this.call<{ ids: string[] }>('GET', '/app/admins');
|
||||
return Array.isArray(r?.ids) ? r.ids : [];
|
||||
}
|
||||
|
||||
/** 표시 이름 (실명 숨기기): 디스코드 아이디 → 이름 */
|
||||
async displayNames(): Promise<Record<string, string>> {
|
||||
const r = await this.call<{ names: Record<string, string> }>('GET', '/app/names');
|
||||
return r?.names && typeof r.names === 'object' ? r.names : {};
|
||||
}
|
||||
adminSetDisplayName(id: string, name: string): Promise<{ names: Record<string, string> }> {
|
||||
return this.call('PUT', '/app/admin/names', { id: id.trim(), name: name.trim() });
|
||||
}
|
||||
|
||||
// ---- 관리자 화면 (서버가 역할을 다시 확인한다)
|
||||
adminUsers(): Promise<{ users: AppUserRow[] }> {
|
||||
return this.call('GET', '/app/admin/users');
|
||||
|
||||
@@ -125,9 +125,49 @@ export class Store {
|
||||
`INSERT INTO users(id,name,color,avatar,updated_at) VALUES(?,?,?,?,?)
|
||||
ON CONFLICT(id) DO UPDATE SET name=excluded.name, avatar=excluded.avatar, updated_at=excluded.updated_at`,
|
||||
)
|
||||
.run(u.id, u.name, colorFor(u.id), u.avatar, now);
|
||||
.run(u.id, this.displayNames()[u.id] ?? u.name, colorFor(u.id), u.avatar, now);
|
||||
return this.getUser(u.id)!;
|
||||
}
|
||||
|
||||
// 표시 이름 (실명 숨기기): 사이트 서버에 정해 둔 이름을 디스코드 이름 대신 저장한다
|
||||
private names: Record<string, string> | null = null;
|
||||
displayNames(): Record<string, string> {
|
||||
if (!this.names) {
|
||||
try {
|
||||
this.names = JSON.parse(this.meta('display_names') || '{}');
|
||||
} catch {
|
||||
this.names = {};
|
||||
}
|
||||
}
|
||||
return this.names!;
|
||||
}
|
||||
/** 새 표시 이름을 저장하고, 이미 저장된 유저 이름 · 지난 범인 분석에 남은 예전 이름도 바꾼다 */
|
||||
setDisplayNames(map: Record<string, string>): void {
|
||||
const names: Record<string, string> = {};
|
||||
for (const [id, name] of Object.entries(map)) if (typeof name === 'string' && name.trim()) names[id] = name.trim();
|
||||
this.names = names;
|
||||
this.setMeta('display_names', JSON.stringify(names));
|
||||
const culprit = !!this.db.prepare(`SELECT 1 FROM sqlite_master WHERE type='table' AND name='culprit_analyses'`).get();
|
||||
const j = (x: string) => JSON.stringify(x).slice(1, -1);
|
||||
this.db.transaction(() => {
|
||||
for (const [id, name] of Object.entries(names)) {
|
||||
const u = this.getUser(id);
|
||||
if (!u || u.name === name) continue;
|
||||
this.db.prepare('UPDATE users SET name=? WHERE id=?').run(name, id);
|
||||
if (culprit && u.name.length >= 2) this.db.prepare('UPDATE culprit_analyses SET result=replace(result,?,?)').run(j(u.name), j(name));
|
||||
}
|
||||
if (!culprit) return;
|
||||
for (const r of this.db.prepare('SELECT id, created_by FROM culprit_analyses').all() as { id: string; created_by: string }[]) {
|
||||
let by: any;
|
||||
try {
|
||||
by = JSON.parse(r.created_by);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
if (by?.id && names[by.id] && by.name !== names[by.id]) this.db.prepare('UPDATE culprit_analyses SET created_by=? WHERE id=?').run(JSON.stringify({ ...by, name: names[by.id] }), r.id);
|
||||
}
|
||||
})();
|
||||
}
|
||||
getUser(id: string): UserRow | undefined {
|
||||
return this.db.prepare('SELECT * FROM users WHERE id=?').get(id) as UserRow | undefined;
|
||||
}
|
||||
|
||||
@@ -128,24 +128,13 @@ export async function runDiagnostics(opts: {
|
||||
});
|
||||
}
|
||||
|
||||
// 5. 채팅 OCR (한국어 OCR 설치 여부 + 정확도)
|
||||
try {
|
||||
const r = await opts.worker.request('ocr_image', { path: path.join(opts.resourcesDir, 'diag', 'lol-chat-sample.png'), lang: 'ko' }, 60000);
|
||||
const lines: string[] = (r.lines || []).map((l: any) => l.text ?? l);
|
||||
const expect = ['드래곤 가자', 'gg', '바텀 갱 간다'];
|
||||
const hit = expect.filter((e) => lines.some((l) => l.replace(/\s/g, '').includes(e.replace(/\s/g, '')))).length;
|
||||
add({ id: 'ocr', label: '채팅 OCR (한국어)', ok: hit >= 2, detail: `예시 3줄 중 ${hit}줄 인식: ${lines.join(' / ')}`, data: r });
|
||||
} catch (e: any) {
|
||||
add({ id: 'ocr', label: '채팅 OCR (한국어)', ok: false, detail: e.message });
|
||||
}
|
||||
|
||||
// 6. r3dlog 채팅
|
||||
// 5. r3dlog 채팅 (롤은 게임 중 채팅 API 가 없어 로그 파일에 남을 때만 쓴다)
|
||||
const logs = opts.lolLogsDir || (lcu?.installDir ? path.join(lcu.installDir, 'Logs', 'GameLogs') : null);
|
||||
if (!logs || !fs.existsSync(logs)) add({ id: 'r3dlog', label: '롤 로그 파일 채팅', ok: null, detail: '로그 폴더를 찾지 못했습니다 (롤을 한 판 한 뒤 확인)' });
|
||||
else {
|
||||
try {
|
||||
const r = await opts.worker.request('r3dlog_check', { logs_dir: logs }, 30000);
|
||||
add({ id: 'r3dlog', label: '롤 로그 파일 채팅', ok: r.found_chat, detail: r.found_chat ? `채팅이 남아 있음 → OCR 대신 사용 (${r.file})` : '로그에 채팅이 없음 → 화면 OCR 사용', data: r });
|
||||
add({ id: 'r3dlog', label: '롤 로그 파일 채팅', ok: r.found_chat ? true : null, detail: r.found_chat ? `채팅이 남아 있음 → 게임 중 채팅을 경기 뒤에 붙임 (${r.file})` : '로그에 채팅이 없음 → 게임 중 전체 · 팀 채팅은 기록되지 않음 (챔피언 선택 · 게임 후 채팅은 LCU 로 기록)', data: r });
|
||||
} catch (e: any) {
|
||||
add({ id: 'r3dlog', label: '롤 로그 파일 채팅', ok: false, detail: e.message });
|
||||
}
|
||||
|
||||
@@ -47,7 +47,8 @@ const DRAGON_KO: Record<string, string> = {
|
||||
* 리그 오브 레전드 어댑터 (보고서 6-5).
|
||||
* - 게임 클라이언트 API(127.0.0.1:2999): 게임 시간, 10명 KDA·CS·아이템, 킬·오브젝트 이벤트
|
||||
* - 롤 클라이언트(LCU): 경기 ID·결과·경기 기록(타임라인), 챔피언 선택·게임 후 채팅
|
||||
* - 게임 중 채팅: 화면 OCR (STT 워커) 또는 로그 파일(남아 있을 때)
|
||||
* - 게임 중 전체 · 팀 채팅: 롤은 이걸 주는 API 가 없다 (LCU · 게임 클라이언트 API 모두). 화면 글자 인식(OCR)은 쓰지 않고,
|
||||
* 게임 로그 파일(r3dlog)에 채팅이 남아 있을 때만 경기 뒤에 읽는다
|
||||
*/
|
||||
export class LolAdapter implements GameAdapter {
|
||||
readonly game = 'lol' as const;
|
||||
@@ -61,15 +62,10 @@ export class LolAdapter implements GameAdapter {
|
||||
private pendingChat: EventRow[] = [];
|
||||
private detailQueue = new Map<string, { gameId: number; tries: number; endedAt: number; startedAt: number }>();
|
||||
private summonerNames = new Map<string, string>();
|
||||
private ocrSeen = new Set<string>();
|
||||
private lastMatchId: string | null = null;
|
||||
private lastErr = '';
|
||||
|
||||
constructor(private host: AdapterHost) {
|
||||
host.worker.on('event', (ev: any) => {
|
||||
if (ev.event === 'ocr_line') this.onOcrLine(ev);
|
||||
});
|
||||
}
|
||||
constructor(private host: AdapterHost) {}
|
||||
|
||||
start(): void {
|
||||
if (this.timer) return;
|
||||
@@ -80,7 +76,6 @@ export class LolAdapter implements GameAdapter {
|
||||
if (this.timer) clearInterval(this.timer);
|
||||
if (this.lcuTimer) clearInterval(this.lcuTimer);
|
||||
this.timer = this.lcuTimer = null;
|
||||
if (this.live) void this.host.worker.request('ocr_stop', {}, 5000).catch(() => undefined);
|
||||
}
|
||||
status() {
|
||||
return { connected: !!this.lcu || !!this.live, inMatch: !!this.live && !this.live.ended, detail: this.lastErr || undefined };
|
||||
@@ -148,7 +143,6 @@ export class LolAdapter implements GameAdapter {
|
||||
ended: false,
|
||||
};
|
||||
this.lastMatchId = id;
|
||||
this.ocrSeen.clear();
|
||||
this.host.matchStarted({
|
||||
id,
|
||||
game: 'lol',
|
||||
@@ -161,7 +155,6 @@ export class LolAdapter implements GameAdapter {
|
||||
// 버퍼해 둔 챔피언 선택 채팅을 이 경기에 붙인다
|
||||
for (const e of this.pendingChat) this.host.event({ ...e, match_id: id, id: `${id}:${e.id}` });
|
||||
this.pendingChat = [];
|
||||
void this.startOcr();
|
||||
log.info(`롤 경기 시작 감지 ${id}`);
|
||||
}
|
||||
const m = this.live;
|
||||
@@ -307,7 +300,6 @@ export class LolAdapter implements GameAdapter {
|
||||
if (!m || m.ended) return;
|
||||
m.ended = true;
|
||||
const now = Date.now();
|
||||
void this.host.worker.request('ocr_stop', {}, 5000).catch(() => undefined);
|
||||
this.host.matchEnded(m.id, now);
|
||||
this.host.matchUpdated(m.id, {
|
||||
result: JSON.stringify({ win, score: null }),
|
||||
@@ -323,19 +315,7 @@ export class LolAdapter implements GameAdapter {
|
||||
}, 60000).unref();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 채팅 OCR · 로그
|
||||
private async startOcr(): Promise<void> {
|
||||
const s = this.host.settings().games;
|
||||
if (!s.lolChatOcr || process.platform !== 'win32') return;
|
||||
try {
|
||||
await this.host.worker.request('ocr_start', { window_title: 'League of Legends (TM) Client', region: s.lolOcrRegion, fps: 3, lang: 'ko' }, 15000);
|
||||
log.info('롤 채팅 OCR 시작');
|
||||
} catch (e: any) {
|
||||
this.lastErr = `채팅 OCR: ${e.message}`;
|
||||
log.warn('채팅 OCR 시작 실패', e);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 게임 중 채팅 (로그 파일)
|
||||
private chatRow(m: LiveMatch, key: string, gameTimeS: number | null, ts: number, p: any, source: ChatData['source']): EventRow {
|
||||
const sender = this.findPlayer(m, p.sender);
|
||||
const ts2 = gameTimeS !== null ? m.startedAt + gameTimeS * 1000 : ts;
|
||||
@@ -363,18 +343,7 @@ export class LolAdapter implements GameAdapter {
|
||||
};
|
||||
}
|
||||
|
||||
private onOcrLine(ev: any): void {
|
||||
const m = this.live;
|
||||
if (!m || m.ended || !ev.parsed?.message) return;
|
||||
const p = ev.parsed;
|
||||
const key = `${p.game_time ?? ''}|${p.sender ?? ''}|${p.message}`;
|
||||
if (this.ocrSeen.has(key)) return;
|
||||
this.ocrSeen.add(key);
|
||||
const gts = typeof p.game_time_s === 'number' ? p.game_time_s : null;
|
||||
this.host.event(this.chatRow(m, hash(key), gts, ev.ts || Date.now(), p, 'ocr'));
|
||||
}
|
||||
|
||||
/** 로그 파일에 채팅이 남아 있으면 OCR 보다 정확하므로 그걸로 바꾼다 */
|
||||
/** 경기가 끝나면 로그 파일에 남은 게임 중 채팅을 붙인다 (LCU 로 받은 챔피언 선택 · 게임 후 채팅은 그대로 둔다) */
|
||||
private async readLogChat(m: LiveMatch): Promise<void> {
|
||||
const dir = this.host.settings().games.lolLogsDir || (this.lcu?.installDir ? `${this.lcu.installDir}\\Logs\\GameLogs` : null);
|
||||
if (!dir) return;
|
||||
@@ -385,8 +354,8 @@ export class LolAdapter implements GameAdapter {
|
||||
const rows = lines.map((p: any, i: number) =>
|
||||
this.chatRow(m, `${i}-${hash(`${p.game_time_s}|${p.sender}|${p.message}`)}`, typeof p.game_time_s === 'number' ? p.game_time_s : null, m.startedAt, p, 'log'),
|
||||
);
|
||||
this.host.replaceEvents(m.id, ['chat'], rows);
|
||||
log.info(`로그 파일 채팅 ${rows.length}줄로 교체`);
|
||||
for (const row of rows) this.host.event(row);
|
||||
log.info(`로그 파일 채팅 ${rows.length}줄`);
|
||||
} catch (e) {
|
||||
log.debug('로그 파일 채팅 없음', e);
|
||||
}
|
||||
|
||||
@@ -145,8 +145,20 @@ export async function startCore(opts: CoreOptions) {
|
||||
};
|
||||
await startBot();
|
||||
|
||||
// 녹음할 서버를 바꾸면 봇을 다시 붙여 새 서버를 지켜본다 (이전 서버의 녹음은 끝난다)
|
||||
let watchedGuild = S().discord.guildId;
|
||||
const offGuild = settings.onChange((s) => {
|
||||
const g = s.discord.guildId;
|
||||
if (g === watchedGuild) return;
|
||||
watchedGuild = g;
|
||||
if (bot.state.status !== 'ready' || !g || bot.state.guild?.id === g) return;
|
||||
log.info('녹음할 서버가 바뀌어 봇을 다시 연결합니다');
|
||||
void bot.stop().then(startBot);
|
||||
});
|
||||
|
||||
const stop = async () => {
|
||||
log.info('종료 중');
|
||||
offGuild();
|
||||
relay.stop();
|
||||
retention.stop();
|
||||
games.stop();
|
||||
|
||||
@@ -21,8 +21,6 @@ export interface Settings {
|
||||
games: {
|
||||
valorant: boolean;
|
||||
lol: boolean;
|
||||
lolChatOcr: boolean;
|
||||
lolOcrRegion: { x: number; y: number; w: number; h: number };
|
||||
lolLogsDir: string | null;
|
||||
};
|
||||
stt: {
|
||||
@@ -100,8 +98,6 @@ export function defaultSettings(): Settings {
|
||||
games: {
|
||||
valorant: true,
|
||||
lol: true,
|
||||
lolChatOcr: true,
|
||||
lolOcrRegion: { x: 0.0, y: 0.6, w: 0.3, h: 0.27 },
|
||||
lolLogsDir: null,
|
||||
},
|
||||
stt: {
|
||||
|
||||
Reference in New Issue
Block a user