Files
jackwener__opencli/clis/lesswrong/user.ts
Xule Lin d2051cdab7 feat(lesswrong): add LessWrong adapter (#773)
* feat(lesswrong): add LessWrong adapter

15 commands for the LessWrong rationality and AI alignment community:
- Post listings: curated, frontpage, new, top, top-week/month/year
- Content: read (full post), comments, shortform (quick takes)
- Discovery: tag, tags, sequences
- Users: user (profile), user-posts

All commands use the public GraphQL API (no browser required).
Time-filtered views use the `after` date parameter.
Tag lookup resolves slugs to IDs via the `tagBySlug` view.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: move lesswrong adapter to clis/ (post PR #782 restructure)

New adapter files were created at src/clis/lesswrong/ but PR #782 moved
all adapters to root clis/. Move to correct location.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: jackwener <jakevingoo@gmail.com>
2026-04-05 03:21:48 +08:00

51 lines
1.6 KiB
TypeScript

import { cli, Strategy } from '../../registry.js';
import { EmptyResultError } from '../../errors.js';
import { DOMAIN, SITE, gqlEscape, gqlRequest, stripHtml } from './_helpers.js';
cli({
site: SITE,
name: 'user',
description: 'User profile',
domain: DOMAIN,
strategy: Strategy.PUBLIC,
browser: false,
args: [
{
name: 'username',
type: 'string',
required: true,
positional: true,
help: 'LessWrong username or slug',
},
],
columns: ['field', 'value'],
func: async (_page, kwargs) => {
const slug = gqlEscape(String(kwargs.username).toLowerCase());
const query = `query UserProfile {
user(input: {selector: {slug: "${slug}"}}) {
result { _id displayName slug bio karma postCount commentCount createdAt }
}
}`;
const data = await gqlRequest(query);
const user = data?.user?.result;
if (!user?._id) {
throw new EmptyResultError(
`lesswrong user ${String(kwargs.username)}`,
'Check the username — LessWrong slugs are lowercase (e.g. "zvi", "eliezer-yudkowsky")',
);
}
return [
{ field: 'Name', value: user.displayName ?? '' },
{ field: 'Username', value: user.slug ?? '' },
{ field: 'Karma', value: user.karma ?? 0 },
{ field: 'Posts', value: user.postCount ?? 0 },
{ field: 'Comments', value: user.commentCount ?? 0 },
{ field: 'Joined', value: user.createdAt ?? '' },
{ field: 'Bio', value: stripHtml(user.bio ?? '') },
{ field: 'URL', value: `https://${DOMAIN}/users/${user.slug}` },
];
},
});