DUNGEONS-30: add access gateway with Telegram and Discord approvals
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
16
scripts/check.js
Normal file
16
scripts/check.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { readdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
function check(directory) {
|
||||
for (const file of readdirSync(directory, { withFileTypes: true })) {
|
||||
const path = join(directory, file.name);
|
||||
if (file.isDirectory()) check(path);
|
||||
else if (file.name.endsWith('.js')) {
|
||||
const result = spawnSync(process.execPath, ['--check', path], { stdio: 'inherit' });
|
||||
if (result.status !== 0) process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const directory of ['src', 'public', 'scripts', 'test']) check(directory);
|
||||
console.log('JavaScript syntax checks passed.');
|
||||
16
scripts/register-discord.js
Normal file
16
scripts/register-discord.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'dotenv/config';
|
||||
import { loadConfig } from '../src/config.js';
|
||||
import { DiscordBot } from '../src/bots/discord.js';
|
||||
|
||||
try {
|
||||
const config = loadConfig();
|
||||
if (!config.discord.token) throw new Error('Configure Discord in .env first.');
|
||||
const bot = new DiscordBot(config);
|
||||
const scope = config.discord.guildId ? `/guilds/${config.discord.guildId}` : '';
|
||||
// POST upserts only /access, preserving unrelated commands registered by the owner.
|
||||
await bot.api(`/applications/${config.discord.applicationId}${scope}/commands`, {
|
||||
name: 'access', description: 'Request private-alpha access to Dungeons & Ground', type: 1,
|
||||
...(scope ? {} : { integration_types: [0], contexts: [0, 1] }),
|
||||
});
|
||||
console.log(`/access registered ${scope ? 'in the configured server' : 'globally (propagation can take time)'}.`);
|
||||
} catch (error) { console.error(error.message); process.exitCode = 1; }
|
||||
22
scripts/revoke-sessions.js
Normal file
22
scripts/revoke-sessions.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'dotenv/config';
|
||||
import { loadConfig } from '../src/config.js';
|
||||
import { AccessStore } from '../src/store.js';
|
||||
|
||||
const [platform, userId] = process.argv.slice(2);
|
||||
if (!['telegram', 'discord'].includes(platform) || !/^\d+$/.test(userId || '')) {
|
||||
console.error('Stop the gateway first, then run: npm run sessions:revoke -- telegram|discord USER_ID');
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
let store;
|
||||
try {
|
||||
store = new AccessStore(loadConfig());
|
||||
store.change(state => {
|
||||
state.sessions = state.sessions.filter(s => s.platform !== platform || s.userId !== userId);
|
||||
for (const request of state.requests) {
|
||||
if (request.platform === platform && request.user_id === userId) { request.status = 'revoked'; delete request.codeHash; }
|
||||
}
|
||||
});
|
||||
console.log('Access numbers, pending requests and sessions revoked for the specified user. Restart the gateway.');
|
||||
} catch (error) { console.error(error.message); process.exitCode = 1; }
|
||||
finally { store?.close(); }
|
||||
}
|
||||
Reference in New Issue
Block a user