9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
/**
|
|
* Chess.com player stats across game kinds (rapid / blitz / bullet /
|
|
* daily / chess960 / etc) via the public stats endpoint.
|
|
*/
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { EmptyResultError } from '@jackwener/opencli/errors';
|
|
import { chessApi, validateUsername, summarizeStats } from './utils.js';
|
|
|
|
const KINDS = ['chess_rapid', 'chess_blitz', 'chess_bullet', 'chess_daily', 'chess960_daily', 'chess_daily_960'];
|
|
|
|
cli({
|
|
site: 'chess',
|
|
name: 'stats',
|
|
access: 'read',
|
|
description: 'Chess.com player ratings + win/loss record across game kinds',
|
|
domain: 'api.chess.com',
|
|
strategy: Strategy.PUBLIC,
|
|
browser: false,
|
|
args: [
|
|
{ name: 'username', type: 'string', required: true, positional: true, help: 'Chess.com username (case-insensitive)' },
|
|
],
|
|
columns: ['kind', 'rating_current', 'rating_best', 'wins', 'losses', 'draws'],
|
|
func: async (kwargs) => {
|
|
const username = validateUsername(kwargs.username);
|
|
const stats = await chessApi(`/player/${encodeURIComponent(username)}/stats`);
|
|
const rows = KINDS.map((k) => summarizeStats(stats, k)).filter(Boolean);
|
|
if (rows.length === 0) {
|
|
throw new EmptyResultError(`Chess.com returned no stats for ${username}`);
|
|
}
|
|
return rows;
|
|
},
|
|
});
|