Files
jackwener__opencli/clis/twitter/hide-reply.ts
jackwener 314bc6f231 refactor: simplify core modules — remove root shims, consolidate error classification, streamline cascade/interceptor, clean up synthesize
1. Remove root-level shim files (errors.ts, logger.ts, registry.ts, types.ts, utils.ts, launcher.ts) — update all ~840 adapter imports to reference src/ directly
2. Consolidate interceptor: reuse shared DISGUISE_FN in tap interceptor instead of reimplementing
3. Unify error classification: single ClassifiedError type with icon/exitCode/hint lookup table, eliminating duplicated pattern matching between resolveExitCode and renderError
4. Simplify cascade probe: replace repetitive switch cases with PROBE_OPTIONS lookup map
12. Clean up synthesize.ts: remove deprecated snake_case field aliases (recommended_args, recommended_columns, recommendedColumnsLegacy) and unnecessary constant aliases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-05 03:06:47 +08:00

72 lines
2.3 KiB
TypeScript

import { CommandExecutionError } from '../../src/errors.js';
import { cli, Strategy } from '../../src/registry.js';
import type { IPage } from '../../src/types.js';
cli({
site: 'twitter',
name: 'hide-reply',
description: 'Hide a reply on your tweet (useful for hiding bot/spam replies)',
domain: 'x.com',
strategy: Strategy.UI,
browser: true,
args: [
{ name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the reply tweet to hide' },
],
columns: ['status', 'message'],
func: async (page: IPage | null, kwargs: any) => {
if (!page) throw new CommandExecutionError('Browser session required for twitter hide-reply');
await page.goto(kwargs.url);
await page.wait({ selector: '[data-testid="primaryColumn"]' });
const result = await page.evaluate(`(async () => {
try {
let attempts = 0;
let moreMenu = null;
while (attempts < 20) {
moreMenu = document.querySelector('[aria-label="More"]');
if (moreMenu) break;
await new Promise(r => setTimeout(r, 500));
attempts++;
}
if (!moreMenu) {
return { ok: false, message: 'Could not find the "More" menu on this tweet. Are you logged in?' };
}
moreMenu.click();
await new Promise(r => setTimeout(r, 1000));
// Look for the "Hide reply" menu item
const items = document.querySelectorAll('[role="menuitem"]');
let hideItem = null;
for (const item of items) {
if (item.textContent && item.textContent.includes('Hide reply')) {
hideItem = item;
break;
}
}
if (!hideItem) {
return { ok: false, message: 'Could not find "Hide reply" option. This may not be a reply on your tweet.' };
}
hideItem.click();
await new Promise(r => setTimeout(r, 1500));
return { ok: true, message: 'Reply successfully hidden.' };
} catch (e) {
return { ok: false, message: e.toString() };
}
})()`);
if (result.ok) await page.wait(2);
return [{
status: result.ok ? 'success' : 'failed',
message: result.message
}];
}
});