Files
bird/src/commands/check.ts
T
yuta 3f370cc4b6
CI / test (push) Successful in 10m2s
feat: support relay profile selection
2026-06-24 18:30:24 +09:00

38 lines
1.4 KiB
TypeScript

import type { Command } from 'commander';
import type { CliContext } from '../cli/shared.js';
import { TwitterClient } from '../lib/twitter-client.js';
export function registerCheckCommand(program: Command, ctx: CliContext): void {
program
.command('check')
.description('Check twitter safe relay availability')
.action(async () => {
const opts = program.opts();
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
const relayBaseUrl = ctx.resolveRelayBaseUrlFromOptions(opts);
const profileName = ctx.resolveProfileNameFromOptions(opts);
console.log(`${ctx.p('info')}Relay check`);
console.log('-'.repeat(40));
if (!relayBaseUrl) {
console.log(`${ctx.p('err')}TWITTER_RELAY_BASE_URL: not set`);
process.exit(1);
}
console.log(`${ctx.p('ok')}relay: ${relayBaseUrl}`);
const client = new TwitterClient({ relayBaseUrl, profileName, timeoutMs });
const result = await client.getCurrentUser();
if (result.success && result.user) {
console.log(`${ctx.l('user')}@${result.user.username} (${result.user.name})`);
console.log(`${ctx.l('userId')}${result.user.id}`);
console.log(`\n${ctx.p('ok')}Ready to use twitter safe relay.`);
} else {
console.log(`${ctx.p('err')}Relay check failed: ${result.error ?? 'Unknown error'}`);
process.exit(1);
}
});
}