--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\Channel;
+use App\Models\TwitchToken;
+use Illuminate\Console\Command;
+use Illuminate\Http\Client\RequestException;
+use Illuminate\Support\Facades\Http;
+
+class TwitchChannelInfo extends Command {
+
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'twitch:channel-info';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Refresh twitch channel info';
+
+ /**
+ * Execute the console command.
+ *
+ * @return int
+ */
+ public function handle()
+ {
+ $this->token = TwitchToken::firstWhere('nick', 'localhorsttv');
+ if (!$this->token) {
+ $this->line('please acquire a token for localhorsttv first');
+ return 1;
+ }
+ $channels = Channel::where('twitch_chat', '!=', '')->where('twitch_id', '=', '')->get();
+ foreach ($channels as $channel) {
+ try {
+ $this->updateChannel($channel);
+ } catch (RequestException $e) {
+ if ($e->response->status() == 401) {
+ $this->token->refresh();
+ $this->updateChannel($channel);
+ }
+ }
+ }
+ return Command::SUCCESS;
+ }
+
+ private function updateChannel(Channel $channel) {
+ $this->line($channel->twitch_chat);
+ $login = substr($channel->twitch_chat, 1);
+ $rsp = $this->token->request()
+ ->get('/users', [
+ 'login' => $login,
+ ])
+ ->throw();
+ foreach ($rsp['data'] as $user) {
+ if ($user['login'] != $login) continue;
+ $channel->twitch_id = $user['id'];
+ $channel->save();
+ }
+ }
+
+ private $token;
+
+}
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('channels', function (Blueprint $table) {
+ $table->string('twitch_id')->default('');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('channels', function (Blueprint $table) {
+ $table->dropColumn('twitch_id');
+ });
+ }
+};
Route::put('channels/{channel}/guessing-game/{name}', 'App\Http\Controllers\ChannelController@saveGuessingGame');
Route::get('guessing-game-monitor/{key}', 'App\Http\Controllers\ChannelController@getGuessingGameMonitor');
+Route::get('guessing-game-leaderboard/twitch/{channel:twitch_id}/{type}', 'App\Http\Controllers\ChannelController@getGuessingGameLeaderboard');
Route::get('content', 'App\Http\Controllers\TechniqueController@search');
Route::get('content/{tech:name}', 'App\Http\Controllers\TechniqueController@single');