From b22c9010876eb9b004c6ea2930e90c1a1a711f48 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 17 Nov 2024 14:01:57 +0100 Subject: [PATCH] add clip command --- app/Console/Commands/TwitchChannelClips.php | 65 +++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 app/Console/Commands/TwitchChannelClips.php diff --git a/app/Console/Commands/TwitchChannelClips.php b/app/Console/Commands/TwitchChannelClips.php new file mode 100644 index 0000000..be9de00 --- /dev/null +++ b/app/Console/Commands/TwitchChannelClips.php @@ -0,0 +1,65 @@ +token = TwitchToken::firstWhere('nick', 'localhorsttv'); + if (!$this->token) { + $this->line('please acquire a token for localhorsttv first'); + return 1; + } + if ($this->token->hasExpired()) { + $this->line('access token has expired, refreshing'); + $this->token->refresh(); + } + $channel = Channel::where('title', '=', $this->argument('name'))->firstOrFail(); + $clips = $this->fetchClips($channel); + foreach ($clips as $clip) { + var_dump($clip); + } + return Command::SUCCESS; + } + + private function fetchClips(Channel $channel) { + $this->line($channel->twitch_chat); + $rsp = $this->token->request() + ->get('/clips', Query::build([ + 'first' => 100, + 'broadcaster_id' => $channel->twitch_id, + ])) + ->throw(); + return $rsp['data']; + } + + private $token; + +} -- 2.39.2