-
app/Console/Commands/TwitterGiveaway.php
Open in GitHubuse Illuminate\Console\Command; use Illuminate\Support\Collection; use Illuminate\Support\Str; use stdClass; class TwitterGiveaway extends Command { // public function handle(Twitter $twitter): void { // $ids = collect(); $cursor = -1; do { $response = $twitter->request( sprintf('statuses/retweeters/ids.json?id=%s&count=100&stringify_ids=true&cursor=%d', $id, $cursor), 'GET' ); $ids->push(...$response->ids); $cursor = $response->next_cursor; } while ($cursor != 0); $users = $ids ->chunk(100) ->map(fn (Collection $ids): array => $twitter->request( sprintf('users/lookup.json?user_id=%s', $ids->implode(',')), 'GET' )) ->collapse() ->map(fn (stdClass $user): string => $user->screen_name) ->push(...$added) ->reject(fn (string $username): bool => $excluded->contains($username)) ->values(); // } // }