chore: remove unused root vendor/ directory (215 files from PR #48)
Root vendor/package/ was an accidentally committed extracted npm tarball (steipete-bird-0.8.0). Zero importers: the real vendored X client lives at scripts/lib/vendor/bird-search/, referenced by scripts/lib/bird_x.py and tests/test_bird_x.py. Removes 215 files + 1 .tgz, dropping repo from 406 to 191 files and clearing the claude.ai skill-upload 200-file cap. Adds /vendor/ to .gitignore (leading slash so scripts/lib/vendor/ is unaffected).
This commit is contained in:
@@ -19,3 +19,6 @@ mise.toml
|
||||
.venv/
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
||||
# Root vendor/ is accidental - real vendored client lives at scripts/lib/vendor/bird-search/
|
||||
/vendor/
|
||||
|
||||
Vendored
-176
@@ -1,176 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## 0.8.0 — 2026-01-19
|
||||
|
||||
### Added
|
||||
- `bookmarks` thread expansion controls (`--expand-root-only`, `--author-chain`, `--author-only`, `--full-chain-only`, `--include-ancestor-branches`, `--include-parent`, `--thread-meta`, `--sort-chronological`) for richer context exports (#55) — thanks @kkretschmer2.
|
||||
- `--chrome-profile-dir` to point at Chromium profile directories or cookie DB files (Arc/Brave/etc) for cookie extraction (#16) — thanks @tekumara.
|
||||
- `about` command to report account origin/location metadata (#51) — thanks @pjtf93.
|
||||
- `follow`/`unfollow` commands to manage follows (#54) — thanks @citizenlee.
|
||||
- Twitter client now supports like/unlike/retweet/unretweet/bookmark via the engagement mixin (#53) — thanks @the-vampiire.
|
||||
|
||||
### Fixed
|
||||
- `bookmarks` expanded JSON now preserves pagination `nextCursor`, and full-chain filtering only includes ancestor branches when requested.
|
||||
- Follow/unfollow REST fallback now supports cursor pagination for followers/following (#54).
|
||||
- About account live coverage now verifies data extraction paths (#51) — thanks @pjtf93.
|
||||
|
||||
### Tests
|
||||
- Live tests now exercise engagement mutations (opt-in) (#53) — thanks @the-vampiire.
|
||||
|
||||
## 0.7.0 — 2026-01-12
|
||||
|
||||
### Added
|
||||
- `home` command for the "For You" and "Following" home timelines (#31) — thanks @odysseus0.
|
||||
- `news`/`trending` command for Explore tabs with AI-curated headlines (#39) — thanks @aavetis.
|
||||
- `user-tweets` command to fetch a user's profile timeline (#34) — thanks @crcatala.
|
||||
- `replies` and `thread` now support pagination (`--all`, `--max-pages`, `--cursor`, `--delay`) (#35) — thanks @crcatala.
|
||||
- `search` now supports pagination (`--all`, `--max-pages`, `--cursor`) (#42) — thanks @pjtf93.
|
||||
- `likes` now supports pagination (`--all`, `--max-pages`, `--cursor`) (#44) — thanks @jsholmes.
|
||||
- `list-timeline` now supports pagination (`--all`, `--max-pages`, `--cursor`) (#30) — thanks @zheli.
|
||||
- Rich text output now shows article previews, quoted tweets, and media links (#32) — thanks @odysseus0.
|
||||
- Long-form article tweets now render rich Draft.js content blocks/entities (#36) — thanks @crcatala.
|
||||
|
||||
### Changed
|
||||
- Library typing: `SearchResult` is now a discriminated union (so `error` only exists when `success: false`).
|
||||
|
||||
### Fixed
|
||||
- Lists GraphQL feature flags updated to prevent 400s (#27) — thanks @zheli.
|
||||
- Lists feature overrides now scope new GraphQL flags correctly (#50) — thanks @ryanh-ai.
|
||||
- Tweet detail parsing now tolerates partial GraphQL errors when usable data exists (#48) — thanks @jsholmes.
|
||||
- News output now respects `--tweets-per-item`, keeps unique IDs, and parses non-add entry instructions (#39) — thanks @aavetis.
|
||||
- Following/followers pagination now guards repeat cursors and standardizes JSON output (#28) — thanks @malpern.
|
||||
- Likes pagination now follows cursors and avoids stalling on duplicate pages (#12) — thanks @titouv.
|
||||
- macOS cookie extraction now supports Brave keychain storage (#40) — thanks @gakonst.
|
||||
- Terminal hyperlinks now sanitize control characters before emitting OSC 8 sequences (#29) — thanks @mafulafunk.
|
||||
- `pnpm run build:dist` now succeeds after tightening JSON/pagination option typing in tweet output commands.
|
||||
|
||||
### Tests
|
||||
- Following: split following/likes tests + cover cursor handling (#33) — thanks @VACInc.
|
||||
|
||||
## 0.6.0 — 2026-01-05
|
||||
|
||||
### Added
|
||||
- Bookmark exports now support pagination (`--all`, `--max-pages`) with retries (#15) — thanks @Nano1337.
|
||||
- `lists` + `list-timeline` commands for Twitter Lists (#21) — thanks @harperreed
|
||||
- Tweet JSON output now includes media items (photos, videos, GIFs) (#14) — thanks @Hormold
|
||||
- Bookmarks can resume pagination from a cursor (#26) — thanks @leonho
|
||||
- `unbookmark` command to remove bookmarked tweets (#22) — thanks @mbelinky.
|
||||
|
||||
### Changed
|
||||
- Feature flags can be overridden at runtime via `features.json` (refreshable via `query-ids`).
|
||||
|
||||
### Fixed
|
||||
- GraphQL feature flags now include `post_ctas_fetch_enabled` to avoid 400s (#38) — thanks @philipp-spiess.
|
||||
|
||||
## 0.5.1 — 2026-01-01
|
||||
|
||||
### Changed
|
||||
- `bird --help` now includes explicit “Shortcuts” and “JSON Output” sections (documents `bird <tweet-id-or-url>` shorthand + `--json`).
|
||||
- Release docs now include explicit npm publish verification steps.
|
||||
|
||||
### Fixed
|
||||
- `pnpm bird --help` now works (dev script runs the CLI entrypoint, not the library entrypoint).
|
||||
- `following`/`followers` now fall back to internal v1.1 REST endpoints when GraphQL returns `404`.
|
||||
|
||||
### Tests
|
||||
- Add root help output regression test.
|
||||
- Add opt-in live CLI test suite (real GraphQL calls; skipped by default; gated via `BIRD_LIVE=1`).
|
||||
|
||||
## 0.5.0 — 2026-01-01
|
||||
|
||||
### Added
|
||||
- `likes` command to list your liked tweets (thanks @swairshah).
|
||||
- Quoted tweet data in JSON output + `--quote-depth` (thanks @alexknowshtml).
|
||||
- `following`/`followers` commands to list users (thanks @lockmeister).
|
||||
|
||||
### Changed
|
||||
- Query ID updater now tracks the Likes GraphQL operation.
|
||||
- Query ID updater now tracks Following/Followers GraphQL operations.
|
||||
- Query ID updater now tracks BookmarkFolderTimeline and keeps bookmark query IDs seeded.
|
||||
- `following`/`followers` JSON user fields are now camelCase (`followersCount`, `followingCount`, `isBlueVerified`, `profileImageUrl`, `createdAt`).
|
||||
- Cookie extraction timeout is now configurable (default 30s on macOS) via `--cookie-timeout` / `BIRD_COOKIE_TIMEOUT_MS` (thanks @tylerseymour).
|
||||
- Search now paginates beyond 20 results when using `-n` (thanks @ryanh-ai).
|
||||
- Library exports are now separated from the CLI entrypoint for easier embedding.
|
||||
|
||||
## 0.4.1 — 2025-12-31
|
||||
|
||||
### Added
|
||||
- `bookmarks` command to list your bookmarked tweets.
|
||||
- `bookmarks --folder-id` to fetch bookmark folders (thanks @tylerseymour).
|
||||
|
||||
### Changed
|
||||
- Cookie extraction now uses `@steipete/sweet-cookie` (drops `sqlite3` CLI + custom browser readers in `bird`).
|
||||
- Query ID updater now tracks the Bookmarks GraphQL operation.
|
||||
- Lint rules stricter (block statements, no-negation-else, useConst/useTemplate, top-level regex, import extension enforcement).
|
||||
- `pnpm lint` now runs both Biome and oxlint (type-aware).
|
||||
|
||||
### Tests
|
||||
- Coverage thresholds raised to 90% statements/lines/functions (80% branches).
|
||||
- Added targeted Twitter client coverage suites.
|
||||
|
||||
## 0.4.0 — 2025-12-26
|
||||
|
||||
### Added
|
||||
- Cookie source selection: `--cookie-source safari|chrome|firefox` (repeatable) + `cookieSource` config (string or array).
|
||||
|
||||
### Fixed
|
||||
- `tweet`/`reply`: fallback to `statuses/update.json` when GraphQL `CreateTweet` returns error 226 (“automated request”).
|
||||
|
||||
### Breaking
|
||||
- Remove `allowSafari`/`allowChrome`/`allowFirefox` config toggles in favor of `cookieSource` ordering.
|
||||
|
||||
## 0.3.0 — 2025-12-26
|
||||
|
||||
### Added
|
||||
- Safari cookie extraction (`Cookies.binarycookies`) + `allowSafari` config toggle.
|
||||
|
||||
### Changed
|
||||
- Removed the Sweetistics engine + fallback. `bird` is GraphQL-only.
|
||||
- Browser cookie fallback order: Safari → Chrome → Firefox.
|
||||
|
||||
### Tests
|
||||
- Enforce coverage thresholds (>= 70% statements/branches/functions/lines) + expand unit coverage for version/output/Twitter client branches.
|
||||
|
||||
## 0.2.0 — 2025-12-26
|
||||
|
||||
### Added
|
||||
- Output controls: `--plain`, `--no-emoji`, `--no-color` (respects `NO_COLOR`).
|
||||
- `help` command: `bird help <command>`.
|
||||
- Runtime GraphQL query ID refresh: `bird query-ids --fresh` (cached on disk; auto-retry on 404; override cache via `BIRD_QUERY_IDS_CACHE`).
|
||||
- GraphQL media uploads via `--media` (up to 4 images/GIFs, or 1 video).
|
||||
|
||||
### Fixed
|
||||
- CLI `--version`: read version from `package.json`/`VERSION` (no hardcoded string) + append git sha when available.
|
||||
|
||||
### Changed
|
||||
- `mentions`: no hardcoded user; defaults to authenticated user or accepts `--user @handle`.
|
||||
- GraphQL query ID updater: correctly pairs `operationName` ↔ `queryId` (CreateTweet/CreateRetweet/etc).
|
||||
- `build:dist`: copies `src/lib/query-ids.json` into `dist/lib/query-ids.json` (keeps `dist/` in sync).
|
||||
- `--engine graphql`: strict GraphQL-only (disables Sweetistics fallback).
|
||||
|
||||
## 0.1.1 — 2025-12-26
|
||||
|
||||
### Changed
|
||||
- Engine default now `auto` (GraphQL primary; Sweetistics only on fallback when configured).
|
||||
|
||||
### Tests
|
||||
- Add engine resolution tests for auto/default behavior.
|
||||
|
||||
### Fixed
|
||||
- GraphQL read: rotate TweetDetail query IDs with fallback to avoid 404s.
|
||||
|
||||
## 0.1.0 — 2025-12-20
|
||||
|
||||
### Added
|
||||
- CLI commands: `tweet`, `reply`, `read`, `replies`, `thread`, `search`, `mentions`, `whoami`, `check`.
|
||||
- URL/ID shorthand for `read`, plus `--json` output where supported.
|
||||
- GraphQL engine with cookie auth from Firefox/Chrome/env/flags (macOS browsers).
|
||||
- Sweetistics engine (API key) with automatic fallback when configured.
|
||||
- Media uploads via Sweetistics with per-item alt text (images or single video).
|
||||
- Long-form Notes and Articles extraction for full text output.
|
||||
- Thread + reply fetching with full conversation parsing.
|
||||
- Search + mentions via GraphQL (latest timeline).
|
||||
- JSON5 config files (`~/.config/bird/config.json5`, `./.birdrc.json5`) with engine defaults, profiles, allowChrome/allowFirefox, and timeoutMs.
|
||||
- Request timeouts (`--timeout`, `timeoutMs`) for GraphQL and Sweetistics calls.
|
||||
- Bun-compiled standalone binary via `pnpm run build`.
|
||||
- Query ID refresh helper: `pnpm run graphql:update`.
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Peter Steinberger
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Vendored
-385
@@ -1,385 +0,0 @@
|
||||
# bird 🐦 — fast X CLI for tweeting, replying, and reading
|
||||
|
||||
`bird` is a fast X CLI for tweeting, replying, and reading via X/Twitter GraphQL (cookie auth).
|
||||
|
||||
## Disclaimer
|
||||
|
||||
This project uses X/Twitter’s **undocumented** web GraphQL API (and cookie auth). X can change endpoints, query IDs,
|
||||
and anti-bot behavior at any time — **expect this to break without notice**.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install -g @steipete/bird
|
||||
# or
|
||||
pnpm add -g @steipete/bird
|
||||
# or
|
||||
bun add -g @steipete/bird
|
||||
|
||||
# one-shot (no install)
|
||||
bunx @steipete/bird whoami
|
||||
```
|
||||
|
||||
Homebrew (macOS, prebuilt Bun binary):
|
||||
|
||||
```bash
|
||||
brew install steipete/tap/bird
|
||||
```
|
||||
|
||||
## Quickstart
|
||||
|
||||
```bash
|
||||
# Show the logged-in account
|
||||
bird whoami
|
||||
|
||||
# Discover command help
|
||||
bird help whoami
|
||||
|
||||
# Read a tweet (URL or ID)
|
||||
bird read https://x.com/user/status/1234567890123456789
|
||||
bird 1234567890123456789 --json
|
||||
|
||||
# Thread + replies
|
||||
bird thread https://x.com/user/status/1234567890123456789
|
||||
bird replies 1234567890123456789
|
||||
bird replies 1234567890123456789 --max-pages 3 --json
|
||||
bird thread 1234567890123456789 --max-pages 3 --json
|
||||
|
||||
# Search + mentions
|
||||
bird search "from:steipete" -n 5
|
||||
bird mentions -n 5
|
||||
bird mentions --user @steipete -n 5
|
||||
|
||||
# User tweets (profile timeline)
|
||||
bird user-tweets @steipete -n 20
|
||||
bird user-tweets @steipete -n 50 --json
|
||||
|
||||
# Bookmarks
|
||||
bird bookmarks -n 5
|
||||
bird bookmarks --folder-id 123456789123456789 -n 5 # https://x.com/i/bookmarks/<folder-id>
|
||||
bird bookmarks --all --json
|
||||
bird bookmarks --all --max-pages 2 --json
|
||||
bird bookmarks --include-parent --json
|
||||
bird unbookmark 1234567890123456789
|
||||
bird unbookmark https://x.com/user/status/1234567890123456789
|
||||
|
||||
# Likes
|
||||
bird likes -n 5
|
||||
|
||||
# News and trending topics (AI-curated from Explore tabs)
|
||||
bird news --ai-only -n 10
|
||||
bird news --sports -n 5
|
||||
|
||||
# Lists
|
||||
bird list-timeline 1234567890 -n 20
|
||||
bird list-timeline https://x.com/i/lists/1234567890 --all --json
|
||||
bird list-timeline 1234567890 --max-pages 3 --json
|
||||
|
||||
# Following (who you follow)
|
||||
bird following -n 20
|
||||
bird following --user 12345678 -n 10 # by user ID
|
||||
|
||||
# Followers (who follows you)
|
||||
bird followers -n 20
|
||||
bird followers --user 12345678 -n 10 # by user ID
|
||||
|
||||
# Refresh GraphQL query IDs cache (no rebuild)
|
||||
bird query-ids --fresh
|
||||
```
|
||||
|
||||
## News & Trending
|
||||
|
||||
Fetch AI-curated news and trending topics from X's Explore page tabs:
|
||||
|
||||
```bash
|
||||
# Fetch 10 news items from all tabs (default: For You, News, Sports, Entertainment)
|
||||
bird news -n 10
|
||||
|
||||
# Fetch only AI-curated news (filters out regular trends)
|
||||
bird news --ai-only -n 20
|
||||
|
||||
# Fetch from specific tabs
|
||||
bird news --news-only --ai-only -n 10
|
||||
bird news --sports -n 15
|
||||
bird news --entertainment --ai-only -n 5
|
||||
|
||||
# Include related tweets for each news item
|
||||
bird news --with-tweets --tweets-per-item 3 -n 10
|
||||
|
||||
# Combine multiple tab filters
|
||||
bird news --sports --entertainment -n 20
|
||||
|
||||
# JSON output
|
||||
bird news --json -n 5
|
||||
bird news --json-full --ai-only -n 10 # includes raw API response
|
||||
```
|
||||
|
||||
Tab options (can be combined):
|
||||
- `--for-you` — Fetch from For You tab only
|
||||
- `--news-only` — Fetch from News tab only
|
||||
- `--sports` — Fetch from Sports tab only
|
||||
- `--entertainment` — Fetch from Entertainment tab only
|
||||
- `--trending-only` — Fetch from Trending tab only
|
||||
|
||||
By default, the command fetches from For You, News, Sports, and Entertainment tabs (Trending excluded to reduce noise). Headlines are automatically deduplicated across tabs.
|
||||
|
||||
## Library
|
||||
|
||||
`bird` can be used as a library (same GraphQL client as the CLI):
|
||||
|
||||
```ts
|
||||
import { TwitterClient, resolveCredentials } from '@steipete/bird';
|
||||
|
||||
const { cookies } = await resolveCredentials({ cookieSource: 'safari' });
|
||||
const client = new TwitterClient({ cookies });
|
||||
|
||||
// Search for tweets
|
||||
const searchResult = await client.search('from:steipete', 50);
|
||||
|
||||
// Fetch news and trending topics from all tabs (default: For You, News, Sports, Entertainment)
|
||||
const newsResult = await client.getNews(10, { aiOnly: true });
|
||||
|
||||
// Fetch from specific tabs with related tweets
|
||||
const sportsNews = await client.getNews(10, {
|
||||
aiOnly: true,
|
||||
withTweets: true,
|
||||
tabs: ['sports', 'entertainment']
|
||||
});
|
||||
```
|
||||
|
||||
Account details (About profile):
|
||||
|
||||
```ts
|
||||
const aboutResult = await client.getUserAboutAccount('steipete');
|
||||
if (aboutResult.success && aboutResult.aboutProfile) {
|
||||
console.log(aboutResult.aboutProfile.accountBasedIn);
|
||||
}
|
||||
```
|
||||
|
||||
Fields:
|
||||
- `accountBasedIn`
|
||||
- `source`
|
||||
- `createdCountryAccurate`
|
||||
- `locationAccurate`
|
||||
- `learnMoreUrl`
|
||||
|
||||
## Commands
|
||||
|
||||
- `bird tweet "<text>"` — post a new tweet.
|
||||
- `bird reply <tweet-id-or-url> "<text>"` — reply to a tweet using its ID or URL.
|
||||
- `bird help [command]` — show help (or help for a subcommand).
|
||||
- `bird query-ids [--fresh] [--json]` — inspect or refresh cached GraphQL query IDs.
|
||||
- `bird home [-n count] [--following] [--json] [--json-full]` — fetch your home timeline (For You) or Following feed.
|
||||
- `bird read <tweet-id-or-url> [--json]` — fetch tweet content as text or JSON.
|
||||
- `bird <tweet-id-or-url> [--json]` — shorthand for `read` when only a URL or ID is provided.
|
||||
- `bird replies <tweet-id-or-url> [--all] [--max-pages n] [--cursor string] [--delay ms] [--json]` — list replies to a tweet.
|
||||
- `bird thread <tweet-id-or-url> [--all] [--max-pages n] [--cursor string] [--delay ms] [--json]` — show the full conversation thread.
|
||||
- `bird search "<query>" [-n count] [--all] [--max-pages n] [--cursor string] [--json]` — search for tweets matching a query; `--max-pages` requires `--all` or `--cursor`.
|
||||
- `bird mentions [-n count] [--user @handle] [--json]` — find tweets mentioning a user (defaults to the authenticated user).
|
||||
- `bird user-tweets <@handle> [-n count] [--cursor string] [--max-pages n] [--delay ms] [--json]` — get tweets from a user's profile timeline.
|
||||
- `bird bookmarks [-n count] [--folder-id id] [--all] [--max-pages n] [--cursor string] [--expand-root-only] [--author-chain] [--author-only] [--full-chain-only] [--include-ancestor-branches] [--include-parent] [--thread-meta] [--sort-chronological] [--json]` — list your bookmarked tweets (or a specific bookmark folder); expansion flags control thread context; `--max-pages` requires `--all` or `--cursor`.
|
||||
- `bird unbookmark <tweet-id-or-url...>` — remove one or more bookmarks by tweet ID or URL.
|
||||
- `bird likes [-n count] [--all] [--max-pages n] [--cursor string] [--json] [--json-full]` — list your liked tweets; `--max-pages` requires `--all` or `--cursor`.
|
||||
- `bird news [-n count] [--ai-only] [--with-tweets] [--tweets-per-item n] [--for-you] [--news-only] [--sports] [--entertainment] [--trending-only] [--json]` — fetch news and trending topics from X's Explore tabs.
|
||||
- `bird trending` — alias for `news` command.
|
||||
- `bird lists [--member-of] [-n count] [--json]` — list your lists (owned or memberships).
|
||||
- `bird list-timeline <list-id-or-url> [-n count] [--all] [--max-pages n] [--cursor string] [--json]` — get tweets from a list timeline; `--max-pages` implies `--all`.
|
||||
- `bird following [--user <userId>] [-n count] [--cursor string] [--all] [--max-pages n] [--json]` — list users that you (or another user) follow; `--max-pages` requires `--all`.
|
||||
- `bird followers [--user <userId>] [-n count] [--cursor string] [--all] [--max-pages n] [--json]` — list users that follow you (or another user); `--max-pages` requires `--all`.
|
||||
- `bird about <@handle> [--json]` — get account origin and location information for a user.
|
||||
- `bird whoami` — print which Twitter account your cookies belong to.
|
||||
- `bird check` — show which credentials are available and where they were sourced from.
|
||||
|
||||
Bookmarks flags:
|
||||
- `--expand-root-only`: expand threads only when the bookmark is a root tweet.
|
||||
- `--author-chain`: keep only the bookmarked author's connected self-reply chain.
|
||||
- `--author-only`: include all tweets from the bookmarked author within the thread.
|
||||
- `--full-chain-only`: keep the entire reply chain connected to the bookmarked tweet (all authors).
|
||||
- `--include-ancestor-branches`: include sibling branches for ancestors when using `--full-chain-only`.
|
||||
- `--include-parent`: include the direct parent tweet for non-root bookmarks.
|
||||
- `--thread-meta`: add thread metadata fields to each tweet.
|
||||
- `--sort-chronological`: sort output globally oldest to newest (default preserves bookmark order).
|
||||
|
||||
Global options:
|
||||
- `--auth-token <token>`: set the `auth_token` cookie manually.
|
||||
- `--ct0 <token>`: set the `ct0` cookie manually.
|
||||
- `--cookie-source <safari|chrome|firefox>`: choose browser cookie source (repeatable; order matters).
|
||||
- `--chrome-profile <name>`: Chrome profile name for cookie extraction (e.g., `Default`, `Profile 2`).
|
||||
- `--chrome-profile-dir <path>`: Chrome/Chromium profile directory or cookie DB path for cookie extraction.
|
||||
- `--firefox-profile <name>`: Firefox profile for cookie extraction.
|
||||
- `--cookie-timeout <ms>`: cookie extraction timeout for keychain/OS helpers (milliseconds).
|
||||
- `--timeout <ms>`: abort requests after the given timeout (milliseconds).
|
||||
- `--quote-depth <n>`: max quoted tweet depth in JSON output (default: 1; 0 disables).
|
||||
- `--plain`: stable output (no emoji, no color).
|
||||
- `--no-emoji`: disable emoji output.
|
||||
- `--no-color`: disable ANSI colors (or set `NO_COLOR=1`).
|
||||
- `--media <path>`: attach media file (repeatable, up to 4 images or 1 video).
|
||||
- `--alt <text>`: alt text for the corresponding `--media` (repeatable).
|
||||
|
||||
## Authentication (GraphQL)
|
||||
|
||||
GraphQL mode uses your existing X/Twitter web session (no password prompt). It sends requests to internal
|
||||
X endpoints and authenticates via cookies (`auth_token`, `ct0`).
|
||||
|
||||
Write operations:
|
||||
- `tweet`/`reply` primarily use GraphQL (`CreateTweet`).
|
||||
- If GraphQL returns error `226` (“automated request”), `bird` falls back to the legacy `statuses/update.json` endpoint.
|
||||
|
||||
`bird` resolves credentials in this order:
|
||||
|
||||
1. CLI flags: `--auth-token`, `--ct0`
|
||||
2. Environment variables: `AUTH_TOKEN`, `CT0` (fallback: `TWITTER_AUTH_TOKEN`, `TWITTER_CT0`)
|
||||
3. Browser cookies via `@steipete/sweet-cookie` (override via `--cookie-source` order)
|
||||
|
||||
Browser cookie sources:
|
||||
- Safari: `~/Library/Cookies/Cookies.binarycookies` (fallback: `~/Library/Containers/com.apple.Safari/Data/Library/Cookies/Cookies.binarycookies`)
|
||||
- Chrome: `~/Library/Application Support/Google/Chrome/<Profile>/Cookies`
|
||||
- Firefox: `~/Library/Application Support/Firefox/Profiles/<profile>/cookies.sqlite`
|
||||
- For Chromium variants (Arc/Brave/etc), pass a profile directory or cookie DB via `--chrome-profile-dir`.
|
||||
|
||||
## Config (JSON5)
|
||||
|
||||
Config precedence: CLI flags > env vars > project config > global config.
|
||||
|
||||
- Global: `~/.config/bird/config.json5`
|
||||
- Project: `./.birdrc.json5`
|
||||
|
||||
Example `~/.config/bird/config.json5`:
|
||||
|
||||
```json5
|
||||
{
|
||||
// Cookie source order for browser extraction (string or array)
|
||||
cookieSource: ["firefox", "safari"],
|
||||
chromeProfileDir: "/path/to/Chromium/Profile",
|
||||
firefoxProfile: "default-release",
|
||||
cookieTimeoutMs: 30000,
|
||||
timeoutMs: 20000,
|
||||
quoteDepth: 1
|
||||
}
|
||||
```
|
||||
|
||||
Environment shortcuts:
|
||||
- `BIRD_TIMEOUT_MS`
|
||||
- `BIRD_COOKIE_TIMEOUT_MS`
|
||||
- `BIRD_QUOTE_DEPTH`
|
||||
|
||||
## Output
|
||||
|
||||
- `--json` prints raw tweet objects for read/replies/thread/search/mentions/user-tweets/bookmarks/likes.
|
||||
- When using `--json` with pagination (`--all`, `--cursor`, `--max-pages`, or for `user-tweets` when `-n > 20`), output is `{ tweets, nextCursor }`.
|
||||
- `read` returns full text for Notes and Articles when present.
|
||||
- Use `--plain` for stable, script-friendly output (no emoji, no color).
|
||||
|
||||
### JSON Schema
|
||||
|
||||
When using `--json`, tweet objects include:
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `id` | string | Tweet ID |
|
||||
| `text` | string | Full tweet text (includes Note/Article content when present) |
|
||||
| `author` | object | `{ username, name }` |
|
||||
| `authorId` | string? | Author's user ID |
|
||||
| `createdAt` | string | Timestamp |
|
||||
| `replyCount` | number | Number of replies |
|
||||
| `retweetCount` | number | Number of retweets |
|
||||
| `likeCount` | number | Number of likes |
|
||||
| `conversationId` | string | Thread conversation ID |
|
||||
| `inReplyToStatusId` | string? | Parent tweet ID (present if this is a reply) |
|
||||
| `quotedTweet` | object? | Embedded quote tweet (same schema; depth controlled by `--quote-depth`) |
|
||||
|
||||
When using `--json` with `following`/`followers`, user objects include:
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `id` | string | User ID |
|
||||
| `username` | string | Username/handle |
|
||||
| `name` | string | Display name |
|
||||
| `description` | string? | User bio |
|
||||
| `followersCount` | number? | Followers count |
|
||||
| `followingCount` | number? | Following count |
|
||||
| `isBlueVerified` | boolean? | Blue verified flag |
|
||||
| `profileImageUrl` | string? | Profile image URL |
|
||||
| `createdAt` | string? | Account creation timestamp |
|
||||
|
||||
When using `--json` with `news`/`trending`, news objects include:
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `id` | string | Unique identifier for the news item |
|
||||
| `headline` | string | News headline or trend title |
|
||||
| `category` | string? | Category (e.g., "AI · Technology", "Trending", "News") |
|
||||
| `timeAgo` | string? | Relative time (e.g., "2h ago") |
|
||||
| `postCount` | number? | Number of posts |
|
||||
| `description` | string? | Item description |
|
||||
| `url` | string? | URL to the trend or news article |
|
||||
| `tweets` | array? | Related tweets (only when `--with-tweets` is used) |
|
||||
| `_raw` | object? | Raw API response (only when `--json-full` is used) |
|
||||
|
||||
|
||||
## Query IDs (GraphQL)
|
||||
|
||||
X rotates GraphQL “query IDs” frequently. Each GraphQL operation is addressed as:
|
||||
|
||||
- `operationName` (e.g. `TweetDetail`, `CreateTweet`)
|
||||
- `queryId` (rotating ID baked into X’s web client bundles)
|
||||
|
||||
`bird` ships with a baseline mapping in `src/lib/query-ids.json` (copied into `dist/` on build). At runtime,
|
||||
it can refresh that mapping by scraping X’s public web client bundles and caching the result on disk.
|
||||
|
||||
Runtime cache:
|
||||
- Default path: `~/.config/bird/query-ids-cache.json`
|
||||
- Override path: `BIRD_QUERY_IDS_CACHE=/path/to/file.json`
|
||||
- TTL: 24h (stale cache is still used, but marked “not fresh”)
|
||||
|
||||
Auto-recovery:
|
||||
- On GraphQL `404` (query ID invalid), `bird` forces a refresh once and retries.
|
||||
- For `TweetDetail`/`SearchTimeline`, `bird` also rotates through a small set of known fallback IDs to reduce
|
||||
breakage while refreshing.
|
||||
|
||||
Refresh on demand:
|
||||
|
||||
```bash
|
||||
bird query-ids --fresh
|
||||
```
|
||||
|
||||
Exit codes:
|
||||
- `0`: success
|
||||
- `1`: runtime error (network/auth/etc)
|
||||
- `2`: invalid usage/validation (e.g. bad `--user` handle)
|
||||
|
||||
## Version
|
||||
|
||||
`bird --version` prints `package.json` version plus current git sha when available, e.g. `0.3.0 (3df7969b)`.
|
||||
|
||||
## Media uploads
|
||||
|
||||
- Attach media with `--media` (repeatable) and optional `--alt` per item.
|
||||
- Up to 4 images/GIFs, or 1 video (no mixing). Supported: jpg, jpeg, png, webp, gif, mp4, mov.
|
||||
- Images/GIFs + 1 video supported (uploads via Twitter legacy upload endpoint + cookies; video may take longer to process).
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
bird tweet "hi" --media img.png --alt "desc"
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
cd ~/Projects/bird
|
||||
pnpm install
|
||||
pnpm run build # dist/ + bun binary
|
||||
pnpm run build:dist # dist/ only
|
||||
pnpm run build:binary
|
||||
|
||||
pnpm run dev tweet "Test"
|
||||
pnpm run dev -- --plain check
|
||||
pnpm test
|
||||
pnpm run lint
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- GraphQL uses internal X endpoints and can be rate limited (429).
|
||||
- Query IDs rotate; refresh at runtime with `bird query-ids --fresh` (or update the baked baseline via `pnpm run graphql:update`).
|
||||
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* bird - CLI tool for posting tweets and replies
|
||||
*
|
||||
* Usage:
|
||||
* bird tweet "Hello world!"
|
||||
* bird reply <tweet-id> "This is a reply"
|
||||
* bird reply <tweet-url> "This is a reply"
|
||||
* bird read <tweet-id-or-url>
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=cli.d.ts.map
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG"}
|
||||
Vendored
-29
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* bird - CLI tool for posting tweets and replies
|
||||
*
|
||||
* Usage:
|
||||
* bird tweet "Hello world!"
|
||||
* bird reply <tweet-id> "This is a reply"
|
||||
* bird reply <tweet-url> "This is a reply"
|
||||
* bird read <tweet-id-or-url>
|
||||
*/
|
||||
import { createProgram, KNOWN_COMMANDS } from './cli/program.js';
|
||||
import { createCliContext } from './cli/shared.js';
|
||||
import { resolveCliInvocation } from './lib/cli-args.js';
|
||||
const rawArgs = process.argv.slice(2);
|
||||
const normalizedArgs = rawArgs[0] === '--' ? rawArgs.slice(1) : rawArgs;
|
||||
const ctx = createCliContext(normalizedArgs);
|
||||
const program = createProgram(ctx);
|
||||
const { argv, showHelp } = resolveCliInvocation(normalizedArgs, KNOWN_COMMANDS);
|
||||
if (showHelp) {
|
||||
program.outputHelp();
|
||||
process.exit(0);
|
||||
}
|
||||
if (argv) {
|
||||
program.parse(argv);
|
||||
}
|
||||
else {
|
||||
program.parse(['node', 'bird', ...normalizedArgs]);
|
||||
}
|
||||
//# sourceMappingURL=cli.js.map
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,OAAO,GAAa,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChD,MAAM,cAAc,GAAa,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAElF,MAAM,GAAG,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;AAE7C,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAEnC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,oBAAoB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;AAEhF,IAAI,QAAQ,EAAE,CAAC;IACb,OAAO,CAAC,UAAU,EAAE,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,IAAI,EAAE,CAAC;IACT,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
export type PaginationCmdOpts = {
|
||||
all?: boolean;
|
||||
maxPages?: string;
|
||||
cursor?: string;
|
||||
delay?: string;
|
||||
};
|
||||
export declare function parsePositiveIntFlag(raw: string | undefined, flagName: string): {
|
||||
ok: true;
|
||||
value: number | undefined;
|
||||
} | {
|
||||
ok: false;
|
||||
error: string;
|
||||
};
|
||||
export declare function parseNonNegativeIntFlag(raw: string | undefined, flagName: string, defaultValue: number): {
|
||||
ok: true;
|
||||
value: number;
|
||||
} | {
|
||||
ok: false;
|
||||
error: string;
|
||||
};
|
||||
export declare function parsePaginationFlags(cmdOpts: PaginationCmdOpts, opts?: {
|
||||
maxPagesImpliesPagination?: boolean;
|
||||
defaultDelayMs?: number;
|
||||
includeDelay?: boolean;
|
||||
}): {
|
||||
ok: true;
|
||||
usePagination: boolean;
|
||||
maxPages?: number;
|
||||
cursor?: string;
|
||||
pageDelayMs?: number;
|
||||
} | {
|
||||
ok: false;
|
||||
error: string;
|
||||
};
|
||||
//# sourceMappingURL=pagination.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/cli/pagination.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,QAAQ,EAAE,MAAM,GACf;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CASxE;AAED,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAM5D;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,iBAAiB,EAC1B,IAAI,CAAC,EAAE;IACL,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,GAEC;IACE,EAAE,EAAE,IAAI,CAAC;IACT,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CA8B/B"}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
export function parsePositiveIntFlag(raw, flagName) {
|
||||
if (raw === undefined) {
|
||||
return { ok: true, value: undefined };
|
||||
}
|
||||
const value = Number.parseInt(raw, 10);
|
||||
if (!Number.isFinite(value) || value <= 0) {
|
||||
return { ok: false, error: `Invalid ${flagName}. Expected a positive integer.` };
|
||||
}
|
||||
return { ok: true, value };
|
||||
}
|
||||
export function parseNonNegativeIntFlag(raw, flagName, defaultValue) {
|
||||
const value = Number.parseInt(raw ?? String(defaultValue), 10);
|
||||
if (!Number.isFinite(value) || value < 0) {
|
||||
return { ok: false, error: `Invalid ${flagName}. Expected a non-negative integer.` };
|
||||
}
|
||||
return { ok: true, value };
|
||||
}
|
||||
export function parsePaginationFlags(cmdOpts, opts) {
|
||||
const maxPagesImpliesPagination = opts?.maxPagesImpliesPagination ?? false;
|
||||
const includeDelay = opts?.includeDelay ?? false;
|
||||
const defaultDelayMs = opts?.defaultDelayMs ?? 1000;
|
||||
const maxPages = parsePositiveIntFlag(cmdOpts.maxPages, '--max-pages');
|
||||
if (!maxPages.ok) {
|
||||
return maxPages;
|
||||
}
|
||||
const usePagination = Boolean(cmdOpts.all || cmdOpts.cursor || (maxPagesImpliesPagination && maxPages.value !== undefined));
|
||||
let pageDelayMs;
|
||||
if (includeDelay) {
|
||||
const delay = parseNonNegativeIntFlag(cmdOpts.delay, '--delay', defaultDelayMs);
|
||||
if (!delay.ok) {
|
||||
return delay;
|
||||
}
|
||||
pageDelayMs = delay.value;
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
usePagination,
|
||||
maxPages: maxPages.value,
|
||||
cursor: cmdOpts.cursor,
|
||||
pageDelayMs,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=pagination.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/cli/pagination.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,oBAAoB,CAClC,GAAuB,EACvB,QAAgB;IAEhB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACxC,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC1C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,QAAQ,gCAAgC,EAAE,CAAC;IACnF,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,GAAuB,EACvB,QAAgB,EAChB,YAAoB;IAEpB,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACzC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,QAAQ,oCAAoC,EAAE,CAAC;IACvF,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,OAA0B,EAC1B,IAIC;IAUD,MAAM,yBAAyB,GAAG,IAAI,EAAE,yBAAyB,IAAI,KAAK,CAAC;IAC3E,MAAM,YAAY,GAAG,IAAI,EAAE,YAAY,IAAI,KAAK,CAAC;IACjD,MAAM,cAAc,GAAG,IAAI,EAAE,cAAc,IAAI,IAAI,CAAC;IAEpD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACvE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,aAAa,GAAG,OAAO,CAC3B,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,yBAAyB,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,CAAC,CAC7F,CAAC;IAEF,IAAI,WAA+B,CAAC;IACpC,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,KAAK,GAAG,uBAAuB,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;QAChF,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;YACd,OAAO,KAAK,CAAC;QACf,CAAC;QACD,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,EAAE,EAAE,IAAI;QACR,aAAa;QACb,QAAQ,EAAE,QAAQ,CAAC,KAAK;QACxB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
||||
Vendored
-5
@@ -1,5 +0,0 @@
|
||||
import { Command } from 'commander';
|
||||
import { type CliContext } from './shared.js';
|
||||
export declare const KNOWN_COMMANDS: Set<string>;
|
||||
export declare function createProgram(ctx: CliContext): Command;
|
||||
//# sourceMappingURL=program.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/cli/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBpC,OAAO,EAAE,KAAK,UAAU,EAAuB,MAAM,aAAa,CAAC;AAEnE,eAAO,MAAM,cAAc,aAyBzB,CAAC;AAEH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CA+GtD"}
|
||||
Vendored
-113
@@ -1,113 +0,0 @@
|
||||
import { Command } from 'commander';
|
||||
import { registerBookmarksCommand } from '../commands/bookmarks.js';
|
||||
import { registerCheckCommand } from '../commands/check.js';
|
||||
import { registerFollowCommands } from '../commands/follow.js';
|
||||
import { registerHelpCommand } from '../commands/help.js';
|
||||
import { registerHomeCommand } from '../commands/home.js';
|
||||
import { registerListsCommand } from '../commands/lists.js';
|
||||
import { registerNewsCommand } from '../commands/news.js';
|
||||
import { registerPostCommands } from '../commands/post.js';
|
||||
import { registerQueryIdsCommand } from '../commands/query-ids.js';
|
||||
import { registerReadCommands } from '../commands/read.js';
|
||||
import { registerSearchCommands } from '../commands/search.js';
|
||||
import { registerUnbookmarkCommand } from '../commands/unbookmark.js';
|
||||
import { registerUserTweetsCommand } from '../commands/user-tweets.js';
|
||||
import { registerUserCommands } from '../commands/users.js';
|
||||
import { getCliVersion } from '../lib/version.js';
|
||||
import { collectCookieSource } from './shared.js';
|
||||
export const KNOWN_COMMANDS = new Set([
|
||||
'tweet',
|
||||
'reply',
|
||||
'query-ids',
|
||||
'read',
|
||||
'replies',
|
||||
'thread',
|
||||
'search',
|
||||
'mentions',
|
||||
'bookmarks',
|
||||
'unbookmark',
|
||||
'follow',
|
||||
'unfollow',
|
||||
'following',
|
||||
'followers',
|
||||
'likes',
|
||||
'lists',
|
||||
'list-timeline',
|
||||
'home',
|
||||
'user-tweets',
|
||||
'news',
|
||||
'trending',
|
||||
'help',
|
||||
'whoami',
|
||||
'check',
|
||||
]);
|
||||
export function createProgram(ctx) {
|
||||
const program = new Command();
|
||||
program.configureHelp({
|
||||
showGlobalOptions: true,
|
||||
styleTitle: (t) => ctx.colors.section(t),
|
||||
styleUsage: (t) => ctx.colors.description(t),
|
||||
styleCommandText: (t) => ctx.colors.command(t),
|
||||
styleCommandDescription: (t) => ctx.colors.muted(t),
|
||||
styleOptionTerm: (t) => ctx.colors.option(t),
|
||||
styleOptionText: (t) => ctx.colors.option(t),
|
||||
styleOptionDescription: (t) => ctx.colors.muted(t),
|
||||
styleArgumentTerm: (t) => ctx.colors.argument(t),
|
||||
styleArgumentText: (t) => ctx.colors.argument(t),
|
||||
styleArgumentDescription: (t) => ctx.colors.muted(t),
|
||||
styleSubcommandTerm: (t) => ctx.colors.command(t),
|
||||
styleSubcommandText: (t) => ctx.colors.command(t),
|
||||
styleSubcommandDescription: (t) => ctx.colors.muted(t),
|
||||
styleDescriptionText: (t) => ctx.colors.muted(t),
|
||||
});
|
||||
const collect = (value, previous = []) => {
|
||||
previous.push(value);
|
||||
return previous;
|
||||
};
|
||||
program.addHelpText('beforeAll', () => `${ctx.colors.banner('bird')} ${ctx.colors.muted(getCliVersion())} ${ctx.colors.subtitle('— fast X CLI for tweeting, replying, and reading')}`);
|
||||
program.name('bird').description('Post tweets and replies via Twitter/X GraphQL API').version(getCliVersion());
|
||||
const formatExample = (command, description) => `${ctx.colors.command(` ${command}`)}\n${ctx.colors.muted(` ${description}`)}`;
|
||||
program.addHelpText('afterAll', () => `\n${ctx.colors.section('Examples')}\n${[
|
||||
formatExample('bird whoami', 'Show the logged-in account via GraphQL cookies'),
|
||||
formatExample('bird --firefox-profile default-release whoami', 'Use Firefox profile cookies'),
|
||||
formatExample('bird tweet "hello from bird"', 'Send a tweet'),
|
||||
formatExample('bird 1234567890123456789 --json', 'Read a tweet (ID or URL shorthand for `read`) and print JSON'),
|
||||
].join('\n\n')}\n\n${ctx.colors.section('Shortcuts')}\n${[
|
||||
formatExample('bird <tweet-id-or-url> [--json]', 'Shorthand for `bird read <tweet-id-or-url>`'),
|
||||
].join('\n\n')}\n\n${ctx.colors.section('JSON Output')}\n${ctx.colors.muted(` Add ${ctx.colors.option('--json')} to: read, replies, thread, search, mentions, bookmarks, likes, following, followers, about, lists, list-timeline, user-tweets, query-ids`)}\n${ctx.colors.muted(` Add ${ctx.colors.option('--json-full')} to include raw API response in ${ctx.colors.argument('_raw')} field (tweet commands only)`)}\n${ctx.colors.muted(` (Run ${ctx.colors.command('bird <command> --help')} to see per-command flags.)`)}`);
|
||||
program.addHelpText('afterAll', () => `\n\n${ctx.colors.section('Config')}\n${ctx.colors.muted(` Reads ${ctx.colors.argument('~/.config/bird/config.json5')} and ${ctx.colors.argument('./.birdrc.json5')} (JSON5)`)}\n${ctx.colors.muted(` Supports: chromeProfile, chromeProfileDir, firefoxProfile, cookieSource, cookieTimeoutMs, timeoutMs, quoteDepth`)}\n\n${ctx.colors.section('Env')}\n${ctx.colors.muted(` ${ctx.colors.option('NO_COLOR')}, ${ctx.colors.option('BIRD_TIMEOUT_MS')}, ${ctx.colors.option('BIRD_COOKIE_TIMEOUT_MS')}, ${ctx.colors.option('BIRD_QUOTE_DEPTH')}`)}`);
|
||||
program
|
||||
.option('--auth-token <token>', 'Twitter auth_token cookie')
|
||||
.option('--ct0 <token>', 'Twitter ct0 cookie')
|
||||
.option('--chrome-profile <name>', 'Chrome profile name for cookie extraction', ctx.config.chromeProfile)
|
||||
.option('--chrome-profile-dir <path>', 'Chrome/Chromium profile directory or cookie DB path for cookie extraction', ctx.config.chromeProfileDir)
|
||||
.option('--firefox-profile <name>', 'Firefox profile name for cookie extraction', ctx.config.firefoxProfile)
|
||||
.option('--cookie-timeout <ms>', 'Cookie extraction timeout in milliseconds (keychain/OS helpers)')
|
||||
.option('--cookie-source <source>', 'Cookie source for browser cookie extraction (repeatable)', collectCookieSource)
|
||||
.option('--media <path>', 'Attach media file (repeatable, up to 4 images or 1 video)', collect)
|
||||
.option('--alt <text>', 'Alt text for the corresponding --media (repeatable)', collect)
|
||||
.option('--timeout <ms>', 'Request timeout in milliseconds')
|
||||
.option('--quote-depth <depth>', 'Max quoted tweet depth (default: 1; 0 disables)')
|
||||
.option('--plain', 'Plain output (stable, no emoji, no color)')
|
||||
.option('--no-emoji', 'Disable emoji output')
|
||||
.option('--no-color', 'Disable ANSI colors (or set NO_COLOR)');
|
||||
program.hook('preAction', (_thisCommand, actionCommand) => {
|
||||
ctx.applyOutputFromCommand(actionCommand);
|
||||
});
|
||||
registerHelpCommand(program, ctx);
|
||||
registerQueryIdsCommand(program, ctx);
|
||||
registerPostCommands(program, ctx);
|
||||
registerReadCommands(program, ctx);
|
||||
registerSearchCommands(program, ctx);
|
||||
registerBookmarksCommand(program, ctx);
|
||||
registerUnbookmarkCommand(program, ctx);
|
||||
registerFollowCommands(program, ctx);
|
||||
registerListsCommand(program, ctx);
|
||||
registerHomeCommand(program, ctx);
|
||||
registerUserCommands(program, ctx);
|
||||
registerUserTweetsCommand(program, ctx);
|
||||
registerNewsCommand(program, ctx);
|
||||
registerCheckCommand(program, ctx);
|
||||
return program;
|
||||
}
|
||||
//# sourceMappingURL=program.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
Vendored
-77
@@ -1,77 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import { type CookieSource, resolveCredentials } from '../lib/cookies.js';
|
||||
import { labelPrefix, type OutputConfig, statusPrefix } from '../lib/output.js';
|
||||
import type { TweetData } from '../lib/twitter-client.js';
|
||||
export type BirdConfig = {
|
||||
chromeProfile?: string;
|
||||
chromeProfileDir?: string;
|
||||
firefoxProfile?: string;
|
||||
cookieSource?: CookieSource | CookieSource[];
|
||||
cookieTimeoutMs?: number;
|
||||
timeoutMs?: number;
|
||||
quoteDepth?: number;
|
||||
};
|
||||
export type MediaSpec = {
|
||||
path: string;
|
||||
alt?: string;
|
||||
mime: string;
|
||||
buffer: Buffer;
|
||||
};
|
||||
export type CliContext = {
|
||||
isTty: boolean;
|
||||
getOutput: () => OutputConfig;
|
||||
colors: {
|
||||
banner: (t: string) => string;
|
||||
subtitle: (t: string) => string;
|
||||
section: (t: string) => string;
|
||||
bullet: (t: string) => string;
|
||||
command: (t: string) => string;
|
||||
option: (t: string) => string;
|
||||
argument: (t: string) => string;
|
||||
description: (t: string) => string;
|
||||
muted: (t: string) => string;
|
||||
accent: (t: string) => string;
|
||||
};
|
||||
p: (kind: Parameters<typeof statusPrefix>[0]) => string;
|
||||
l: (kind: Parameters<typeof labelPrefix>[0]) => string;
|
||||
config: BirdConfig;
|
||||
applyOutputFromCommand: (command: Command) => void;
|
||||
resolveTimeoutFromOptions: (options: {
|
||||
timeout?: string | number;
|
||||
}) => number | undefined;
|
||||
resolveQuoteDepthFromOptions: (options: {
|
||||
quoteDepth?: string | number;
|
||||
}) => number | undefined;
|
||||
resolveCredentialsFromOptions: (opts: CredentialsOptions) => ReturnType<typeof resolveCredentials>;
|
||||
loadMedia: (opts: {
|
||||
media: string[];
|
||||
alts: string[];
|
||||
}) => MediaSpec[];
|
||||
printTweets: (tweets: TweetData[], opts?: {
|
||||
json?: boolean;
|
||||
emptyMessage?: string;
|
||||
showSeparator?: boolean;
|
||||
}) => void;
|
||||
printTweetsResult: (result: {
|
||||
tweets?: TweetData[];
|
||||
nextCursor?: string;
|
||||
}, opts: {
|
||||
json: boolean;
|
||||
usePagination: boolean;
|
||||
emptyMessage: string;
|
||||
}) => void;
|
||||
extractTweetId: (tweetIdOrUrl: string) => string;
|
||||
};
|
||||
export declare const collectCookieSource: (value: string, previous?: CookieSource[]) => CookieSource[];
|
||||
type CredentialsOptions = {
|
||||
authToken?: string;
|
||||
ct0?: string;
|
||||
chromeProfile?: string;
|
||||
chromeProfileDir?: string;
|
||||
firefoxProfile?: string;
|
||||
cookieSource?: CookieSource[];
|
||||
cookieTimeout?: string | number;
|
||||
};
|
||||
export declare function createCliContext(normalizedArgs: string[], env?: NodeJS.ProcessEnv): CliContext;
|
||||
export {};
|
||||
//# sourceMappingURL=shared.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/cli/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,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ACjB,MAAM,EAAE;QACN,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,EACD,IAAI,EAAE;QACJ,IAAI,EAAE,OAAO,CAAC;QACd,aAAa,EAAE,OAAO,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;KACtB,KACE,IAAI,CAAC;IACV,cAAc,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;CAClD,CAAC;AAYF,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,EAAE,WAAU,YAAY,EAAO,KAAG,YAAY,EAG9F,CAAC;AA4FF,KAAK,kBAAkB,GAAG;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,YAAY,EAAE,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,UAAU,CA2P3G"}
|
||||
Vendored
-327
@@ -1,327 +0,0 @@
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import JSON5 from 'json5';
|
||||
import kleur from 'kleur';
|
||||
import { resolveCredentials } from '../lib/cookies.js';
|
||||
import { extractTweetId } from '../lib/extract-tweet-id.js';
|
||||
import { hyperlink, labelPrefix, resolveOutputConfigFromArgv, resolveOutputConfigFromCommander, statusPrefix, } from '../lib/output.js';
|
||||
const COOKIE_SOURCES = ['safari', 'chrome', 'firefox'];
|
||||
function parseCookieSource(value) {
|
||||
const normalized = value.trim().toLowerCase();
|
||||
if (normalized === 'safari' || normalized === 'chrome' || normalized === 'firefox') {
|
||||
return normalized;
|
||||
}
|
||||
throw new Error(`Invalid --cookie-source "${value}". Allowed: safari, chrome, firefox.`);
|
||||
}
|
||||
export const collectCookieSource = (value, previous = []) => {
|
||||
previous.push(parseCookieSource(value));
|
||||
return previous;
|
||||
};
|
||||
function resolveCookieSourceOrder(input) {
|
||||
if (typeof input === 'string') {
|
||||
return [parseCookieSource(input)];
|
||||
}
|
||||
if (Array.isArray(input)) {
|
||||
const result = [];
|
||||
for (const entry of input) {
|
||||
if (typeof entry !== 'string') {
|
||||
continue;
|
||||
}
|
||||
result.push(parseCookieSource(entry));
|
||||
}
|
||||
return result.length > 0 ? result : undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
function resolveTimeoutMs(...values) {
|
||||
for (const value of values) {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
continue;
|
||||
}
|
||||
const parsed = typeof value === 'number' ? value : Number(value);
|
||||
if (Number.isFinite(parsed) && parsed > 0) {
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
function resolveQuoteDepth(...values) {
|
||||
for (const value of values) {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
continue;
|
||||
}
|
||||
const parsed = typeof value === 'number' ? value : Number.parseInt(value, 10);
|
||||
if (Number.isFinite(parsed) && parsed >= 0) {
|
||||
return Math.floor(parsed);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
function detectMime(path) {
|
||||
const ext = path.toLowerCase();
|
||||
if (ext.endsWith('.jpg') || ext.endsWith('.jpeg')) {
|
||||
return 'image/jpeg';
|
||||
}
|
||||
if (ext.endsWith('.png')) {
|
||||
return 'image/png';
|
||||
}
|
||||
if (ext.endsWith('.webp')) {
|
||||
return 'image/webp';
|
||||
}
|
||||
if (ext.endsWith('.gif')) {
|
||||
return 'image/gif';
|
||||
}
|
||||
if (ext.endsWith('.mp4') || ext.endsWith('.m4v')) {
|
||||
return 'video/mp4';
|
||||
}
|
||||
if (ext.endsWith('.mov')) {
|
||||
return 'video/quicktime';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function readConfigFile(path, warn) {
|
||||
if (!existsSync(path)) {
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
const raw = readFileSync(path, 'utf8');
|
||||
const parsed = JSON5.parse(raw);
|
||||
return parsed ?? {};
|
||||
}
|
||||
catch (error) {
|
||||
warn(`Failed to parse config at ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
function loadConfig(warn) {
|
||||
const globalPath = join(homedir(), '.config', 'bird', 'config.json5');
|
||||
const localPath = join(process.cwd(), '.birdrc.json5');
|
||||
return {
|
||||
...readConfigFile(globalPath, warn),
|
||||
...readConfigFile(localPath, warn),
|
||||
};
|
||||
}
|
||||
export function createCliContext(normalizedArgs, env = process.env) {
|
||||
const isTty = process.stdout.isTTY;
|
||||
let output = resolveOutputConfigFromArgv(normalizedArgs, env, isTty);
|
||||
kleur.enabled = output.color;
|
||||
const wrap = (styler) => (text) => isTty ? styler(text) : text;
|
||||
const colors = {
|
||||
banner: wrap((t) => kleur.bold().blue(t)),
|
||||
subtitle: wrap((t) => kleur.dim(t)),
|
||||
section: wrap((t) => kleur.bold().white(t)),
|
||||
bullet: wrap((t) => kleur.blue(t)),
|
||||
command: wrap((t) => kleur.bold().cyan(t)),
|
||||
option: wrap((t) => kleur.cyan(t)),
|
||||
argument: wrap((t) => kleur.magenta(t)),
|
||||
description: wrap((t) => kleur.white(t)),
|
||||
muted: wrap((t) => kleur.gray(t)),
|
||||
accent: wrap((t) => kleur.green(t)),
|
||||
};
|
||||
const p = (kind) => {
|
||||
const prefix = statusPrefix(kind, output);
|
||||
if (output.plain || !output.color) {
|
||||
return prefix;
|
||||
}
|
||||
if (kind === 'ok') {
|
||||
return kleur.green(prefix);
|
||||
}
|
||||
if (kind === 'warn') {
|
||||
return kleur.yellow(prefix);
|
||||
}
|
||||
if (kind === 'err') {
|
||||
return kleur.red(prefix);
|
||||
}
|
||||
if (kind === 'info') {
|
||||
return kleur.cyan(prefix);
|
||||
}
|
||||
return kleur.gray(prefix);
|
||||
};
|
||||
const l = (kind) => {
|
||||
const prefix = labelPrefix(kind, output);
|
||||
if (output.plain || !output.color) {
|
||||
return prefix;
|
||||
}
|
||||
if (kind === 'url') {
|
||||
return kleur.cyan(prefix);
|
||||
}
|
||||
if (kind === 'date') {
|
||||
return kleur.magenta(prefix);
|
||||
}
|
||||
if (kind === 'source') {
|
||||
return kleur.gray(prefix);
|
||||
}
|
||||
if (kind === 'engine') {
|
||||
return kleur.blue(prefix);
|
||||
}
|
||||
if (kind === 'credentials') {
|
||||
return kleur.yellow(prefix);
|
||||
}
|
||||
if (kind === 'user') {
|
||||
return kleur.cyan(prefix);
|
||||
}
|
||||
if (kind === 'userId') {
|
||||
return kleur.magenta(prefix);
|
||||
}
|
||||
if (kind === 'email') {
|
||||
return kleur.green(prefix);
|
||||
}
|
||||
return kleur.gray(prefix);
|
||||
};
|
||||
const config = loadConfig((message) => {
|
||||
console.error(colors.muted(`${p('warn')}${message}`));
|
||||
});
|
||||
function applyOutputFromCommand(command) {
|
||||
const opts = command.optsWithGlobals();
|
||||
output = resolveOutputConfigFromCommander(opts, env, isTty);
|
||||
kleur.enabled = output.color;
|
||||
}
|
||||
function resolveTimeoutFromOptions(options) {
|
||||
return resolveTimeoutMs(options.timeout, config.timeoutMs, env.BIRD_TIMEOUT_MS);
|
||||
}
|
||||
function resolveCookieTimeoutFromOptions(options) {
|
||||
return resolveTimeoutMs(options.cookieTimeout, config.cookieTimeoutMs, env.BIRD_COOKIE_TIMEOUT_MS);
|
||||
}
|
||||
function resolveQuoteDepthFromOptions(options) {
|
||||
return resolveQuoteDepth(options.quoteDepth, config.quoteDepth, env.BIRD_QUOTE_DEPTH);
|
||||
}
|
||||
function resolveCredentialsFromOptions(opts) {
|
||||
const cookieSource = opts.cookieSource?.length
|
||||
? opts.cookieSource
|
||||
: (resolveCookieSourceOrder(config.cookieSource) ?? COOKIE_SOURCES);
|
||||
const chromeProfile = opts.chromeProfileDir || opts.chromeProfile || config.chromeProfileDir || config.chromeProfile;
|
||||
return resolveCredentials({
|
||||
authToken: opts.authToken,
|
||||
ct0: opts.ct0,
|
||||
cookieSource,
|
||||
chromeProfile,
|
||||
firefoxProfile: opts.firefoxProfile || config.firefoxProfile,
|
||||
cookieTimeoutMs: resolveCookieTimeoutFromOptions(opts),
|
||||
});
|
||||
}
|
||||
function loadMedia(opts) {
|
||||
if (opts.media.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const specs = [];
|
||||
for (const [index, path] of opts.media.entries()) {
|
||||
const mime = detectMime(path);
|
||||
if (!mime) {
|
||||
throw new Error(`Unsupported media type for ${path}. Supported: jpg, jpeg, png, webp, gif, mp4, mov`);
|
||||
}
|
||||
const buffer = readFileSync(path);
|
||||
specs.push({ path, mime, buffer, alt: opts.alts[index] });
|
||||
}
|
||||
const videoCount = specs.filter((m) => m.mime.startsWith('video/')).length;
|
||||
if (videoCount > 1) {
|
||||
throw new Error('Only one video can be attached');
|
||||
}
|
||||
if (videoCount === 1 && specs.length > 1) {
|
||||
throw new Error('Video cannot be combined with other media');
|
||||
}
|
||||
if (specs.length > 4) {
|
||||
throw new Error('Maximum 4 media attachments');
|
||||
}
|
||||
return specs;
|
||||
}
|
||||
function printTweets(tweets, opts = {}) {
|
||||
if (opts.json) {
|
||||
console.log(JSON.stringify(tweets, null, 2));
|
||||
return;
|
||||
}
|
||||
if (tweets.length === 0) {
|
||||
console.log(opts.emptyMessage ?? 'No tweets found.');
|
||||
return;
|
||||
}
|
||||
const useEmoji = output.emoji && !output.plain;
|
||||
const articleLabel = useEmoji ? '📰' : 'Article:';
|
||||
const mediaLabel = (type) => {
|
||||
if (useEmoji) {
|
||||
return type === 'video' ? '🎬' : type === 'animated_gif' ? '🔄' : '🖼️';
|
||||
}
|
||||
return type === 'video' ? 'VIDEO:' : type === 'animated_gif' ? 'GIF:' : 'PHOTO:';
|
||||
};
|
||||
const quotePrefix = useEmoji ? { top: '┌─', mid: '│ ', bot: '└─' } : { top: '> ', mid: '> ', bot: '> ' };
|
||||
for (const tweet of tweets) {
|
||||
console.log(`\n@${tweet.author.username} (${tweet.author.name}):`);
|
||||
// Display tweet text, with article indicator if present
|
||||
if (tweet.article) {
|
||||
// Full body mode: text starts with article title (from extractArticleText)
|
||||
// Preview mode: text is short tweet intro that doesn't start with title
|
||||
const hasFullBody = tweet.text.startsWith(tweet.article.title);
|
||||
if (hasFullBody) {
|
||||
console.log(`${articleLabel} ${tweet.text}`);
|
||||
}
|
||||
else {
|
||||
console.log(`${articleLabel} ${tweet.article.title}`);
|
||||
if (tweet.article.previewText) {
|
||||
console.log(` ${tweet.article.previewText}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log(tweet.text);
|
||||
}
|
||||
// Display media attachments
|
||||
if (tweet.media && tweet.media.length > 0) {
|
||||
for (const m of tweet.media) {
|
||||
console.log(`${mediaLabel(m.type)} ${m.url}`);
|
||||
}
|
||||
}
|
||||
// Display quoted tweet
|
||||
if (tweet.quotedTweet) {
|
||||
console.log(`${quotePrefix.top} QT @${tweet.quotedTweet.author.username}:`);
|
||||
const qtText = tweet.quotedTweet.article
|
||||
? `${articleLabel} ${tweet.quotedTweet.article.title}`
|
||||
: tweet.quotedTweet.text;
|
||||
// Indent and truncate quoted tweet text
|
||||
const maxLen = 280;
|
||||
const truncated = qtText.length > maxLen ? `${qtText.slice(0, maxLen)}...` : qtText;
|
||||
for (const line of truncated.split('\n').slice(0, 4)) {
|
||||
console.log(`${quotePrefix.mid}${line}`);
|
||||
}
|
||||
// Display quoted tweet media
|
||||
if (tweet.quotedTweet.media && tweet.quotedTweet.media.length > 0) {
|
||||
for (const m of tweet.quotedTweet.media) {
|
||||
console.log(`${quotePrefix.mid}${mediaLabel(m.type)} ${m.url}`);
|
||||
}
|
||||
}
|
||||
console.log(`${quotePrefix.bot} https://x.com/${tweet.quotedTweet.author.username}/status/${tweet.quotedTweet.id}`);
|
||||
}
|
||||
if (tweet.createdAt) {
|
||||
console.log(`${l('date')}${tweet.createdAt}`);
|
||||
}
|
||||
const tweetUrl = `https://x.com/${tweet.author.username}/status/${tweet.id}`;
|
||||
console.log(`${l('url')}${hyperlink(tweetUrl, tweetUrl, output)}`);
|
||||
if (opts.showSeparator ?? true) {
|
||||
console.log('─'.repeat(50));
|
||||
}
|
||||
}
|
||||
}
|
||||
function printTweetsResult(result, opts) {
|
||||
const tweets = result.tweets ?? [];
|
||||
if (opts.json && opts.usePagination) {
|
||||
console.log(JSON.stringify({ tweets, nextCursor: result.nextCursor ?? null }, null, 2));
|
||||
return;
|
||||
}
|
||||
printTweets(tweets, { json: opts.json, emptyMessage: opts.emptyMessage });
|
||||
}
|
||||
return {
|
||||
isTty,
|
||||
getOutput: () => output,
|
||||
colors,
|
||||
p,
|
||||
l,
|
||||
config,
|
||||
applyOutputFromCommand,
|
||||
resolveTimeoutFromOptions,
|
||||
resolveQuoteDepthFromOptions,
|
||||
resolveCredentialsFromOptions,
|
||||
loadMedia,
|
||||
printTweets,
|
||||
printTweetsResult,
|
||||
extractTweetId,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=shared.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerBookmarksCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=bookmarks.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"bookmarks.d.ts","sourceRoot":"","sources":["../../src/commands/bookmarks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAsOhF"}
|
||||
-189
@@ -1,189 +0,0 @@
|
||||
import { parsePaginationFlags } from '../cli/pagination.js';
|
||||
import { extractBookmarkFolderId } from '../lib/extract-bookmark-folder-id.js';
|
||||
import { addThreadMetadata, filterAuthorChain, filterAuthorOnly, filterFullChain } from '../lib/thread-filters.js';
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
export function registerBookmarksCommand(program, ctx) {
|
||||
program
|
||||
.command('bookmarks')
|
||||
.description('Get your bookmarked tweets')
|
||||
.option('-n, --count <number>', 'Number of bookmarks to fetch', '20')
|
||||
.option('--folder-id <id>', 'Bookmark folder (collection) id')
|
||||
.option('--all', 'Fetch all bookmarks (paged)')
|
||||
.option('--max-pages <number>', 'Stop after N pages when using --all')
|
||||
.option('--cursor <string>', 'Resume pagination from a cursor')
|
||||
.option('--expand-root-only', 'Only expand threads when bookmarked tweet is root')
|
||||
.option('--author-chain', 'Only include author self-reply chains connected to the bookmark')
|
||||
.option('--author-only', 'Include all tweets from bookmarked tweet author in thread')
|
||||
.option('--full-chain-only', 'Save entire reply chain connected to the bookmarked tweet')
|
||||
.option('--include-ancestor-branches', 'Include sibling branches for ancestors when using --full-chain-only')
|
||||
.option('--include-parent', 'Include direct parent tweet for non-root bookmarks')
|
||||
.option('--thread-meta', 'Add metadata fields (isThread, threadPosition, etc.)')
|
||||
.option('--sort-chronological', 'Sort output globally oldest -> newest')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
||||
const pagination = parsePaginationFlags(cmdOpts);
|
||||
if (!pagination.ok) {
|
||||
console.error(`${ctx.p('err')}${pagination.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const maxPages = pagination.maxPages;
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const usePagination = pagination.usePagination;
|
||||
if (maxPages !== undefined && !usePagination) {
|
||||
console.error(`${ctx.p('err')}--max-pages requires --all or --cursor.`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
|
||||
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs });
|
||||
const folderId = cmdOpts.folderId ? extractBookmarkFolderId(cmdOpts.folderId) : null;
|
||||
if (cmdOpts.folderId && !folderId) {
|
||||
console.error(`${ctx.p('err')}Invalid --folder-id. Expected numeric ID or https://x.com/i/bookmarks/<id>.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const timelineOptions = { includeRaw };
|
||||
const paginationOptions = { includeRaw, maxPages, cursor: pagination.cursor };
|
||||
const result = folderId
|
||||
? usePagination
|
||||
? await client.getAllBookmarkFolderTimeline(folderId, paginationOptions)
|
||||
: await client.getBookmarkFolderTimeline(folderId, count, timelineOptions)
|
||||
: usePagination
|
||||
? await client.getAllBookmarks(paginationOptions)
|
||||
: await client.getBookmarks(count, timelineOptions);
|
||||
if (!result.success) {
|
||||
console.error(`${ctx.p('err')}Failed to fetch bookmarks: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (cmdOpts.authorChain && (cmdOpts.authorOnly || cmdOpts.fullChainOnly)) {
|
||||
console.error(`${ctx.p('warn')}--author-chain already limits to the connected self-reply chain; ` +
|
||||
'other chain filters are redundant.');
|
||||
}
|
||||
if (cmdOpts.includeAncestorBranches && !cmdOpts.fullChainOnly) {
|
||||
console.error(`${ctx.p('warn')}--include-ancestor-branches only applies with --full-chain-only.`);
|
||||
}
|
||||
const bookmarks = result.tweets;
|
||||
if (!bookmarks || bookmarks.length === 0) {
|
||||
const emptyMessage = folderId ? 'No bookmarks found in folder.' : 'No bookmarks found.';
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
ctx.printTweetsResult(result, { json: isJson, usePagination, emptyMessage });
|
||||
return;
|
||||
}
|
||||
const expandedResults = [];
|
||||
const threadCache = new Map();
|
||||
const includeMeta = Boolean(cmdOpts.threadMeta);
|
||||
const includeParent = Boolean(cmdOpts.includeParent);
|
||||
const expandRootOnly = Boolean(cmdOpts.expandRootOnly);
|
||||
const filterAuthorChainFlag = Boolean(cmdOpts.authorChain);
|
||||
const filterAuthorOnlyFlag = Boolean(cmdOpts.authorOnly);
|
||||
const filterFullChainFlag = Boolean(cmdOpts.fullChainOnly);
|
||||
const includeAncestorBranches = Boolean(cmdOpts.includeAncestorBranches) && filterFullChainFlag;
|
||||
const useChronologicalSort = Boolean(cmdOpts.sortChronological);
|
||||
const shouldAttemptExpand = expandRootOnly || filterAuthorChainFlag || filterAuthorOnlyFlag || filterFullChainFlag;
|
||||
const shouldFetchThread = shouldAttemptExpand || includeMeta;
|
||||
const fetchThread = async (tweet) => {
|
||||
const cachedKey = tweet.conversationId ?? tweet.id;
|
||||
const cached = threadCache.get(cachedKey);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const threadResult = await client.getThread(tweet.id, { includeRaw });
|
||||
if (!threadResult.success) {
|
||||
console.error(`${ctx.p('warn')}Failed to expand thread for ${tweet.id}: ${threadResult.error ?? 'Unknown error'}`);
|
||||
return null;
|
||||
}
|
||||
if (!threadResult.tweets) {
|
||||
console.error(`${ctx.p('warn')}No thread tweets returned for ${tweet.id}.`);
|
||||
return null;
|
||||
}
|
||||
const rootKey = threadResult.tweets[0]?.conversationId ?? cachedKey;
|
||||
threadCache.set(rootKey, threadResult.tweets);
|
||||
return threadResult.tweets;
|
||||
};
|
||||
const delayBetweenExpansionsMs = 1000;
|
||||
for (let index = 0; index < bookmarks.length; index += 1) {
|
||||
const bookmark = bookmarks[index];
|
||||
const isRoot = !bookmark.inReplyToStatusId;
|
||||
let threadTweets = null;
|
||||
if (shouldFetchThread) {
|
||||
if (!expandRootOnly || isRoot || includeMeta) {
|
||||
if (index > 0) {
|
||||
await new Promise((resolve) => setTimeout(resolve, delayBetweenExpansionsMs));
|
||||
}
|
||||
threadTweets = await fetchThread(bookmark);
|
||||
}
|
||||
}
|
||||
let outputTweets = [bookmark];
|
||||
if (shouldAttemptExpand) {
|
||||
if (expandRootOnly && !isRoot) {
|
||||
outputTweets = [bookmark];
|
||||
}
|
||||
else if (threadTweets) {
|
||||
if (filterAuthorChainFlag) {
|
||||
outputTweets = filterAuthorChain(threadTweets, bookmark);
|
||||
}
|
||||
else {
|
||||
outputTweets = filterFullChainFlag
|
||||
? filterFullChain(threadTweets, bookmark, { includeAncestorBranches })
|
||||
: threadTweets;
|
||||
if (filterAuthorOnlyFlag) {
|
||||
outputTweets = filterAuthorOnly(outputTweets, bookmark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (includeParent && bookmark.inReplyToStatusId) {
|
||||
const alreadyIncluded = outputTweets.some((tweet) => tweet.id === bookmark.inReplyToStatusId);
|
||||
if (!alreadyIncluded) {
|
||||
const parentFromThread = threadTweets?.find((tweet) => tweet.id === bookmark.inReplyToStatusId);
|
||||
if (parentFromThread) {
|
||||
expandedResults.push(parentFromThread);
|
||||
}
|
||||
else {
|
||||
const parentResult = await client.getTweet(bookmark.inReplyToStatusId, { includeRaw });
|
||||
if (parentResult.success && parentResult.tweet) {
|
||||
expandedResults.push(parentResult.tweet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
expandedResults.push(...outputTweets);
|
||||
}
|
||||
let finalResults = expandedResults;
|
||||
if (includeMeta) {
|
||||
finalResults = expandedResults.map((tweet) => {
|
||||
const cacheKey = tweet.conversationId ?? tweet.id;
|
||||
let conversationTweets = threadCache.get(cacheKey);
|
||||
if (!conversationTweets) {
|
||||
conversationTweets = [tweet];
|
||||
}
|
||||
return addThreadMetadata(tweet, conversationTweets);
|
||||
});
|
||||
}
|
||||
const uniqueTweets = Array.from(new Map(finalResults.map((tweet) => [tweet.id, tweet])).values());
|
||||
if (useChronologicalSort) {
|
||||
uniqueTweets.sort((a, b) => {
|
||||
const aTime = a.createdAt ? Date.parse(a.createdAt) : 0;
|
||||
const bTime = b.createdAt ? Date.parse(b.createdAt) : 0;
|
||||
return aTime - bTime;
|
||||
});
|
||||
}
|
||||
const emptyMessage = folderId ? 'No bookmarks found in folder.' : 'No bookmarks found.';
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
ctx.printTweetsResult({ tweets: uniqueTweets, nextCursor: result.nextCursor }, { json: isJson, usePagination, emptyMessage });
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=bookmarks.js.map
|
||||
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerCheckCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=check.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CA4C5E"}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
export function registerCheckCommand(program, ctx) {
|
||||
program
|
||||
.command('check')
|
||||
.description('Check credential availability')
|
||||
.action(async () => {
|
||||
const opts = program.opts();
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
console.log(`${ctx.p('info')}Credential check`);
|
||||
console.log('─'.repeat(40));
|
||||
if (cookies.authToken) {
|
||||
console.log(`${ctx.p('ok')}auth_token: ${cookies.authToken.slice(0, 10)}...`);
|
||||
}
|
||||
else {
|
||||
console.log(`${ctx.p('err')}auth_token: not found`);
|
||||
}
|
||||
if (cookies.ct0) {
|
||||
console.log(`${ctx.p('ok')}ct0: ${cookies.ct0.slice(0, 10)}...`);
|
||||
}
|
||||
else {
|
||||
console.log(`${ctx.p('err')}ct0: not found`);
|
||||
}
|
||||
if (cookies.source) {
|
||||
console.log(`${ctx.l('source')}${cookies.source}`);
|
||||
}
|
||||
if (warnings.length > 0) {
|
||||
console.log(`\n${ctx.p('warn')}Warnings:`);
|
||||
for (const warning of warnings) {
|
||||
console.log(` - ${warning}`);
|
||||
}
|
||||
}
|
||||
if (cookies.authToken && cookies.ct0) {
|
||||
console.log(`\n${ctx.p('ok')}Ready to tweet!`);
|
||||
}
|
||||
else {
|
||||
console.log(`\n${ctx.p('err')}Missing credentials. Options:`);
|
||||
console.log(' 1. Login to x.com in Safari/Chrome/Firefox');
|
||||
console.log(' 2. Set AUTH_TOKEN and CT0 environment variables');
|
||||
console.log(' 3. Use --auth-token and --ct0 flags');
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=check.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,GAAe;IACpE,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,+BAA+B,CAAC;SAC5C,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,EAAE,OAAO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AM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,OAAO,CAAC,GAAG,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACjD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC9D,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;YAC7D,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;YAClE,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerFollowCommands(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=follow.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"follow.d.ts","sourceRoot":"","sources":["../../src/commands/follow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAmCnD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CA8E9E"}
|
||||
-91
@@ -1,91 +0,0 @@
|
||||
import { normalizeHandle } from '../lib/normalize-handle.js';
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
const ONLY_DIGITS_REGEX = /^\d+$/;
|
||||
async function resolveUserId(client, usernameOrId, ctx) {
|
||||
const raw = usernameOrId.trim();
|
||||
const isNumeric = ONLY_DIGITS_REGEX.test(raw);
|
||||
// Otherwise, treat as username and look up
|
||||
const handle = normalizeHandle(raw);
|
||||
if (handle) {
|
||||
const lookup = await client.getUserIdByUsername(handle);
|
||||
if (lookup.success && lookup.userId) {
|
||||
return { userId: lookup.userId, username: lookup.username };
|
||||
}
|
||||
if (!isNumeric) {
|
||||
console.error(`${ctx.p('err')}Failed to find user @${handle}: ${lookup.error ?? 'Unknown error'}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (isNumeric) {
|
||||
return { userId: raw };
|
||||
}
|
||||
console.error(`${ctx.p('err')}Invalid username: ${usernameOrId}`);
|
||||
return null;
|
||||
}
|
||||
export function registerFollowCommands(program, ctx) {
|
||||
program
|
||||
.command('follow')
|
||||
.description('Follow a user')
|
||||
.argument('<username-or-id>', 'Username (with or without @) or user ID to follow')
|
||||
.action(async (usernameOrId) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs });
|
||||
const resolved = await resolveUserId(client, usernameOrId, ctx);
|
||||
if (!resolved) {
|
||||
process.exit(1);
|
||||
}
|
||||
const { userId, username } = resolved;
|
||||
const displayName = username ? `@${username}` : userId;
|
||||
const result = await client.follow(userId);
|
||||
if (result.success) {
|
||||
const finalName = result.username ? `@${result.username}` : displayName;
|
||||
console.log(`${ctx.p('ok')}Now following ${finalName}`);
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to follow ${displayName}: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('unfollow')
|
||||
.description('Unfollow a user')
|
||||
.argument('<username-or-id>', 'Username (with or without @) or user ID to unfollow')
|
||||
.action(async (usernameOrId) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs });
|
||||
const resolved = await resolveUserId(client, usernameOrId, ctx);
|
||||
if (!resolved) {
|
||||
process.exit(1);
|
||||
}
|
||||
const { userId, username } = resolved;
|
||||
const displayName = username ? `@${username}` : userId;
|
||||
const result = await client.unfollow(userId);
|
||||
if (result.success) {
|
||||
const finalName = result.username ? `@${result.username}` : displayName;
|
||||
console.log(`${ctx.p('ok')}Unfollowed ${finalName}`);
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to unfollow ${displayName}: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=follow.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"follow.js","sourceRoot":"","sources":["../../src/commands/follow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC,KAAK,UAAU,aAAa,CAC1B,MAAqB,EACrB,YAAoB,EACpB,GAAe;IAEf,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,iBAAiB,CAAC,I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AC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC;QACtC,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;QAEvD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;YACxE,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,SAAS,EAAE,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,sBAAsB,WAAW,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YACnF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerHelpCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=help.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/commands/help.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAmB3E"}
|
||||
Vendored
-19
@@ -1,19 +0,0 @@
|
||||
export function registerHelpCommand(program, ctx) {
|
||||
program
|
||||
.command('help [command]')
|
||||
.description('Show help for a command')
|
||||
.action((commandName) => {
|
||||
if (!commandName) {
|
||||
program.outputHelp();
|
||||
return;
|
||||
}
|
||||
const cmd = program.commands.find((c) => c.name() === commandName);
|
||||
if (!cmd) {
|
||||
console.error(`${ctx.p('err')}Unknown command: ${commandName}`);
|
||||
process.exitCode = 2;
|
||||
return;
|
||||
}
|
||||
cmd.outputHelp();
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=help.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/commands/help.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,GAAe;IACnE,OAAO;SACJ,OAAO,CAAC,gBAAgB,CAAC;SACzB,WAAW,CAAC,yBAAyB,CAAC;SACtC,MAAM,CAAC,CAAC,WAAoB,EAAE,EAAE;QAC/B,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,UAAU,EAAE,CAAC;YACrB,OAAO;QACT,CAAC;QAED,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,WAAW,CAAC,CAAC;QACnE,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,WAAW,EAAE,CAAC,CAAC;YAChE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QAED,GAAG,CAAC,UAAU,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACP,CAAC"}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerHomeCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=home.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"home.d.ts","sourceRoot":"","sources":["../../src/commands/home.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CA8C3E"}
|
||||
Vendored
-43
@@ -1,43 +0,0 @@
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
export function registerHomeCommand(program, ctx) {
|
||||
program
|
||||
.command('home')
|
||||
.description('Get your home timeline ("For You" feed)')
|
||||
.option('-n, --count <number>', 'Number of tweets to fetch', '20')
|
||||
.option('--following', 'Get "Following" feed (chronological) instead of "For You"')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!Number.isFinite(count) || count <= 0) {
|
||||
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs });
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const result = cmdOpts.following
|
||||
? await client.getHomeLatestTimeline(count, { includeRaw })
|
||||
: await client.getHomeTimeline(count, { includeRaw });
|
||||
if (result.success) {
|
||||
const feedType = cmdOpts.following ? 'Following' : 'For You';
|
||||
const emptyMessage = `No tweets found in ${feedType} timeline.`;
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
ctx.printTweets(result.tweets, { json: isJson, emptyMessage });
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch home timeline: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=home.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"home.js","sourceRoot":"","sources":["../../src/commands/home.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,GAAe;IACnE,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,yCAAyC,CAAC;SACtD,MAAM,CAAC,sBAAsB,EAAE,2BAA2B,EAAE,IAAI,CAAC;SACjE,MAAM,CAAC,aAAa,EAAE,2DAA2D,CAAC;SAClF,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC;SAClC,MAAM,CAAC,aAAa,EAAE,yDAAyD,CAAC;SAChF,MAAM,CAAC,KAAK,EAAE,OAAoF,EAAE,EAAE;QACrG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,SAAS,GAAG,GAAG,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;QAEzD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,GAAG,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAE5E,KAAK,MAAM,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IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;YACzD,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,kCAAkC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerListsCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=lists.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"lists.d.ts","sourceRoot":"","sources":["../../src/commands/lists.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA4BnD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAyH5E"}
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
// ABOUTME: CLI command for fetching Twitter Lists.
|
||||
// ABOUTME: Supports listing owned lists, memberships, and list timelines.
|
||||
import { parsePaginationFlags } from '../cli/pagination.js';
|
||||
import { extractListId } from '../lib/extract-list-id.js';
|
||||
import { hyperlink } from '../lib/output.js';
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
function printLists(lists, ctx) {
|
||||
if (lists.length === 0) {
|
||||
console.log('No lists found.');
|
||||
return;
|
||||
}
|
||||
for (const list of lists) {
|
||||
const visibility = list.isPrivate ? '[private]' : '[public]';
|
||||
console.log(`${list.name} ${ctx.colors.muted(visibility)}`);
|
||||
if (list.description) {
|
||||
console.log(` ${list.description.slice(0, 100)}${list.description.length > 100 ? '...' : ''}`);
|
||||
}
|
||||
console.log(` ${ctx.p('info')}${list.memberCount?.toLocaleString() ?? 0} members`);
|
||||
if (list.owner) {
|
||||
console.log(` ${ctx.colors.muted(`Owner: @${list.owner.username}`)}`);
|
||||
}
|
||||
const listUrl = `https://x.com/i/lists/${list.id}`;
|
||||
console.log(` ${ctx.colors.accent(hyperlink(listUrl, listUrl, ctx.getOutput()))}`);
|
||||
console.log('──────────────────────────────────────────────────');
|
||||
}
|
||||
}
|
||||
export function registerListsCommand(program, ctx) {
|
||||
program
|
||||
.command('lists')
|
||||
.description('Get your Twitter lists')
|
||||
.option('--member-of', 'Show lists you are a member of (instead of owned lists)')
|
||||
.option('-n, --count <number>', 'Number of lists to fetch', '100')
|
||||
.option('--json', 'Output as JSON')
|
||||
.action(async (cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '100', 10);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs });
|
||||
const result = cmdOpts.memberOf ? await client.getListMemberships(count) : await client.getOwnedLists(count);
|
||||
if (result.success && result.lists) {
|
||||
if (cmdOpts.json) {
|
||||
console.log(JSON.stringify(result.lists, null, 2));
|
||||
}
|
||||
else {
|
||||
const emptyMessage = cmdOpts.memberOf ? 'You are not a member of any lists.' : 'You do not own any lists.';
|
||||
if (result.lists.length === 0) {
|
||||
console.log(emptyMessage);
|
||||
}
|
||||
else {
|
||||
printLists(result.lists, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch lists: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('list-timeline <list-id-or-url>')
|
||||
.description('Get tweets from a list timeline')
|
||||
.option('-n, --count <number>', 'Number of tweets to fetch', '20')
|
||||
.option('--all', 'Fetch all tweets from list (paged). WARNING: your account might get banned using this flag')
|
||||
.option('--max-pages <number>', 'Fetch N pages (implies --all)')
|
||||
.option('--cursor <string>', 'Resume pagination from a cursor')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (listIdOrUrl, cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
||||
const pagination = parsePaginationFlags(cmdOpts, { maxPagesImpliesPagination: true });
|
||||
if (!pagination.ok) {
|
||||
console.error(`${ctx.p('err')}${pagination.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const listId = extractListId(listIdOrUrl);
|
||||
if (!listId) {
|
||||
console.error(`${ctx.p('err')}Invalid list ID or URL. Expected numeric ID or https://x.com/i/lists/<id>.`);
|
||||
process.exit(2);
|
||||
}
|
||||
const usePagination = pagination.usePagination;
|
||||
if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
|
||||
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const timelineOptions = { includeRaw };
|
||||
const paginationOptions = { includeRaw, maxPages: pagination.maxPages, cursor: pagination.cursor };
|
||||
const result = usePagination
|
||||
? await client.getAllListTimeline(listId, paginationOptions)
|
||||
: await client.getListTimeline(listId, count, timelineOptions);
|
||||
if (result.success) {
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
ctx.printTweetsResult(result, {
|
||||
json: isJson,
|
||||
usePagination,
|
||||
emptyMessage: 'No tweets found in this list.',
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch list timeline: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=lists.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerNewsCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=news.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"news.d.ts","sourceRoot":"","sources":["../../src/commands/news.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAmEnD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAuG3E"}
|
||||
Vendored
-131
@@ -1,131 +0,0 @@
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
function formatPostCount(count) {
|
||||
if (count >= 1_000_000) {
|
||||
return `${(count / 1_000_000).toFixed(1)}M`;
|
||||
}
|
||||
if (count >= 1_000) {
|
||||
return `${(count / 1_000).toFixed(1)}K`;
|
||||
}
|
||||
return String(count);
|
||||
}
|
||||
function printNewsItems(items, ctx, opts = {}) {
|
||||
if (opts.json) {
|
||||
console.log(JSON.stringify(items, null, 2));
|
||||
return;
|
||||
}
|
||||
if (items.length === 0) {
|
||||
console.log(opts.emptyMessage ?? 'No news items found.');
|
||||
return;
|
||||
}
|
||||
for (const item of items) {
|
||||
const categoryLabel = item.category ? `[${item.category}]` : '';
|
||||
console.log(`\n${ctx.colors.accent(categoryLabel)} ${ctx.colors.command(item.headline)}`);
|
||||
if (item.description) {
|
||||
console.log(` ${ctx.colors.muted(item.description)}`);
|
||||
}
|
||||
const meta = [];
|
||||
if (item.timeAgo) {
|
||||
meta.push(item.timeAgo);
|
||||
}
|
||||
if (item.postCount) {
|
||||
meta.push(`${formatPostCount(item.postCount)} posts`);
|
||||
}
|
||||
if (meta.length > 0) {
|
||||
console.log(` ${ctx.colors.muted(meta.join(' | '))}`);
|
||||
}
|
||||
if (item.url) {
|
||||
console.log(` ${ctx.l('url')}${item.url}`);
|
||||
}
|
||||
// Print related tweets if available
|
||||
if (item.tweets && item.tweets.length > 0) {
|
||||
console.log(` ${ctx.colors.section('Related tweets:')}`);
|
||||
const tweetLimit = opts.tweetLimit ?? item.tweets.length;
|
||||
for (const tweet of item.tweets.slice(0, tweetLimit)) {
|
||||
console.log(` @${tweet.author.username}: ${tweet.text.slice(0, 100)}${tweet.text.length > 100 ? '...' : ''}`);
|
||||
}
|
||||
}
|
||||
console.log(ctx.colors.muted('─'.repeat(50)));
|
||||
}
|
||||
}
|
||||
export function registerNewsCommand(program, ctx) {
|
||||
program
|
||||
.command('news')
|
||||
.alias('trending')
|
||||
.description('Fetch AI-curated news and trending topics from Explore tabs')
|
||||
.option('-n, --count <number>', 'Number of items to fetch', '10')
|
||||
.option('--ai-only', 'Show only AI-curated news items')
|
||||
.option('--with-tweets', 'Also fetch related tweets for each news item')
|
||||
.option('--tweets-per-item <number>', 'Number of tweets to fetch per news item (default: 5)', '5')
|
||||
.option('--for-you', 'Fetch only from For You tab')
|
||||
.option('--news-only', 'Fetch only from News tab')
|
||||
.option('--sports', 'Fetch only from Sports tab')
|
||||
.option('--entertainment', 'Fetch only from Entertainment tab')
|
||||
.option('--trending-only', 'Fetch only from Trending tab')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '10', 10);
|
||||
const tweetsPerItem = Number.parseInt(cmdOpts.tweetsPerItem || '5', 10);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (Number.isNaN(count) || count < 1) {
|
||||
console.error(`${ctx.p('err')}--count must be a positive number`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (Number.isNaN(tweetsPerItem) || tweetsPerItem < 1) {
|
||||
console.error(`${ctx.p('err')}--tweets-per-item must be a positive number`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
// Determine which tabs to fetch from
|
||||
const tabs = [];
|
||||
if (cmdOpts.forYou) {
|
||||
tabs.push('forYou');
|
||||
}
|
||||
if (cmdOpts.newsOnly) {
|
||||
tabs.push('news');
|
||||
}
|
||||
if (cmdOpts.sports) {
|
||||
tabs.push('sports');
|
||||
}
|
||||
if (cmdOpts.entertainment) {
|
||||
tabs.push('entertainment');
|
||||
}
|
||||
if (cmdOpts.trendingOnly) {
|
||||
tabs.push('trending');
|
||||
}
|
||||
// If no specific tabs selected, use defaults (all tabs except trending)
|
||||
const tabsToFetch = tabs.length > 0 ? tabs : undefined;
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const withTweets = cmdOpts.withTweets ?? false;
|
||||
const aiOnly = cmdOpts.aiOnly ?? false;
|
||||
const result = await client.getNews(count, {
|
||||
includeRaw,
|
||||
withTweets,
|
||||
tweetsPerItem,
|
||||
aiOnly,
|
||||
tabs: tabsToFetch,
|
||||
});
|
||||
if (result.success) {
|
||||
printNewsItems(result.items, ctx, {
|
||||
json: cmdOpts.json || cmdOpts.jsonFull,
|
||||
emptyMessage: 'No news items found.',
|
||||
tweetLimit: withTweets ? tweetsPerItem : undefined,
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch news: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=news.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerPostCommands(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=post.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../src/commands/post.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;AAyB9D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CA4F5E"}
|
||||
Vendored
-101
@@ -1,101 +0,0 @@
|
||||
import { formatTweetUrlLine } from '../lib/output.js';
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
async function uploadMediaOrExit(client, media, ctx) {
|
||||
if (media.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
const uploaded = [];
|
||||
for (const item of media) {
|
||||
const res = await client.uploadMedia({ data: item.buffer, mimeType: item.mime, alt: item.alt });
|
||||
if (!res.success || !res.mediaId) {
|
||||
console.error(`${ctx.p('err')}Media upload failed: ${res.error ?? 'Unknown error'}`);
|
||||
process.exit(1);
|
||||
}
|
||||
uploaded.push(res.mediaId);
|
||||
}
|
||||
return uploaded;
|
||||
}
|
||||
export function registerPostCommands(program, ctx) {
|
||||
program
|
||||
.command('tweet')
|
||||
.description('Post a new tweet')
|
||||
.argument('<text>', 'Tweet text')
|
||||
.action(async (text) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
let media = [];
|
||||
try {
|
||||
media = ctx.loadMedia({ media: opts.media ?? [], alts: opts.alt ?? [] });
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`${ctx.p('err')}${error instanceof Error ? error.message : String(error)}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (cookies.source) {
|
||||
console.error(`${ctx.l('source')}${cookies.source}`);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const mediaIds = await uploadMediaOrExit(client, media, ctx);
|
||||
const result = await client.tweet(text, mediaIds);
|
||||
if (result.success) {
|
||||
console.log(`${ctx.p('ok')}Tweet posted successfully!`);
|
||||
console.log(formatTweetUrlLine(result.tweetId, ctx.getOutput()));
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to post tweet: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('reply')
|
||||
.description('Reply to an existing tweet')
|
||||
.argument('<tweet-id-or-url>', 'Tweet ID or URL to reply to')
|
||||
.argument('<text>', 'Reply text')
|
||||
.action(async (tweetIdOrUrl, text) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
let media = [];
|
||||
try {
|
||||
media = ctx.loadMedia({ media: opts.media ?? [], alts: opts.alt ?? [] });
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`${ctx.p('err')}${error instanceof Error ? error.message : String(error)}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (cookies.source) {
|
||||
console.error(`${ctx.l('source')}${cookies.source}`);
|
||||
}
|
||||
console.error(`${ctx.p('info')}Replying to tweet: ${tweetId}`);
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const mediaIds = await uploadMediaOrExit(client, media, ctx);
|
||||
const result = await client.reply(text, tweetId, mediaIds);
|
||||
if (result.success) {
|
||||
console.log(`${ctx.p('ok')}Reply posted successfully!`);
|
||||
console.log(formatTweetUrlLine(result.tweetId, ctx.getOutput()));
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to post reply: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=post.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"post.js","sourceRoot":"","sources":["../../src/commands/post.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE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MAAM,GAAG,IAAI,aAAa,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;QACrE,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAC7D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAE3D,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;YACxD,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QACnE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,yBAAyB,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerQueryIdsCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=query-ids.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"query-ids.d.ts","sourceRoot":"","sources":["../../src/commands/query-ids.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAqBnD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAgF/E"}
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
import { getFeatureOverridesSnapshot, refreshFeatureOverridesCache, } from '../lib/runtime-features.js';
|
||||
import { runtimeQueryIds } from '../lib/runtime-query-ids.js';
|
||||
function countFeatureOverrides(overrides) {
|
||||
let count = 0;
|
||||
if (overrides.global) {
|
||||
count += Object.keys(overrides.global).length;
|
||||
}
|
||||
if (overrides.sets) {
|
||||
for (const setOverrides of Object.values(overrides.sets)) {
|
||||
count += Object.keys(setOverrides).length;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
export function registerQueryIdsCommand(program, ctx) {
|
||||
program
|
||||
.command('query-ids')
|
||||
.description('Show or refresh cached Twitter GraphQL query IDs')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--fresh', 'Force refresh (downloads X client bundles)', false)
|
||||
.action(async (cmdOpts) => {
|
||||
const operations = [
|
||||
'CreateTweet',
|
||||
'CreateRetweet',
|
||||
'FavoriteTweet',
|
||||
'TweetDetail',
|
||||
'SearchTimeline',
|
||||
'UserArticlesTweets',
|
||||
'Bookmarks',
|
||||
'Following',
|
||||
'Followers',
|
||||
'Likes',
|
||||
];
|
||||
if (cmdOpts.fresh) {
|
||||
console.error(`${ctx.p('info')}Refreshing GraphQL query IDs…`);
|
||||
await runtimeQueryIds.refresh(operations, { force: true });
|
||||
console.error(`${ctx.p('info')}Refreshing feature overrides…`);
|
||||
await refreshFeatureOverridesCache();
|
||||
}
|
||||
const featureSnapshot = getFeatureOverridesSnapshot();
|
||||
const info = await runtimeQueryIds.getSnapshotInfo();
|
||||
if (!info) {
|
||||
if (cmdOpts.json) {
|
||||
console.log(JSON.stringify({
|
||||
cached: false,
|
||||
cachePath: runtimeQueryIds.cachePath,
|
||||
featuresPath: featureSnapshot.cachePath,
|
||||
features: featureSnapshot.overrides,
|
||||
}, null, 2));
|
||||
return;
|
||||
}
|
||||
console.log(`${ctx.p('warn')}No cached query IDs yet.`);
|
||||
console.log(`${ctx.p('info')}Run: bird query-ids --fresh`);
|
||||
console.log(`features_path: ${featureSnapshot.cachePath}`);
|
||||
return;
|
||||
}
|
||||
if (cmdOpts.json) {
|
||||
console.log(JSON.stringify({
|
||||
cached: true,
|
||||
cachePath: info.cachePath,
|
||||
fetchedAt: info.snapshot.fetchedAt,
|
||||
isFresh: info.isFresh,
|
||||
ageMs: info.ageMs,
|
||||
ids: info.snapshot.ids,
|
||||
discovery: info.snapshot.discovery,
|
||||
featuresPath: featureSnapshot.cachePath,
|
||||
features: featureSnapshot.overrides,
|
||||
}, null, 2));
|
||||
return;
|
||||
}
|
||||
console.log(`${ctx.p('ok')}GraphQL query IDs cached`);
|
||||
console.log(`path: ${info.cachePath}`);
|
||||
console.log(`fetched_at: ${info.snapshot.fetchedAt}`);
|
||||
console.log(`fresh: ${info.isFresh ? 'yes' : 'no'}`);
|
||||
console.log(`ops: ${Object.keys(info.snapshot.ids).length}`);
|
||||
console.log(`features_path: ${featureSnapshot.cachePath}`);
|
||||
console.log(`features: ${countFeatureOverrides(featureSnapshot.overrides)}`);
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=query-ids.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"query-ids.js","sourceRoot":"","sources":["../../src/commands/query-ids.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,SAAS,qBAAqB,CAAC,SAA2B;IACxD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;QACrB,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IAChD,CAAC;IACD,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,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IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,QAAQ,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7D,OAAO,CAAC,GAAG,CAAC,kBAAkB,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC,aAAa,qBAAqB,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;AACP,CAAC"}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerReadCommands(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=read.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/commands/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAqM5E"}
|
||||
Vendored
-152
@@ -1,152 +0,0 @@
|
||||
import { parsePaginationFlags } from '../cli/pagination.js';
|
||||
import { formatStatsLine } from '../lib/output.js';
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
export function registerReadCommands(program, ctx) {
|
||||
program
|
||||
.command('read')
|
||||
.description('Read/fetch a tweet by ID or URL')
|
||||
.argument('<tweet-id-or-url>', 'Tweet ID or URL to read')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (tweetIdOrUrl, cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const result = await client.getTweet(tweetId, { includeRaw });
|
||||
if (result.success && result.tweet) {
|
||||
if (cmdOpts.json || cmdOpts.jsonFull) {
|
||||
console.log(JSON.stringify(result.tweet, null, 2));
|
||||
}
|
||||
else {
|
||||
ctx.printTweets([result.tweet], { showSeparator: false });
|
||||
console.log(formatStatsLine(result.tweet, ctx.getOutput()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to read tweet: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('replies')
|
||||
.description('List replies to a tweet (by ID or URL)')
|
||||
.argument('<tweet-id-or-url>', 'Tweet ID or URL')
|
||||
.option('--all', 'Fetch all replies (paged)')
|
||||
.option('--max-pages <number>', 'Fetch N pages (implies pagination)')
|
||||
.option('--delay <ms>', 'Delay in ms between page fetches', '1000')
|
||||
.option('--cursor <string>', 'Resume pagination from a cursor')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (tweetIdOrUrl, cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
||||
const pagination = parsePaginationFlags(cmdOpts, { maxPagesImpliesPagination: true, includeDelay: true });
|
||||
if (!pagination.ok) {
|
||||
console.error(`${ctx.p('err')}${pagination.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const result = pagination.usePagination
|
||||
? await client.getRepliesPaged(tweetId, {
|
||||
includeRaw,
|
||||
maxPages: pagination.maxPages,
|
||||
cursor: pagination.cursor,
|
||||
pageDelayMs: pagination.pageDelayMs,
|
||||
})
|
||||
: await client.getReplies(tweetId, { includeRaw });
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
if (result.tweets) {
|
||||
ctx.printTweetsResult(result, {
|
||||
json: isJson,
|
||||
usePagination: pagination.usePagination,
|
||||
emptyMessage: 'No replies found.',
|
||||
});
|
||||
// Show pagination hint if there's more
|
||||
if (result.nextCursor && !isJson) {
|
||||
console.error(`${ctx.p('info')}More replies available. Use --cursor "${result.nextCursor}" to continue.`);
|
||||
}
|
||||
}
|
||||
if (!result.success) {
|
||||
console.error(`${ctx.p('err')}Failed to fetch replies: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('thread')
|
||||
.description('Show the full conversation thread containing the tweet')
|
||||
.argument('<tweet-id-or-url>', 'Tweet ID or URL')
|
||||
.option('--all', 'Fetch all thread tweets (paged)')
|
||||
.option('--max-pages <number>', 'Fetch N pages (implies pagination)')
|
||||
.option('--delay <ms>', 'Delay in ms between page fetches', '1000')
|
||||
.option('--cursor <string>', 'Resume pagination from a cursor')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (tweetIdOrUrl, cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
||||
const pagination = parsePaginationFlags(cmdOpts, { maxPagesImpliesPagination: true, includeDelay: true });
|
||||
if (!pagination.ok) {
|
||||
console.error(`${ctx.p('err')}${pagination.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const result = pagination.usePagination
|
||||
? await client.getThreadPaged(tweetId, {
|
||||
includeRaw,
|
||||
maxPages: pagination.maxPages,
|
||||
cursor: pagination.cursor,
|
||||
pageDelayMs: pagination.pageDelayMs,
|
||||
})
|
||||
: await client.getThread(tweetId, { includeRaw });
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
if (result.tweets) {
|
||||
ctx.printTweetsResult(result, {
|
||||
json: isJson,
|
||||
usePagination: pagination.usePagination,
|
||||
emptyMessage: 'No thread tweets found.',
|
||||
});
|
||||
// Show pagination hint if there's more
|
||||
if (result.nextCursor && !isJson) {
|
||||
console.error(`${ctx.p('info')}More thread tweets available. Use --cursor "${result.nextCursor}" to continue.`);
|
||||
}
|
||||
}
|
||||
if (!result.success) {
|
||||
console.error(`${ctx.p('err')}Failed to fetch thread: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=read.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerSearchCommands(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=search.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CA0I9E"}
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
import { parsePaginationFlags } from '../cli/pagination.js';
|
||||
import { mentionsQueryFromUserOption, normalizeHandle } from '../lib/normalize-handle.js';
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
export function registerSearchCommands(program, ctx) {
|
||||
program
|
||||
.command('search')
|
||||
.description('Search for tweets')
|
||||
.argument('<query>', 'Search query (e.g., "@clawdbot" or "from:clawdbot")')
|
||||
.option('-n, --count <number>', 'Number of tweets to fetch', '10')
|
||||
.option('--all', 'Fetch all search results (paged)')
|
||||
.option('--max-pages <number>', 'Stop after N pages when using --all')
|
||||
.option('--cursor <string>', 'Resume pagination from a cursor')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (query, cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '10', 10);
|
||||
const pagination = parsePaginationFlags(cmdOpts);
|
||||
if (!pagination.ok) {
|
||||
console.error(`${ctx.p('err')}${pagination.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const maxPages = pagination.maxPages;
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const usePagination = pagination.usePagination;
|
||||
if (maxPages !== undefined && !usePagination) {
|
||||
console.error(`${ctx.p('err')}--max-pages requires --all or --cursor.`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
|
||||
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const searchOptions = { includeRaw };
|
||||
const paginationOptions = { includeRaw, maxPages, cursor: pagination.cursor };
|
||||
const result = usePagination
|
||||
? await client.getAllSearchResults(query, paginationOptions)
|
||||
: await client.search(query, count, searchOptions);
|
||||
if (result.success) {
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
ctx.printTweetsResult(result, {
|
||||
json: isJson,
|
||||
usePagination: Boolean(usePagination),
|
||||
emptyMessage: 'No tweets found.',
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Search failed: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('mentions')
|
||||
.description('Find tweets mentioning a user (defaults to current user)')
|
||||
.option('-u, --user <handle>', 'User handle (e.g. @steipete)')
|
||||
.option('-n, --count <number>', 'Number of tweets to fetch', '10')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '10', 10);
|
||||
const fromUserOpt = mentionsQueryFromUserOption(cmdOpts.user);
|
||||
if (fromUserOpt.error) {
|
||||
console.error(`${ctx.p('err')}${fromUserOpt.error}`);
|
||||
process.exit(2);
|
||||
}
|
||||
let query = fromUserOpt.query;
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
if (!query) {
|
||||
const who = await client.getCurrentUser();
|
||||
const handle = normalizeHandle(who.user?.username);
|
||||
if (handle) {
|
||||
query = `@${handle}`;
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Could not determine current user (${who.error ?? 'Unknown error'}). Use --user <handle>.`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const result = await client.search(query, count, { includeRaw });
|
||||
if (result.success) {
|
||||
ctx.printTweets(result.tweets, {
|
||||
json: cmdOpts.json || cmdOpts.jsonFull,
|
||||
emptyMessage: 'No mentions found.',
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch mentions: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=search.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerUnbookmarkCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=unbookmark.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"unbookmark.d.ts","sourceRoot":"","sources":["../../src/commands/unbookmark.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAsCjF"}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
export function registerUnbookmarkCommand(program, ctx) {
|
||||
program
|
||||
.command('unbookmark')
|
||||
.description('Remove bookmarked tweets')
|
||||
.argument('<tweet-id-or-url...>', 'Tweet IDs or URLs to remove from bookmarks')
|
||||
.action(async (tweetIdOrUrls) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs });
|
||||
let failures = 0;
|
||||
for (const input of tweetIdOrUrls) {
|
||||
const tweetId = ctx.extractTweetId(input);
|
||||
const result = await client.unbookmark(tweetId);
|
||||
if (result.success) {
|
||||
console.log(`${ctx.p('ok')}Removed bookmark for ${tweetId}`);
|
||||
}
|
||||
else {
|
||||
failures += 1;
|
||||
console.error(`${ctx.p('err')}Failed to remove bookmark for ${tweetId}: ${result.error}`);
|
||||
}
|
||||
}
|
||||
if (failures > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||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AAG,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC1C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAChD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;YAC/D,CAAC;iBAAM,CAAC;gBACN,QAAQ,IAAI,CAAC,CAAC;gBACd,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,iCAAiC,OAAO,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YAC5F,CAAC;QACH,CAAC;QAED,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
||||
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerUserTweetsCommand(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=user-tweets.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"user-tweets.d.ts","sourceRoot":"","sources":["../../src/commands/user-tweets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAwIjF"}
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
import { parseNonNegativeIntFlag, parsePositiveIntFlag } from '../cli/pagination.js';
|
||||
import { normalizeHandle } from '../lib/normalize-handle.js';
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
export function registerUserTweetsCommand(program, ctx) {
|
||||
const formatExample = (cmd, desc) => ` ${ctx.colors.command(cmd)}\n ${ctx.colors.muted(desc)}`;
|
||||
program
|
||||
.command('user-tweets')
|
||||
.description("Get tweets from a user's profile timeline")
|
||||
.argument('<handle>', 'Username to fetch tweets from (e.g., @steipete or steipete)')
|
||||
.option('-n, --count <number>', 'Number of tweets to fetch', '20')
|
||||
.option('--max-pages <number>', 'Stop after N pages (max: 10)')
|
||||
.option('--delay <ms>', 'Delay in ms between page fetches', '1000')
|
||||
.option('--cursor <string>', 'Resume pagination from a cursor')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.addHelpText('after', () => `\n${ctx.colors.section('Command Examples')}\n${[
|
||||
formatExample('bird user-tweets @steipete', 'Get recent tweets from a user'),
|
||||
formatExample('bird user-tweets steipete -n 10', 'Get 10 tweets (@ is optional)'),
|
||||
formatExample('bird user-tweets @steipete -n 50', 'Fetch 50 tweets (paged)'),
|
||||
formatExample('bird user-tweets @steipete --max-pages 3 -n 200', 'Safety cap (max 3 pages)'),
|
||||
formatExample('bird user-tweets @steipete --json', 'Output as JSON'),
|
||||
formatExample('bird user-tweets @steipete --cursor "DAABCg..."', 'Resume from cursor'),
|
||||
].join('\n')}`)
|
||||
.action(async (handle, cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
||||
const maxPagesParsed = parsePositiveIntFlag(cmdOpts.maxPages, '--max-pages');
|
||||
if (!maxPagesParsed.ok) {
|
||||
console.error(`${ctx.p('err')}${maxPagesParsed.error}`);
|
||||
process.exit(2);
|
||||
}
|
||||
const maxPages = maxPagesParsed.value;
|
||||
const delayParsed = parseNonNegativeIntFlag(cmdOpts.delay, '--delay', 1000);
|
||||
if (!delayParsed.ok) {
|
||||
console.error(`${ctx.p('err')}${delayParsed.error}`);
|
||||
process.exit(2);
|
||||
}
|
||||
const pageDelayMs = delayParsed.value;
|
||||
// Validate inputs
|
||||
if (!Number.isFinite(count) || count <= 0) {
|
||||
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
||||
process.exit(2);
|
||||
}
|
||||
const pageSize = 20;
|
||||
const hardMaxPages = 10;
|
||||
const hardMaxTweets = pageSize * hardMaxPages;
|
||||
if (count > hardMaxTweets) {
|
||||
console.error(`${ctx.p('err')}Invalid --count. Max ${hardMaxTweets} tweets per run (safety cap: ${hardMaxPages} pages). Use --cursor to continue.`);
|
||||
process.exit(2);
|
||||
}
|
||||
if (maxPages !== undefined && maxPages > hardMaxPages) {
|
||||
console.error(`${ctx.p('err')}Invalid --max-pages. Expected a positive integer (max: ${hardMaxPages}).`);
|
||||
process.exit(2);
|
||||
}
|
||||
// Normalize handle (strip @ if present)
|
||||
const username = normalizeHandle(handle);
|
||||
if (!username) {
|
||||
console.error(`${ctx.p('err')}Invalid handle: ${handle}`);
|
||||
process.exit(2);
|
||||
}
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
// Look up user ID from username
|
||||
console.error(`${ctx.p('info')}Looking up @${username}...`);
|
||||
const userLookup = await client.getUserIdByUsername(username);
|
||||
if (!userLookup.success || !userLookup.userId) {
|
||||
console.error(`${ctx.p('err')}${userLookup.error || `Could not find user @${username}`}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const displayName = userLookup.name
|
||||
? `${userLookup.name} (@${userLookup.username})`
|
||||
: `@${userLookup.username}`;
|
||||
console.error(`${ctx.p('info')}Fetching tweets from ${displayName}...`);
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const wantsPaginationOutput = Boolean(cmdOpts.cursor) || maxPages !== undefined || count > pageSize;
|
||||
const result = await client.getUserTweetsPaged(userLookup.userId, count, {
|
||||
includeRaw,
|
||||
maxPages,
|
||||
cursor: cmdOpts.cursor,
|
||||
pageDelayMs,
|
||||
});
|
||||
if (result.success) {
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
ctx.printTweetsResult(result, {
|
||||
json: isJson,
|
||||
usePagination: wantsPaginationOutput,
|
||||
emptyMessage: `No tweets found for @${username}.`,
|
||||
});
|
||||
// Show pagination hint if there's more
|
||||
if (result.nextCursor && !cmdOpts.json && !cmdOpts.jsonFull) {
|
||||
console.error(`${ctx.p('info')}More tweets available. Use --cursor "${result.nextCursor}" to continue.`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch tweets: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=user-tweets.js.map
|
||||
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
import type { Command } from 'commander';
|
||||
import type { CliContext } from '../cli/shared.js';
|
||||
export declare function registerUserCommands(program: Command, ctx: CliContext): void;
|
||||
//# sourceMappingURL=users.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/commands/users.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAwMnD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAkL5E"}
|
||||
-295
@@ -1,295 +0,0 @@
|
||||
import { normalizeHandle } from '../lib/normalize-handle.js';
|
||||
import { TwitterClient } from '../lib/twitter-client.js';
|
||||
function formatAboutProfile(profile, ctx, handle) {
|
||||
const lines = [`${ctx.p('info')}Account information for @${handle}:`];
|
||||
if (profile.accountBasedIn) {
|
||||
lines.push(` Account based in: ${profile.accountBasedIn}`);
|
||||
}
|
||||
if (profile.createdCountryAccurate !== undefined) {
|
||||
lines.push(` Creation country accurate: ${profile.createdCountryAccurate ? 'Yes' : 'No'}`);
|
||||
}
|
||||
if (profile.locationAccurate !== undefined) {
|
||||
lines.push(` Location accurate: ${profile.locationAccurate ? 'Yes' : 'No'}`);
|
||||
}
|
||||
if (profile.source) {
|
||||
lines.push(`${ctx.l('source')}${profile.source}`);
|
||||
}
|
||||
if (profile.learnMoreUrl) {
|
||||
lines.push(` Learn more: ${profile.learnMoreUrl}`);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
function printUsers(users, ctx) {
|
||||
for (const user of users) {
|
||||
console.log(`@${user.username} (${user.name})`);
|
||||
if (user.description) {
|
||||
console.log(` ${user.description.slice(0, 100)}${user.description.length > 100 ? '...' : ''}`);
|
||||
}
|
||||
if (user.followersCount !== undefined) {
|
||||
console.log(` ${ctx.p('info')}${user.followersCount.toLocaleString()} followers`);
|
||||
}
|
||||
console.log('──────────────────────────────────────────────────');
|
||||
}
|
||||
}
|
||||
async function resolveUserIdOrExit(client, requestedUserId, ctx) {
|
||||
if (requestedUserId) {
|
||||
return requestedUserId;
|
||||
}
|
||||
const currentUser = await client.getCurrentUser();
|
||||
if (!currentUser.success || !currentUser.user?.id) {
|
||||
console.error(`${ctx.p('err')}Failed to get current user: ${currentUser.error || 'Unknown error'}`);
|
||||
process.exit(1);
|
||||
}
|
||||
return currentUser.user.id;
|
||||
}
|
||||
async function runUserListCommand(program, ctx, spec, cmdOpts) {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
||||
const maxPages = cmdOpts.maxPages ? Number.parseInt(cmdOpts.maxPages, 10) : undefined;
|
||||
const usePagination = cmdOpts.all || cmdOpts.cursor;
|
||||
if (maxPages !== undefined && !cmdOpts.all) {
|
||||
console.error(`${ctx.p('err')}--max-pages requires --all.`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (maxPages !== undefined && (!Number.isFinite(maxPages) || maxPages <= 0)) {
|
||||
console.error(`${ctx.p('err')}Invalid --max-pages. Expected a positive integer.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs });
|
||||
const userId = await resolveUserIdOrExit(client, cmdOpts.user, ctx);
|
||||
if (cmdOpts.all) {
|
||||
const allUsers = [];
|
||||
const seen = new Set();
|
||||
let cursor = cmdOpts.cursor;
|
||||
let pageNum = 0;
|
||||
let nextCursor;
|
||||
while (true) {
|
||||
pageNum += 1;
|
||||
if (!cmdOpts.json) {
|
||||
console.error(`${ctx.p('info')}Fetching page ${pageNum}...`);
|
||||
}
|
||||
const result = await spec.fetch(client, userId, count, cursor);
|
||||
if (!result.success || !result.users) {
|
||||
console.error(`${ctx.p('err')}Failed to fetch ${spec.name}: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
let added = 0;
|
||||
for (const user of result.users) {
|
||||
if (!seen.has(user.id)) {
|
||||
seen.add(user.id);
|
||||
allUsers.push(user);
|
||||
added += 1;
|
||||
}
|
||||
}
|
||||
const pageCursor = result.nextCursor;
|
||||
if (!pageCursor || result.users.length === 0 || added === 0 || pageCursor === cursor) {
|
||||
nextCursor = undefined;
|
||||
break;
|
||||
}
|
||||
if (maxPages && pageNum >= maxPages) {
|
||||
nextCursor = pageCursor;
|
||||
break;
|
||||
}
|
||||
cursor = pageCursor;
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
if (cmdOpts.json) {
|
||||
console.log(JSON.stringify({ users: allUsers, nextCursor: nextCursor ?? null }, null, 2));
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('info')}Total: ${allUsers.length} users`);
|
||||
if (nextCursor) {
|
||||
console.error(`${ctx.p('info')}Stopped at --max-pages. Use --cursor to continue.`);
|
||||
console.error(`${ctx.p('info')}Next cursor: ${nextCursor}`);
|
||||
}
|
||||
printUsers(allUsers, ctx);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const result = await spec.fetch(client, userId, count, cmdOpts.cursor);
|
||||
if (result.success && result.users) {
|
||||
if (cmdOpts.json) {
|
||||
if (usePagination) {
|
||||
console.log(JSON.stringify({ users: result.users, nextCursor: result.nextCursor ?? null }, null, 2));
|
||||
}
|
||||
else {
|
||||
console.log(JSON.stringify(result.users, null, 2));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (result.users.length === 0) {
|
||||
console.log('No users found.');
|
||||
}
|
||||
else {
|
||||
printUsers(result.users, ctx);
|
||||
if (result.nextCursor) {
|
||||
console.error(`${ctx.p('info')}Next cursor: ${result.nextCursor}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch ${spec.name}: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
export function registerUserCommands(program, ctx) {
|
||||
const registerUserListCommand = (spec) => {
|
||||
program
|
||||
.command(spec.name)
|
||||
.description(spec.description)
|
||||
.option('--user <userId>', `User ID to get ${spec.name} for (defaults to current user)`)
|
||||
.option('-n, --count <number>', 'Number of users to fetch per page', '20')
|
||||
.option('--cursor <cursor>', 'Cursor for pagination (from previous response)')
|
||||
.option('--all', 'Fetch all users (paginate automatically)')
|
||||
.option('--max-pages <number>', 'Stop after N pages when using --all')
|
||||
.option('--json', 'Output as JSON')
|
||||
.action(async (cmdOpts) => runUserListCommand(program, ctx, spec, cmdOpts));
|
||||
};
|
||||
registerUserListCommand({
|
||||
name: 'following',
|
||||
description: 'Get users that you (or another user) follow',
|
||||
fetch: (client, userId, count, cursor) => client.getFollowing(userId, count, cursor),
|
||||
});
|
||||
registerUserListCommand({
|
||||
name: 'followers',
|
||||
description: 'Get users that follow you (or another user)',
|
||||
fetch: (client, userId, count, cursor) => client.getFollowers(userId, count, cursor),
|
||||
});
|
||||
program
|
||||
.command('likes')
|
||||
.description('Get your liked tweets')
|
||||
.option('-n, --count <number>', 'Number of likes to fetch', '20')
|
||||
.option('--all', 'Fetch all likes (paged)')
|
||||
.option('--max-pages <number>', 'Stop after N pages when using --all')
|
||||
.option('--cursor <string>', 'Resume pagination from a cursor')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
||||
.action(async (cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
||||
const maxPages = cmdOpts.maxPages ? Number.parseInt(cmdOpts.maxPages, 10) : undefined;
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const usePagination = cmdOpts.all || cmdOpts.cursor;
|
||||
if (maxPages !== undefined && !usePagination) {
|
||||
console.error(`${ctx.p('err')}--max-pages requires --all or --cursor.`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
|
||||
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (maxPages !== undefined && (!Number.isFinite(maxPages) || maxPages <= 0)) {
|
||||
console.error(`${ctx.p('err')}Invalid --max-pages. Expected a positive integer.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const includeRaw = cmdOpts.jsonFull ?? false;
|
||||
const timelineOptions = { includeRaw };
|
||||
const paginationOptions = { includeRaw, maxPages, cursor: cmdOpts.cursor };
|
||||
const result = usePagination
|
||||
? await client.getAllLikes(paginationOptions)
|
||||
: await client.getLikes(count, timelineOptions);
|
||||
if (result.success) {
|
||||
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
||||
ctx.printTweetsResult(result, {
|
||||
json: isJson,
|
||||
usePagination: Boolean(usePagination),
|
||||
emptyMessage: 'No liked tweets found.',
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch likes: ${result.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('whoami')
|
||||
.description('Show which Twitter account the current credentials belong to')
|
||||
.action(async () => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (cookies.source) {
|
||||
console.error(`${ctx.l('source')}${cookies.source}`);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
||||
const result = await client.getCurrentUser();
|
||||
const credentialSource = cookies.source ?? 'env/auto-detected cookies';
|
||||
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(`${ctx.l('engine')}graphql`);
|
||||
console.log(`${ctx.l('credentials')}${credentialSource}`);
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to determine current user: ${result.error ?? 'Unknown error'}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('about')
|
||||
.description('Get account origin and location information for a user')
|
||||
.argument('<username>', 'Twitter username (with or without @)')
|
||||
.option('--json', 'Output as JSON')
|
||||
.action(async (username, cmdOpts) => {
|
||||
const opts = program.opts();
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const normalizedHandle = normalizeHandle(username);
|
||||
if (!normalizedHandle) {
|
||||
console.error(`${ctx.p('err')}Invalid username: ${username}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
for (const warning of warnings) {
|
||||
console.error(`${ctx.p('warn')}${warning}`);
|
||||
}
|
||||
if (!cookies.authToken || !cookies.ct0) {
|
||||
console.error(`${ctx.p('err')}Missing required credentials`);
|
||||
process.exit(1);
|
||||
}
|
||||
const client = new TwitterClient({ cookies, timeoutMs });
|
||||
const result = await client.getUserAboutAccount(normalizedHandle);
|
||||
if (result.success && result.aboutProfile) {
|
||||
if (cmdOpts.json) {
|
||||
console.log(JSON.stringify(result.aboutProfile, null, 2));
|
||||
}
|
||||
else {
|
||||
for (const line of formatAboutProfile(result.aboutProfile, ctx, normalizedHandle)) {
|
||||
console.log(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error(`${ctx.p('err')}Failed to fetch account information: ${result.error ?? 'Unknown error'}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=users.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
export * from './lib/index.js';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
||||
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
export * from './lib/index.js';
|
||||
//# sourceMappingURL=index.js.map
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
export type CliInvocation = {
|
||||
argv: string[] | null;
|
||||
showHelp: boolean;
|
||||
};
|
||||
export declare function looksLikeTweetInput(value: string): boolean;
|
||||
export declare function resolveCliInvocation(rawArgs: string[], knownCommands: Set<string>): CliInvocation;
|
||||
//# sourceMappingURL=cli-args.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../../src/lib/cli-args.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAKF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAM1D;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,aAAa,CAiBjG"}
|
||||
Vendored
-25
@@ -1,25 +0,0 @@
|
||||
const TWEET_URL_REGEX = /^(?:https?:\/\/)?(?:www\.)?(?:twitter\.com|x\.com)\/[^/]+\/status\/\d+/i;
|
||||
const TWEET_ID_REGEX = /^\d{8,}$/;
|
||||
export function looksLikeTweetInput(value) {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) {
|
||||
return false;
|
||||
}
|
||||
return TWEET_URL_REGEX.test(trimmed) || TWEET_ID_REGEX.test(trimmed);
|
||||
}
|
||||
export function resolveCliInvocation(rawArgs, knownCommands) {
|
||||
if (rawArgs.length === 0) {
|
||||
return { argv: null, showHelp: true };
|
||||
}
|
||||
const hasKnownCommand = rawArgs.some((arg) => knownCommands.has(arg));
|
||||
if (!hasKnownCommand) {
|
||||
const tweetArgIndex = rawArgs.findIndex(looksLikeTweetInput);
|
||||
if (tweetArgIndex >= 0) {
|
||||
const rewrittenArgs = [...rawArgs];
|
||||
rewrittenArgs.splice(tweetArgIndex, 0, 'read');
|
||||
return { argv: ['node', 'bird', ...rewrittenArgs], showHelp: false };
|
||||
}
|
||||
}
|
||||
return { argv: null, showHelp: false };
|
||||
}
|
||||
//# sourceMappingURL=cli-args.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../../src/lib/cli-args.ts"],"names":[],"mappings":"AAKA,MAAM,eAAe,GAAG,yEAAyE,CAAC;AAClG,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAiB,EAAE,aAA0B;IAChF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxC,CAAC;IAED,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAEtE,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QAC7D,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,aAAa,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;YACnC,aAAa,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;YAC/C,OAAO,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACvE,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACzC,CAAC"}
|
||||
Vendored
-31
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* Browser cookie extraction for Twitter authentication.
|
||||
* Delegates to @steipete/sweet-cookie for Safari/Chrome/Firefox reads.
|
||||
*/
|
||||
export interface TwitterCookies {
|
||||
authToken: string | null;
|
||||
ct0: string | null;
|
||||
cookieHeader: string | null;
|
||||
source: string | null;
|
||||
}
|
||||
export interface CookieExtractionResult {
|
||||
cookies: TwitterCookies;
|
||||
warnings: string[];
|
||||
}
|
||||
export type CookieSource = 'safari' | 'chrome' | 'firefox';
|
||||
export declare function extractCookiesFromSafari(): Promise<CookieExtractionResult>;
|
||||
export declare function extractCookiesFromChrome(profile?: string): Promise<CookieExtractionResult>;
|
||||
export declare function extractCookiesFromFirefox(profile?: string): Promise<CookieExtractionResult>;
|
||||
/**
|
||||
* Resolve Twitter credentials from multiple sources.
|
||||
* Priority: CLI args > environment variables > browsers (ordered).
|
||||
*/
|
||||
export declare function resolveCredentials(options: {
|
||||
authToken?: string;
|
||||
ct0?: string;
|
||||
cookieSource?: CookieSource | CookieSource[];
|
||||
chromeProfile?: string;
|
||||
firefoxProfile?: string;
|
||||
cookieTimeoutMs?: number;
|
||||
}): Promise<CookieExtractionResult>;
|
||||
//# sourceMappingURL=cookies.d.ts.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/lib/cookies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,cAAc,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAsI3D,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAEhF;AAED,wBAAsB,wBAAwB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAEhG;AAED,wBAAsB,yBAAyB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAEjG;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAC;IAC7C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,OAAO,CAAC,sBAAsB,CAAC,CA0DlC"}
|
||||
Vendored
-173
@@ -1,173 +0,0 @@
|
||||
/**
|
||||
* Browser cookie extraction for Twitter authentication.
|
||||
* Delegates to @steipete/sweet-cookie for Safari/Chrome/Firefox reads.
|
||||
*/
|
||||
import { getCookies } from '@steipete/sweet-cookie';
|
||||
const TWITTER_COOKIE_NAMES = ['auth_token', 'ct0'];
|
||||
const TWITTER_URL = 'https://x.com/';
|
||||
const TWITTER_ORIGINS = ['https://x.com/', 'https://twitter.com/'];
|
||||
const DEFAULT_COOKIE_TIMEOUT_MS = 30_000;
|
||||
function normalizeValue(value) {
|
||||
if (typeof value !== 'string') {
|
||||
return null;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
function cookieHeader(authToken, ct0) {
|
||||
return `auth_token=${authToken}; ct0=${ct0}`;
|
||||
}
|
||||
function buildEmpty() {
|
||||
return { authToken: null, ct0: null, cookieHeader: null, source: null };
|
||||
}
|
||||
function readEnvCookie(cookies, keys, field) {
|
||||
if (cookies[field]) {
|
||||
return;
|
||||
}
|
||||
for (const key of keys) {
|
||||
const value = normalizeValue(process.env[key]);
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
cookies[field] = value;
|
||||
if (!cookies.source) {
|
||||
cookies.source = `env ${key}`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
function resolveSources(cookieSource) {
|
||||
if (Array.isArray(cookieSource)) {
|
||||
return cookieSource;
|
||||
}
|
||||
if (cookieSource) {
|
||||
return [cookieSource];
|
||||
}
|
||||
return ['safari', 'chrome', 'firefox'];
|
||||
}
|
||||
function labelForSource(source, profile) {
|
||||
if (source === 'safari') {
|
||||
return 'Safari';
|
||||
}
|
||||
if (source === 'chrome') {
|
||||
return profile ? `Chrome profile "${profile}"` : 'Chrome default profile';
|
||||
}
|
||||
return profile ? `Firefox profile "${profile}"` : 'Firefox default profile';
|
||||
}
|
||||
function pickCookieValue(cookies, name) {
|
||||
const matches = cookies.filter((c) => c?.name === name && typeof c.value === 'string');
|
||||
if (matches.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const preferred = matches.find((c) => (c.domain ?? '').endsWith('x.com'));
|
||||
if (preferred?.value) {
|
||||
return preferred.value;
|
||||
}
|
||||
const twitter = matches.find((c) => (c.domain ?? '').endsWith('twitter.com'));
|
||||
if (twitter?.value) {
|
||||
return twitter.value;
|
||||
}
|
||||
return matches[0]?.value ?? null;
|
||||
}
|
||||
async function readTwitterCookiesFromBrowser(options) {
|
||||
const warnings = [];
|
||||
const out = buildEmpty();
|
||||
const { cookies, warnings: providerWarnings } = await getCookies({
|
||||
url: TWITTER_URL,
|
||||
origins: TWITTER_ORIGINS,
|
||||
names: [...TWITTER_COOKIE_NAMES],
|
||||
browsers: [options.source],
|
||||
mode: 'merge',
|
||||
chromeProfile: options.chromeProfile,
|
||||
firefoxProfile: options.firefoxProfile,
|
||||
timeoutMs: options.cookieTimeoutMs,
|
||||
});
|
||||
warnings.push(...providerWarnings);
|
||||
const authToken = pickCookieValue(cookies, 'auth_token');
|
||||
const ct0 = pickCookieValue(cookies, 'ct0');
|
||||
if (authToken) {
|
||||
out.authToken = authToken;
|
||||
}
|
||||
if (ct0) {
|
||||
out.ct0 = ct0;
|
||||
}
|
||||
if (out.authToken && out.ct0) {
|
||||
out.cookieHeader = cookieHeader(out.authToken, out.ct0);
|
||||
out.source = labelForSource(options.source, options.source === 'chrome' ? options.chromeProfile : options.firefoxProfile);
|
||||
return { cookies: out, warnings };
|
||||
}
|
||||
if (options.source === 'safari') {
|
||||
warnings.push('No Twitter cookies found in Safari. Make sure you are logged into x.com in Safari.');
|
||||
}
|
||||
else if (options.source === 'chrome') {
|
||||
warnings.push('No Twitter cookies found in Chrome. Make sure you are logged into x.com in Chrome.');
|
||||
}
|
||||
else {
|
||||
warnings.push('No Twitter cookies found in Firefox. Make sure you are logged into x.com in Firefox and the profile exists.');
|
||||
}
|
||||
return { cookies: out, warnings };
|
||||
}
|
||||
export async function extractCookiesFromSafari() {
|
||||
return readTwitterCookiesFromBrowser({ source: 'safari' });
|
||||
}
|
||||
export async function extractCookiesFromChrome(profile) {
|
||||
return readTwitterCookiesFromBrowser({ source: 'chrome', chromeProfile: profile });
|
||||
}
|
||||
export async function extractCookiesFromFirefox(profile) {
|
||||
return readTwitterCookiesFromBrowser({ source: 'firefox', firefoxProfile: profile });
|
||||
}
|
||||
/**
|
||||
* Resolve Twitter credentials from multiple sources.
|
||||
* Priority: CLI args > environment variables > browsers (ordered).
|
||||
*/
|
||||
export async function resolveCredentials(options) {
|
||||
const warnings = [];
|
||||
const cookies = buildEmpty();
|
||||
const cookieTimeoutMs = typeof options.cookieTimeoutMs === 'number' &&
|
||||
Number.isFinite(options.cookieTimeoutMs) &&
|
||||
options.cookieTimeoutMs > 0
|
||||
? options.cookieTimeoutMs
|
||||
: process.platform === 'darwin'
|
||||
? DEFAULT_COOKIE_TIMEOUT_MS
|
||||
: undefined;
|
||||
if (options.authToken) {
|
||||
cookies.authToken = options.authToken;
|
||||
cookies.source = 'CLI argument';
|
||||
}
|
||||
if (options.ct0) {
|
||||
cookies.ct0 = options.ct0;
|
||||
if (!cookies.source) {
|
||||
cookies.source = 'CLI argument';
|
||||
}
|
||||
}
|
||||
readEnvCookie(cookies, ['AUTH_TOKEN', 'TWITTER_AUTH_TOKEN'], 'authToken');
|
||||
readEnvCookie(cookies, ['CT0', 'TWITTER_CT0'], 'ct0');
|
||||
if (cookies.authToken && cookies.ct0) {
|
||||
cookies.cookieHeader = cookieHeader(cookies.authToken, cookies.ct0);
|
||||
return { cookies, warnings };
|
||||
}
|
||||
const sourcesToTry = resolveSources(options.cookieSource);
|
||||
for (const source of sourcesToTry) {
|
||||
const res = await readTwitterCookiesFromBrowser({
|
||||
source,
|
||||
chromeProfile: options.chromeProfile,
|
||||
firefoxProfile: options.firefoxProfile,
|
||||
cookieTimeoutMs,
|
||||
});
|
||||
warnings.push(...res.warnings);
|
||||
if (res.cookies.authToken && res.cookies.ct0) {
|
||||
return { cookies: res.cookies, warnings };
|
||||
}
|
||||
}
|
||||
if (!cookies.authToken) {
|
||||
warnings.push('Missing auth_token - provide via --auth-token, AUTH_TOKEN env var, or login to x.com in Safari/Chrome/Firefox');
|
||||
}
|
||||
if (!cookies.ct0) {
|
||||
warnings.push('Missing ct0 - provide via --ct0, CT0 env var, or login to x.com in Safari/Chrome/Firefox');
|
||||
}
|
||||
if (cookies.authToken && cookies.ct0) {
|
||||
cookies.cookieHeader = cookieHeader(cookies.authToken, cookies.ct0);
|
||||
}
|
||||
return { cookies, warnings };
|
||||
}
|
||||
//# sourceMappingURL=cookies.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
@@ -1,2 +0,0 @@
|
||||
export declare function extractBookmarkFolderId(input: string): string | null;
|
||||
//# sourceMappingURL=extract-bookmark-folder-id.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"extract-bookmark-folder-id.d.ts","sourceRoot":"","sources":["../../src/lib/extract-bookmark-folder-id.ts"],"names":[],"mappings":"AAMA,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAapE"}
|
||||
@@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Extract bookmark folder (collection) ID from an X/Twitter bookmarks URL.
|
||||
*/
|
||||
const BOOKMARK_FOLDER_URL_REGEX = /(?:twitter\.com|x\.com)\/i\/bookmarks\/(\d+)/i;
|
||||
const BOOKMARK_FOLDER_ID_REGEX = /^\d{5,}$/;
|
||||
export function extractBookmarkFolderId(input) {
|
||||
const trimmed = input.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
const urlMatch = BOOKMARK_FOLDER_URL_REGEX.exec(trimmed);
|
||||
if (urlMatch) {
|
||||
return urlMatch[1];
|
||||
}
|
||||
if (BOOKMARK_FOLDER_ID_REGEX.test(trimmed)) {
|
||||
return trimmed;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//# sourceMappingURL=extract-bookmark-folder-id.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"extract-bookmark-folder-id.js","sourceRoot":"","sources":["../../src/lib/extract-bookmark-folder-id.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,yBAAyB,GAAG,+CAA+C,CAAC;AAClF,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAE5C,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,QAAQ,GAAG,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IACD,IAAI,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
||||
@@ -1,2 +0,0 @@
|
||||
export declare function extractListId(input: string): string | null;
|
||||
//# sourceMappingURL=extract-list-id.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"extract-list-id.d.ts","sourceRoot":"","sources":["../../src/lib/extract-list-id.ts"],"names":[],"mappings":"AAMA,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAa1D"}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
// ABOUTME: Extract list ID from an X/Twitter list URL.
|
||||
// ABOUTME: Returns list ID or null if input is invalid.
|
||||
const LIST_URL_REGEX = /(?:twitter\.com|x\.com)\/i\/lists\/(\d+)/i;
|
||||
const LIST_ID_REGEX = /^\d{5,}$/;
|
||||
export function extractListId(input) {
|
||||
const trimmed = input.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
const urlMatch = LIST_URL_REGEX.exec(trimmed);
|
||||
if (urlMatch) {
|
||||
return urlMatch[1];
|
||||
}
|
||||
if (LIST_ID_REGEX.test(trimmed)) {
|
||||
return trimmed;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//# sourceMappingURL=extract-list-id.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"extract-list-id.js","sourceRoot":"","sources":["../../src/lib/extract-list-id.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,wDAAwD;AAExD,MAAM,cAAc,GAAG,2CAA2C,CAAC;AACnE,MAAM,aAAa,GAAG,UAAU,CAAC;AAEjC,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IACD,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
||||
@@ -1,2 +0,0 @@
|
||||
export declare function extractTweetId(input: string): string;
|
||||
//# sourceMappingURL=extract-tweet-id.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"extract-tweet-id.d.ts","sourceRoot":"","sources":["../../src/lib/extract-tweet-id.ts"],"names":[],"mappings":"AAKA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQpD"}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Extract tweet ID from a Twitter/X URL or return the input unchanged if it's already an ID.
|
||||
*/
|
||||
const TWEET_URL_REGEX = /(?:twitter\.com|x\.com)\/(?:\w+\/status|i\/web\/status)\/(\d+)/i;
|
||||
export function extractTweetId(input) {
|
||||
// If it's a URL, extract the tweet ID
|
||||
const urlMatch = TWEET_URL_REGEX.exec(input);
|
||||
if (urlMatch) {
|
||||
return urlMatch[1];
|
||||
}
|
||||
// Assume it's already an ID
|
||||
return input;
|
||||
}
|
||||
//# sourceMappingURL=extract-tweet-id.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"extract-tweet-id.js","sourceRoot":"","sources":["../../src/lib/extract-tweet-id.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,eAAe,GAAG,iEAAiE,CAAC;AAE1F,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,sCAAsC;IACtC,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IACD,4BAA4B;IAC5B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user