import { Command } from 'commander'; import chalk from 'chalk'; import { getClient, outputResult, executePaginated, type PaginatedCommandOptions } from './shared.js'; export function registerNotificationCommands(program: Command): void { program .command('notifications') .description('Get all notifications') .option('-n, --count ', 'Number of results per page', '20') .option('--cursor ', 'Pagination cursor') .option('--all', 'Fetch all pages') .option('--max-pages ', 'Maximum pages to fetch') .option('--resume ', 'Resume file for cursor state') .option('--delay ', 'Delay between pages', '1000') .action(async (options: PaginatedCommandOptions, command) => { const globalOpts = command.parent?.opts() || {}; const client = await getClient(globalOpts); try { const count = parseInt(options.count || '20'); await executePaginated( (cursor) => client.getNotifications(count, cursor), options, globalOpts ); } catch (error: any) { console.error(chalk.red(`Error: ${error.message}`)); process.exit(1); } }); program .command('mentions') .description('Get mention notifications (tweets that mention you)') .option('-n, --count ', 'Number of results per page', '20') .option('--cursor ', 'Pagination cursor') .option('--all', 'Fetch all pages') .option('--max-pages ', 'Maximum pages to fetch') .option('--resume ', 'Resume file for cursor state') .option('--delay ', 'Delay between pages', '1000') .action(async (options: PaginatedCommandOptions, command) => { const globalOpts = command.parent?.opts() || {}; const client = await getClient(globalOpts); try { const count = parseInt(options.count || '20'); await executePaginated( (cursor) => client.getMentions(count, cursor), options, globalOpts ); } catch (error: any) { console.error(chalk.red(`Error: ${error.message}`)); process.exit(1); } }); program .command('verified-notifications') .description('Get notifications from verified accounts') .option('-n, --count ', 'Number of results per page', '20') .option('--cursor ', 'Pagination cursor') .option('--all', 'Fetch all pages') .option('--max-pages ', 'Maximum pages to fetch') .option('--resume ', 'Resume file for cursor state') .option('--delay ', 'Delay between pages', '1000') .action(async (options: PaginatedCommandOptions, command) => { const globalOpts = command.parent?.opts() || {}; const client = await getClient(globalOpts); try { const count = parseInt(options.count || '20'); await executePaginated( (cursor) => client.getVerifiedNotifications(count, cursor), options, globalOpts ); } catch (error: any) { console.error(chalk.red(`Error: ${error.message}`)); process.exit(1); } }); }