Pick recording servers from the voice-changer app; fix per-server recording status
consent-recorder: operators (ADMIN_DISCORD_IDS) create an app key on the site; the app calls GET/POST /api/guilds with it to turn servers on/off. Turned-off servers are left immediately. recordingNow() now checks the user picked that server, so someone who only chose server A is not shown as recorded while sitting in a B channel the bot records for others. voice-changer: new "녹음 서버" dialog (record_servers.py), network in a worker thread, key saved in config/record-servers.json; upgrade cleanup list knows the new file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -55,3 +55,39 @@ test('녹음할 서버로 고르지 않은 서버에서는 동의자라도 따
|
||||
await bot.client.destroy();
|
||||
store.close();
|
||||
});
|
||||
|
||||
test('녹음 중 표시는 그 서버를 고른 사람에게만 (다른 동의자를 녹음 중인 채널에 같이 있어도)', async () => {
|
||||
const store = new Store(':memory:');
|
||||
store.consent({ id: 'u1', username: 'a' });
|
||||
store.consent({ id: 'u3', username: 'c' });
|
||||
store.setConsentGuilds('u1', ['g']);
|
||||
store.setConsentGuilds('u3', ['other']);
|
||||
const cfg = loadConfig({ PUBLIC_URL: 'http://localhost', DISCORD_CLIENT_ID: 'c', DISCORD_CLIENT_SECRET: 's' }, false);
|
||||
const bot = new FollowBot(cfg, store);
|
||||
const guild = fakeGuild();
|
||||
guild.voiceStates.cache.set('u3', { id: 'u3', channelId: 'A', member: { user: { bot: false } } });
|
||||
guild.channels = { cache: new Map([['A', { name: 'A채널' }]]) };
|
||||
(bot.client.guilds.cache as any).set('g', guild);
|
||||
(bot as any).recorders.set('g', { channelId: 'A' });
|
||||
assert.equal(bot.recordingNow('u1'), 'A채널');
|
||||
assert.equal(bot.recordingNow('u3'), null);
|
||||
(bot as any).recorders.clear();
|
||||
(bot.client.guilds.cache as any).clear();
|
||||
await bot.client.destroy();
|
||||
store.close();
|
||||
});
|
||||
|
||||
test('운영자가 앱에서 끈 서버는 따라가지 않는다', async () => {
|
||||
const store = new Store(':memory:');
|
||||
const cfg = loadConfig({ PUBLIC_URL: 'http://localhost', DISCORD_CLIENT_ID: 'c', DISCORD_CLIENT_SECRET: 's' }, false);
|
||||
const bot = new FollowBot(cfg, store);
|
||||
const guild = { ...fakeGuild(), name: '서버' };
|
||||
(bot.client.guilds.cache as any).set('g', guild);
|
||||
assert.equal((bot as any).allowedGuild(guild), true); // 처음에는 켜짐
|
||||
store.setGuildEnabled('admin', { g: false });
|
||||
assert.equal((bot as any).allowedGuild(guild), false);
|
||||
assert.deepEqual(bot.adminGuilds(), [{ id: 'g', name: '서버', enabled: false }]);
|
||||
(bot.client.guilds.cache as any).clear();
|
||||
await bot.client.destroy();
|
||||
store.close();
|
||||
});
|
||||
|
||||
@@ -18,6 +18,8 @@ let base = '';
|
||||
let tmp = '';
|
||||
const changed: string[] = [];
|
||||
const events: string[] = [];
|
||||
const guildOn: Record<string, boolean> = {};
|
||||
let settingsChanged = 0;
|
||||
|
||||
before(async () => {
|
||||
tmp = fs.mkdtempSync(path.join(os.homedir(), '.tmp-consent-'));
|
||||
@@ -46,7 +48,7 @@ before(async () => {
|
||||
site.close();
|
||||
base = `http://127.0.0.1:${port}`;
|
||||
const cfg = loadConfig(
|
||||
{ PUBLIC_URL: base, DISCORD_CLIENT_ID: 'cid', DISCORD_CLIENT_SECRET: 'sec', DATA_DIR: tmp, OPERATOR_NAME: '승한', DISCORD_API: `http://127.0.0.1:${dport}` },
|
||||
{ PUBLIC_URL: base, DISCORD_CLIENT_ID: 'cid', DISCORD_CLIENT_SECRET: 'sec', DATA_DIR: tmp, OPERATOR_NAME: '승한', ADMIN_DISCORD_IDS: USER.id, DISCORD_API: `http://127.0.0.1:${dport}` },
|
||||
false,
|
||||
);
|
||||
site = createSite(cfg, store, {
|
||||
@@ -57,6 +59,8 @@ before(async () => {
|
||||
{ id: 'g1', name: '첫째 서버' },
|
||||
{ id: 'g2', name: '둘째 서버' },
|
||||
],
|
||||
adminGuilds: () => ['g1', 'g2'].map((id) => ({ id, name: id, enabled: store.guildEnabled(id) })),
|
||||
guildSettingsChanged: () => settingsChanged++,
|
||||
});
|
||||
await new Promise<void>((r) => site.listen(port, '127.0.0.1', r));
|
||||
});
|
||||
@@ -171,6 +175,41 @@ test('디스코드 로그인 → 모든 항목 체크해야 동의 → 철회하
|
||||
assert.doesNotMatch(await (await get('/', cookie)).text(), /하늘님/);
|
||||
});
|
||||
|
||||
test('운영자는 앱 연결 키를 만들어 앱에서 녹음할 서버를 켜고 끈다', async () => {
|
||||
const { cookie, csrf } = await login();
|
||||
assert.match(await (await get('/', cookie)).text(), /음성 변환기 앱 연결/);
|
||||
assert.equal((await post('/app-key', cookie, {})).status, 403); // CSRF
|
||||
const page = await (await post('/app-key', cookie, { csrf })).text();
|
||||
const key = /<code class="key">([^<]+)<\/code>/.exec(page)![1];
|
||||
const api = (method: string, k: string, body?: unknown) =>
|
||||
fetch(base + '/api/guilds', { method, headers: { authorization: `Bearer ${k}`, 'content-type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||
|
||||
assert.equal((await fetch(base + '/api/guilds')).status, 401);
|
||||
assert.equal((await api('GET', 'vc_wrong')).status, 401);
|
||||
const list = await (await api('GET', key)).json();
|
||||
assert.deepEqual(list.guilds.map((g: any) => [g.id, g.enabled]), [['g1', true], ['g2', true]]);
|
||||
|
||||
const r = await api('POST', key, { enabled: ['g1'] });
|
||||
assert.equal(r.status, 200);
|
||||
assert.deepEqual((await r.json()).guilds.map((g: any) => [g.id, g.enabled]), [['g1', true], ['g2', false]]);
|
||||
assert.equal(store.guildEnabled('g2'), false);
|
||||
assert.equal(settingsChanged, 1);
|
||||
assert.equal((await api('POST', key, { enabled: ['nope'] })).status, 400);
|
||||
assert.equal((await api('POST', key, { enabled: 'g1' })).status, 400);
|
||||
assert.equal(store.guildEnabled('g2'), false);
|
||||
|
||||
// 새 키를 만들면 예전 키는 못 쓴다
|
||||
const page2 = await (await post('/app-key', cookie, { csrf })).text();
|
||||
const key2 = /<code class="key">([^<]+)<\/code>/.exec(page2)![1];
|
||||
assert.equal((await api('GET', key)).status, 401);
|
||||
assert.equal((await api('POST', key2, { enabled: ['g1', 'g2'] })).status, 200);
|
||||
assert.equal(store.guildEnabled('g2'), true);
|
||||
|
||||
// 운영자가 아닌 사람의 키는 거절 (운영자 목록에서 빠진 경우 포함)
|
||||
assert.equal((await api('GET', store.newAppKey('999999'))).status, 401);
|
||||
assert.equal((await post('/logout', cookie, { csrf })).status, 303);
|
||||
});
|
||||
|
||||
test('클릭재킹 막기 헤더', async () => {
|
||||
const r = await get('/');
|
||||
assert.equal(r.headers.get('x-frame-options'), 'DENY');
|
||||
|
||||
Reference in New Issue
Block a user