dp-worker 0.1.24 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bird/sidecar-entry.js +16 -2
- package/dist/bird/sidecar-entry.js.map +1 -1
- package/dist/chrome-extension/omni-flow/manifest.json +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.d.ts +94 -0
- package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.js +108 -0
- package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/task-history-contracts.d.ts +2 -2
- package/package.json +4 -2
- package/vendor/bird/LICENSE +21 -0
- package/vendor/bird/README.md +116 -0
- package/vendor/bird/dist/cli/pagination.d.ts +35 -0
- package/vendor/bird/dist/cli/pagination.js +43 -0
- package/vendor/bird/dist/cli/program.d.ts +5 -0
- package/vendor/bird/dist/cli/program.js +113 -0
- package/vendor/bird/dist/cli/shared.d.ts +77 -0
- package/vendor/bird/dist/cli/shared.js +327 -0
- package/vendor/bird/dist/cli.d.ts +12 -0
- package/vendor/bird/dist/cli.js +29 -0
- package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
- package/vendor/bird/dist/commands/bookmarks.js +189 -0
- package/vendor/bird/dist/commands/check.d.ts +4 -0
- package/vendor/bird/dist/commands/check.js +43 -0
- package/vendor/bird/dist/commands/follow.d.ts +4 -0
- package/vendor/bird/dist/commands/follow.js +91 -0
- package/vendor/bird/dist/commands/help.d.ts +4 -0
- package/vendor/bird/dist/commands/help.js +19 -0
- package/vendor/bird/dist/commands/home.d.ts +4 -0
- package/vendor/bird/dist/commands/home.js +43 -0
- package/vendor/bird/dist/commands/lists.d.ts +4 -0
- package/vendor/bird/dist/commands/lists.js +125 -0
- package/vendor/bird/dist/commands/news.d.ts +4 -0
- package/vendor/bird/dist/commands/news.js +131 -0
- package/vendor/bird/dist/commands/post.d.ts +4 -0
- package/vendor/bird/dist/commands/post.js +101 -0
- package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
- package/vendor/bird/dist/commands/query-ids.js +80 -0
- package/vendor/bird/dist/commands/read.d.ts +4 -0
- package/vendor/bird/dist/commands/read.js +152 -0
- package/vendor/bird/dist/commands/search.d.ts +4 -0
- package/vendor/bird/dist/commands/search.js +115 -0
- package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
- package/vendor/bird/dist/commands/unbookmark.js +36 -0
- package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
- package/vendor/bird/dist/commands/user-tweets.js +109 -0
- package/vendor/bird/dist/commands/users.d.ts +4 -0
- package/vendor/bird/dist/commands/users.js +295 -0
- package/vendor/bird/dist/index.d.ts +2 -0
- package/vendor/bird/dist/index.js +2 -0
- package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
- package/vendor/bird/dist/lib/cli-args.js +25 -0
- package/vendor/bird/dist/lib/cookies.d.ts +31 -0
- package/vendor/bird/dist/lib/cookies.js +81 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
- package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-list-id.js +19 -0
- package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
- package/vendor/bird/dist/lib/features.json +17 -0
- package/vendor/bird/dist/lib/index.d.ts +10 -0
- package/vendor/bird/dist/lib/index.js +4 -0
- package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
- package/vendor/bird/dist/lib/normalize-handle.js +31 -0
- package/vendor/bird/dist/lib/output.d.ts +29 -0
- package/vendor/bird/dist/lib/output.js +88 -0
- package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
- package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
- package/vendor/bird/dist/lib/query-ids.json +20 -0
- package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
- package/vendor/bird/dist/lib/runtime-features.js +151 -0
- package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
- package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
- package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
- package/vendor/bird/dist/lib/thread-filters.js +124 -0
- package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
- package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
- package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
- package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
- package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
- package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
- package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
- package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
- package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
- package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
- package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
- package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
- package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
- package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
- package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
- package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
- package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
- package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
- package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
- package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
- package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
- package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
- package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client.js +21 -0
- package/vendor/bird/dist/lib/version.d.ts +6 -0
- package/vendor/bird/dist/lib/version.js +174 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { normalizeHandle } from '../lib/normalize-handle.js';
|
|
2
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
3
|
+
const ONLY_DIGITS_REGEX = /^\d+$/;
|
|
4
|
+
async function resolveUserId(client, usernameOrId, ctx) {
|
|
5
|
+
const raw = usernameOrId.trim();
|
|
6
|
+
const isNumeric = ONLY_DIGITS_REGEX.test(raw);
|
|
7
|
+
// Otherwise, treat as username and look up
|
|
8
|
+
const handle = normalizeHandle(raw);
|
|
9
|
+
if (handle) {
|
|
10
|
+
const lookup = await client.getUserIdByUsername(handle);
|
|
11
|
+
if (lookup.success && lookup.userId) {
|
|
12
|
+
return { userId: lookup.userId, username: lookup.username };
|
|
13
|
+
}
|
|
14
|
+
if (!isNumeric) {
|
|
15
|
+
console.error(`${ctx.p('err')}Failed to find user @${handle}: ${lookup.error ?? 'Unknown error'}`);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (isNumeric) {
|
|
20
|
+
return { userId: raw };
|
|
21
|
+
}
|
|
22
|
+
console.error(`${ctx.p('err')}Invalid username: ${usernameOrId}`);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
export function registerFollowCommands(program, ctx) {
|
|
26
|
+
program
|
|
27
|
+
.command('follow')
|
|
28
|
+
.description('Follow a user')
|
|
29
|
+
.argument('<username-or-id>', 'Username (with or without @) or user ID to follow')
|
|
30
|
+
.action(async (usernameOrId) => {
|
|
31
|
+
const opts = program.opts();
|
|
32
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
33
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
34
|
+
for (const warning of warnings) {
|
|
35
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
36
|
+
}
|
|
37
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
38
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
42
|
+
const resolved = await resolveUserId(client, usernameOrId, ctx);
|
|
43
|
+
if (!resolved) {
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const { userId, username } = resolved;
|
|
47
|
+
const displayName = username ? `@${username}` : userId;
|
|
48
|
+
const result = await client.follow(userId);
|
|
49
|
+
if (result.success) {
|
|
50
|
+
const finalName = result.username ? `@${result.username}` : displayName;
|
|
51
|
+
console.log(`${ctx.p('ok')}Now following ${finalName}`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.error(`${ctx.p('err')}Failed to follow ${displayName}: ${result.error}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
program
|
|
59
|
+
.command('unfollow')
|
|
60
|
+
.description('Unfollow a user')
|
|
61
|
+
.argument('<username-or-id>', 'Username (with or without @) or user ID to unfollow')
|
|
62
|
+
.action(async (usernameOrId) => {
|
|
63
|
+
const opts = program.opts();
|
|
64
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
65
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
66
|
+
for (const warning of warnings) {
|
|
67
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
68
|
+
}
|
|
69
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
70
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
74
|
+
const resolved = await resolveUserId(client, usernameOrId, ctx);
|
|
75
|
+
if (!resolved) {
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const { userId, username } = resolved;
|
|
79
|
+
const displayName = username ? `@${username}` : userId;
|
|
80
|
+
const result = await client.unfollow(userId);
|
|
81
|
+
if (result.success) {
|
|
82
|
+
const finalName = result.username ? `@${result.username}` : displayName;
|
|
83
|
+
console.log(`${ctx.p('ok')}Unfollowed ${finalName}`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.error(`${ctx.p('err')}Failed to unfollow ${displayName}: ${result.error}`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=follow.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function registerHelpCommand(program, ctx) {
|
|
2
|
+
program
|
|
3
|
+
.command('help [command]')
|
|
4
|
+
.description('Show help for a command')
|
|
5
|
+
.action((commandName) => {
|
|
6
|
+
if (!commandName) {
|
|
7
|
+
program.outputHelp();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const cmd = program.commands.find((c) => c.name() === commandName);
|
|
11
|
+
if (!cmd) {
|
|
12
|
+
console.error(`${ctx.p('err')}Unknown command: ${commandName}`);
|
|
13
|
+
process.exitCode = 2;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
cmd.outputHelp();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
2
|
+
export function registerHomeCommand(program, ctx) {
|
|
3
|
+
program
|
|
4
|
+
.command('home')
|
|
5
|
+
.description('Get your home timeline ("For You" feed)')
|
|
6
|
+
.option('-n, --count <number>', 'Number of tweets to fetch', '20')
|
|
7
|
+
.option('--following', 'Get "Following" feed (chronological) instead of "For You"')
|
|
8
|
+
.option('--json', 'Output as JSON')
|
|
9
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
10
|
+
.action(async (cmdOpts) => {
|
|
11
|
+
const opts = program.opts();
|
|
12
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
13
|
+
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
|
14
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
15
|
+
for (const warning of warnings) {
|
|
16
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
17
|
+
}
|
|
18
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
19
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
if (!Number.isFinite(count) || count <= 0) {
|
|
23
|
+
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
27
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
28
|
+
const result = cmdOpts.following
|
|
29
|
+
? await client.getHomeLatestTimeline(count, { includeRaw })
|
|
30
|
+
: await client.getHomeTimeline(count, { includeRaw });
|
|
31
|
+
if (result.success) {
|
|
32
|
+
const feedType = cmdOpts.following ? 'Following' : 'For You';
|
|
33
|
+
const emptyMessage = `No tweets found in ${feedType} timeline.`;
|
|
34
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
35
|
+
ctx.printTweets(result.tweets, { json: isJson, emptyMessage });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.error(`${ctx.p('err')}Failed to fetch home timeline: ${result.error}`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=home.js.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// ABOUTME: CLI command for fetching Twitter Lists.
|
|
2
|
+
// ABOUTME: Supports listing owned lists, memberships, and list timelines.
|
|
3
|
+
import { parsePaginationFlags } from '../cli/pagination.js';
|
|
4
|
+
import { extractListId } from '../lib/extract-list-id.js';
|
|
5
|
+
import { hyperlink } from '../lib/output.js';
|
|
6
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
7
|
+
function printLists(lists, ctx) {
|
|
8
|
+
if (lists.length === 0) {
|
|
9
|
+
console.log('No lists found.');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for (const list of lists) {
|
|
13
|
+
const visibility = list.isPrivate ? '[private]' : '[public]';
|
|
14
|
+
console.log(`${list.name} ${ctx.colors.muted(visibility)}`);
|
|
15
|
+
if (list.description) {
|
|
16
|
+
console.log(` ${list.description.slice(0, 100)}${list.description.length > 100 ? '...' : ''}`);
|
|
17
|
+
}
|
|
18
|
+
console.log(` ${ctx.p('info')}${list.memberCount?.toLocaleString() ?? 0} members`);
|
|
19
|
+
if (list.owner) {
|
|
20
|
+
console.log(` ${ctx.colors.muted(`Owner: @${list.owner.username}`)}`);
|
|
21
|
+
}
|
|
22
|
+
const listUrl = `https://x.com/i/lists/${list.id}`;
|
|
23
|
+
console.log(` ${ctx.colors.accent(hyperlink(listUrl, listUrl, ctx.getOutput()))}`);
|
|
24
|
+
console.log('──────────────────────────────────────────────────');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function registerListsCommand(program, ctx) {
|
|
28
|
+
program
|
|
29
|
+
.command('lists')
|
|
30
|
+
.description('Get your Twitter lists')
|
|
31
|
+
.option('--member-of', 'Show lists you are a member of (instead of owned lists)')
|
|
32
|
+
.option('-n, --count <number>', 'Number of lists to fetch', '100')
|
|
33
|
+
.option('--json', 'Output as JSON')
|
|
34
|
+
.action(async (cmdOpts) => {
|
|
35
|
+
const opts = program.opts();
|
|
36
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
37
|
+
const count = Number.parseInt(cmdOpts.count || '100', 10);
|
|
38
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
39
|
+
for (const warning of warnings) {
|
|
40
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
41
|
+
}
|
|
42
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
43
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
47
|
+
const result = cmdOpts.memberOf ? await client.getListMemberships(count) : await client.getOwnedLists(count);
|
|
48
|
+
if (result.success && result.lists) {
|
|
49
|
+
if (cmdOpts.json) {
|
|
50
|
+
console.log(JSON.stringify(result.lists, null, 2));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const emptyMessage = cmdOpts.memberOf ? 'You are not a member of any lists.' : 'You do not own any lists.';
|
|
54
|
+
if (result.lists.length === 0) {
|
|
55
|
+
console.log(emptyMessage);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
printLists(result.lists, ctx);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error(`${ctx.p('err')}Failed to fetch lists: ${result.error}`);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
program
|
|
68
|
+
.command('list-timeline <list-id-or-url>')
|
|
69
|
+
.description('Get tweets from a list timeline')
|
|
70
|
+
.option('-n, --count <number>', 'Number of tweets to fetch', '20')
|
|
71
|
+
.option('--all', 'Fetch all tweets from list (paged). WARNING: your account might get banned using this flag')
|
|
72
|
+
.option('--max-pages <number>', 'Fetch N pages (implies --all)')
|
|
73
|
+
.option('--cursor <string>', 'Resume pagination from a cursor')
|
|
74
|
+
.option('--json', 'Output as JSON')
|
|
75
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
76
|
+
.action(async (listIdOrUrl, cmdOpts) => {
|
|
77
|
+
const opts = program.opts();
|
|
78
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
79
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
80
|
+
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
|
81
|
+
const pagination = parsePaginationFlags(cmdOpts, { maxPagesImpliesPagination: true });
|
|
82
|
+
if (!pagination.ok) {
|
|
83
|
+
console.error(`${ctx.p('err')}${pagination.error}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
const listId = extractListId(listIdOrUrl);
|
|
87
|
+
if (!listId) {
|
|
88
|
+
console.error(`${ctx.p('err')}Invalid list ID or URL. Expected numeric ID or https://x.com/i/lists/<id>.`);
|
|
89
|
+
process.exit(2);
|
|
90
|
+
}
|
|
91
|
+
const usePagination = pagination.usePagination;
|
|
92
|
+
if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
|
|
93
|
+
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
97
|
+
for (const warning of warnings) {
|
|
98
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
99
|
+
}
|
|
100
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
101
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
105
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
106
|
+
const timelineOptions = { includeRaw };
|
|
107
|
+
const paginationOptions = { includeRaw, maxPages: pagination.maxPages, cursor: pagination.cursor };
|
|
108
|
+
const result = usePagination
|
|
109
|
+
? await client.getAllListTimeline(listId, paginationOptions)
|
|
110
|
+
: await client.getListTimeline(listId, count, timelineOptions);
|
|
111
|
+
if (result.success) {
|
|
112
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
113
|
+
ctx.printTweetsResult(result, {
|
|
114
|
+
json: isJson,
|
|
115
|
+
usePagination,
|
|
116
|
+
emptyMessage: 'No tweets found in this list.',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.error(`${ctx.p('err')}Failed to fetch list timeline: ${result.error}`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=lists.js.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
2
|
+
function formatPostCount(count) {
|
|
3
|
+
if (count >= 1_000_000) {
|
|
4
|
+
return `${(count / 1_000_000).toFixed(1)}M`;
|
|
5
|
+
}
|
|
6
|
+
if (count >= 1_000) {
|
|
7
|
+
return `${(count / 1_000).toFixed(1)}K`;
|
|
8
|
+
}
|
|
9
|
+
return String(count);
|
|
10
|
+
}
|
|
11
|
+
function printNewsItems(items, ctx, opts = {}) {
|
|
12
|
+
if (opts.json) {
|
|
13
|
+
console.log(JSON.stringify(items, null, 2));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (items.length === 0) {
|
|
17
|
+
console.log(opts.emptyMessage ?? 'No news items found.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
for (const item of items) {
|
|
21
|
+
const categoryLabel = item.category ? `[${item.category}]` : '';
|
|
22
|
+
console.log(`\n${ctx.colors.accent(categoryLabel)} ${ctx.colors.command(item.headline)}`);
|
|
23
|
+
if (item.description) {
|
|
24
|
+
console.log(` ${ctx.colors.muted(item.description)}`);
|
|
25
|
+
}
|
|
26
|
+
const meta = [];
|
|
27
|
+
if (item.timeAgo) {
|
|
28
|
+
meta.push(item.timeAgo);
|
|
29
|
+
}
|
|
30
|
+
if (item.postCount) {
|
|
31
|
+
meta.push(`${formatPostCount(item.postCount)} posts`);
|
|
32
|
+
}
|
|
33
|
+
if (meta.length > 0) {
|
|
34
|
+
console.log(` ${ctx.colors.muted(meta.join(' | '))}`);
|
|
35
|
+
}
|
|
36
|
+
if (item.url) {
|
|
37
|
+
console.log(` ${ctx.l('url')}${item.url}`);
|
|
38
|
+
}
|
|
39
|
+
// Print related tweets if available
|
|
40
|
+
if (item.tweets && item.tweets.length > 0) {
|
|
41
|
+
console.log(` ${ctx.colors.section('Related tweets:')}`);
|
|
42
|
+
const tweetLimit = opts.tweetLimit ?? item.tweets.length;
|
|
43
|
+
for (const tweet of item.tweets.slice(0, tweetLimit)) {
|
|
44
|
+
console.log(` @${tweet.author.username}: ${tweet.text.slice(0, 100)}${tweet.text.length > 100 ? '...' : ''}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
console.log(ctx.colors.muted('─'.repeat(50)));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function registerNewsCommand(program, ctx) {
|
|
51
|
+
program
|
|
52
|
+
.command('news')
|
|
53
|
+
.alias('trending')
|
|
54
|
+
.description('Fetch AI-curated news and trending topics from Explore tabs')
|
|
55
|
+
.option('-n, --count <number>', 'Number of items to fetch', '10')
|
|
56
|
+
.option('--ai-only', 'Show only AI-curated news items')
|
|
57
|
+
.option('--with-tweets', 'Also fetch related tweets for each news item')
|
|
58
|
+
.option('--tweets-per-item <number>', 'Number of tweets to fetch per news item (default: 5)', '5')
|
|
59
|
+
.option('--for-you', 'Fetch only from For You tab')
|
|
60
|
+
.option('--news-only', 'Fetch only from News tab')
|
|
61
|
+
.option('--sports', 'Fetch only from Sports tab')
|
|
62
|
+
.option('--entertainment', 'Fetch only from Entertainment tab')
|
|
63
|
+
.option('--trending-only', 'Fetch only from Trending tab')
|
|
64
|
+
.option('--json', 'Output as JSON')
|
|
65
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
66
|
+
.action(async (cmdOpts) => {
|
|
67
|
+
const opts = program.opts();
|
|
68
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
69
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
70
|
+
const count = Number.parseInt(cmdOpts.count || '10', 10);
|
|
71
|
+
const tweetsPerItem = Number.parseInt(cmdOpts.tweetsPerItem || '5', 10);
|
|
72
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
73
|
+
for (const warning of warnings) {
|
|
74
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
75
|
+
}
|
|
76
|
+
if (Number.isNaN(count) || count < 1) {
|
|
77
|
+
console.error(`${ctx.p('err')}--count must be a positive number`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
if (Number.isNaN(tweetsPerItem) || tweetsPerItem < 1) {
|
|
81
|
+
console.error(`${ctx.p('err')}--tweets-per-item must be a positive number`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
85
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
// Determine which tabs to fetch from
|
|
89
|
+
const tabs = [];
|
|
90
|
+
if (cmdOpts.forYou) {
|
|
91
|
+
tabs.push('forYou');
|
|
92
|
+
}
|
|
93
|
+
if (cmdOpts.newsOnly) {
|
|
94
|
+
tabs.push('news');
|
|
95
|
+
}
|
|
96
|
+
if (cmdOpts.sports) {
|
|
97
|
+
tabs.push('sports');
|
|
98
|
+
}
|
|
99
|
+
if (cmdOpts.entertainment) {
|
|
100
|
+
tabs.push('entertainment');
|
|
101
|
+
}
|
|
102
|
+
if (cmdOpts.trendingOnly) {
|
|
103
|
+
tabs.push('trending');
|
|
104
|
+
}
|
|
105
|
+
// If no specific tabs selected, use defaults (all tabs except trending)
|
|
106
|
+
const tabsToFetch = tabs.length > 0 ? tabs : undefined;
|
|
107
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
108
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
109
|
+
const withTweets = cmdOpts.withTweets ?? false;
|
|
110
|
+
const aiOnly = cmdOpts.aiOnly ?? false;
|
|
111
|
+
const result = await client.getNews(count, {
|
|
112
|
+
includeRaw,
|
|
113
|
+
withTweets,
|
|
114
|
+
tweetsPerItem,
|
|
115
|
+
aiOnly,
|
|
116
|
+
tabs: tabsToFetch,
|
|
117
|
+
});
|
|
118
|
+
if (result.success) {
|
|
119
|
+
printNewsItems(result.items, ctx, {
|
|
120
|
+
json: cmdOpts.json || cmdOpts.jsonFull,
|
|
121
|
+
emptyMessage: 'No news items found.',
|
|
122
|
+
tweetLimit: withTweets ? tweetsPerItem : undefined,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.error(`${ctx.p('err')}Failed to fetch news: ${result.error}`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=news.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { formatTweetUrlLine } from '../lib/output.js';
|
|
2
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
3
|
+
async function uploadMediaOrExit(client, media, ctx) {
|
|
4
|
+
if (media.length === 0) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const uploaded = [];
|
|
8
|
+
for (const item of media) {
|
|
9
|
+
const res = await client.uploadMedia({ data: item.buffer, mimeType: item.mime, alt: item.alt });
|
|
10
|
+
if (!res.success || !res.mediaId) {
|
|
11
|
+
console.error(`${ctx.p('err')}Media upload failed: ${res.error ?? 'Unknown error'}`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
uploaded.push(res.mediaId);
|
|
15
|
+
}
|
|
16
|
+
return uploaded;
|
|
17
|
+
}
|
|
18
|
+
export function registerPostCommands(program, ctx) {
|
|
19
|
+
program
|
|
20
|
+
.command('tweet')
|
|
21
|
+
.description('Post a new tweet')
|
|
22
|
+
.argument('<text>', 'Tweet text')
|
|
23
|
+
.action(async (text) => {
|
|
24
|
+
const opts = program.opts();
|
|
25
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
26
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
27
|
+
let media = [];
|
|
28
|
+
try {
|
|
29
|
+
media = ctx.loadMedia({ media: opts.media ?? [], alts: opts.alt ?? [] });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error(`${ctx.p('err')}${error instanceof Error ? error.message : String(error)}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
36
|
+
for (const warning of warnings) {
|
|
37
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
38
|
+
}
|
|
39
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
40
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
if (cookies.source) {
|
|
44
|
+
console.error(`${ctx.l('source')}${cookies.source}`);
|
|
45
|
+
}
|
|
46
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
47
|
+
const mediaIds = await uploadMediaOrExit(client, media, ctx);
|
|
48
|
+
const result = await client.tweet(text, mediaIds);
|
|
49
|
+
if (result.success) {
|
|
50
|
+
console.log(`${ctx.p('ok')}Tweet posted successfully!`);
|
|
51
|
+
console.log(formatTweetUrlLine(result.tweetId, ctx.getOutput()));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.error(`${ctx.p('err')}Failed to post tweet: ${result.error}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
program
|
|
59
|
+
.command('reply')
|
|
60
|
+
.description('Reply to an existing tweet')
|
|
61
|
+
.argument('<tweet-id-or-url>', 'Tweet ID or URL to reply to')
|
|
62
|
+
.argument('<text>', 'Reply text')
|
|
63
|
+
.action(async (tweetIdOrUrl, text) => {
|
|
64
|
+
const opts = program.opts();
|
|
65
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
66
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
67
|
+
let media = [];
|
|
68
|
+
try {
|
|
69
|
+
media = ctx.loadMedia({ media: opts.media ?? [], alts: opts.alt ?? [] });
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error(`${ctx.p('err')}${error instanceof Error ? error.message : String(error)}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
|
76
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
77
|
+
for (const warning of warnings) {
|
|
78
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
79
|
+
}
|
|
80
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
81
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (cookies.source) {
|
|
85
|
+
console.error(`${ctx.l('source')}${cookies.source}`);
|
|
86
|
+
}
|
|
87
|
+
console.error(`${ctx.p('info')}Replying to tweet: ${tweetId}`);
|
|
88
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
89
|
+
const mediaIds = await uploadMediaOrExit(client, media, ctx);
|
|
90
|
+
const result = await client.reply(text, tweetId, mediaIds);
|
|
91
|
+
if (result.success) {
|
|
92
|
+
console.log(`${ctx.p('ok')}Reply posted successfully!`);
|
|
93
|
+
console.log(formatTweetUrlLine(result.tweetId, ctx.getOutput()));
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
console.error(`${ctx.p('err')}Failed to post reply: ${result.error}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=post.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { getFeatureOverridesSnapshot, refreshFeatureOverridesCache, } from '../lib/runtime-features.js';
|
|
2
|
+
import { runtimeQueryIds } from '../lib/runtime-query-ids.js';
|
|
3
|
+
function countFeatureOverrides(overrides) {
|
|
4
|
+
let count = 0;
|
|
5
|
+
if (overrides.global) {
|
|
6
|
+
count += Object.keys(overrides.global).length;
|
|
7
|
+
}
|
|
8
|
+
if (overrides.sets) {
|
|
9
|
+
for (const setOverrides of Object.values(overrides.sets)) {
|
|
10
|
+
count += Object.keys(setOverrides).length;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return count;
|
|
14
|
+
}
|
|
15
|
+
export function registerQueryIdsCommand(program, ctx) {
|
|
16
|
+
program
|
|
17
|
+
.command('query-ids')
|
|
18
|
+
.description('Show or refresh cached Twitter GraphQL query IDs')
|
|
19
|
+
.option('--json', 'Output as JSON')
|
|
20
|
+
.option('--fresh', 'Force refresh (downloads X client bundles)', false)
|
|
21
|
+
.action(async (cmdOpts) => {
|
|
22
|
+
const operations = [
|
|
23
|
+
'CreateTweet',
|
|
24
|
+
'CreateRetweet',
|
|
25
|
+
'FavoriteTweet',
|
|
26
|
+
'TweetDetail',
|
|
27
|
+
'SearchTimeline',
|
|
28
|
+
'UserArticlesTweets',
|
|
29
|
+
'Bookmarks',
|
|
30
|
+
'Following',
|
|
31
|
+
'Followers',
|
|
32
|
+
'Likes',
|
|
33
|
+
];
|
|
34
|
+
if (cmdOpts.fresh) {
|
|
35
|
+
console.error(`${ctx.p('info')}Refreshing GraphQL query IDs…`);
|
|
36
|
+
await runtimeQueryIds.refresh(operations, { force: true });
|
|
37
|
+
console.error(`${ctx.p('info')}Refreshing feature overrides…`);
|
|
38
|
+
await refreshFeatureOverridesCache();
|
|
39
|
+
}
|
|
40
|
+
const featureSnapshot = getFeatureOverridesSnapshot();
|
|
41
|
+
const info = await runtimeQueryIds.getSnapshotInfo();
|
|
42
|
+
if (!info) {
|
|
43
|
+
if (cmdOpts.json) {
|
|
44
|
+
console.log(JSON.stringify({
|
|
45
|
+
cached: false,
|
|
46
|
+
cachePath: runtimeQueryIds.cachePath,
|
|
47
|
+
featuresPath: featureSnapshot.cachePath,
|
|
48
|
+
features: featureSnapshot.overrides,
|
|
49
|
+
}, null, 2));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
console.log(`${ctx.p('warn')}No cached query IDs yet.`);
|
|
53
|
+
console.log(`${ctx.p('info')}Run: bird query-ids --fresh`);
|
|
54
|
+
console.log(`features_path: ${featureSnapshot.cachePath}`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (cmdOpts.json) {
|
|
58
|
+
console.log(JSON.stringify({
|
|
59
|
+
cached: true,
|
|
60
|
+
cachePath: info.cachePath,
|
|
61
|
+
fetchedAt: info.snapshot.fetchedAt,
|
|
62
|
+
isFresh: info.isFresh,
|
|
63
|
+
ageMs: info.ageMs,
|
|
64
|
+
ids: info.snapshot.ids,
|
|
65
|
+
discovery: info.snapshot.discovery,
|
|
66
|
+
featuresPath: featureSnapshot.cachePath,
|
|
67
|
+
features: featureSnapshot.overrides,
|
|
68
|
+
}, null, 2));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(`${ctx.p('ok')}GraphQL query IDs cached`);
|
|
72
|
+
console.log(`path: ${info.cachePath}`);
|
|
73
|
+
console.log(`fetched_at: ${info.snapshot.fetchedAt}`);
|
|
74
|
+
console.log(`fresh: ${info.isFresh ? 'yes' : 'no'}`);
|
|
75
|
+
console.log(`ops: ${Object.keys(info.snapshot.ids).length}`);
|
|
76
|
+
console.log(`features_path: ${featureSnapshot.cachePath}`);
|
|
77
|
+
console.log(`features: ${countFeatureOverrides(featureSnapshot.overrides)}`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=query-ids.js.map
|