/** * @throws \LogicException */ public function handle() { Karma::created(function (Karma $karma) { $count = $karma->user->thanks->count(); if ($count === 100) { $this->create($karma->user, $karma->created_at); } }); }
/** * @throws \LogicException */ public function handle() { Karma::created(function (Karma $karma) { $count = $karma->target->karma->count(); if ($count === 500) { $this->create($karma->target, $karma->created_at); } }); }
/** * @throws \LogicException */ public function handle() { Karma::created(function (Karma $karma) { $thanks = $karma->user->thanks->count(); $karma = $karma->target->karma->count(); if ($thanks === 10 && $karma === 0) { $this->create($karma->user, $karma->created_at); } }); }
/** * Execute the console command. * * @param Repository $config * @param Container $container * * @return mixed * @throws \InvalidArgumentException * @throws \RuntimeException * @throws \LogicException * @throws \Exception */ public function handle(Repository $config, Container $container) { $this->syncUsers($config, $container); $config->set('gitter.output', false); $client = Client::make($config->get('gitter.token'), $this->argument('room')); $room = $container->make(Room::class); $this->karma = new Validator(); $request = $this->cursor($client, $room); $count = 1; // Start number $page = 0; // Current page $chunk = 100; // Per page while (true) { $messageChunk = $request($chunk, $chunk * $page++); if (!count($messageChunk)) { $this->output->write(sprintf("\r Well done. <comment>%s</comment> Messages was be loaded.", $count)); break; } foreach ($messageChunk as $m) { echo "\rLoad message: {$count} "; $count++; } $name = 'sync/' . $page . '.json'; echo '...dump to ' . $name; file_put_contents(storage_path($name), json_encode($messageChunk)); } echo "\n"; $this->output->write('Flush database karma increments'); Karma::query()->where('room_id', $room->id)->delete(); $this->output->write('Start message parsing.'); $finder = (new Finder())->files()->in(storage_path('sync'))->name('*.json')->sort(function ($a, $b) { $parse = function (\SplFileInfo $file) { return str_replace('.json', '', $file->getFilename()); }; return $parse($b) <=> $parse($a); }); $count = 1; foreach ($finder as $file) { $messages = json_decode($file->getContents(), true); foreach ($messages as $message) { $message = Message::fromGitterObject($message); echo "\r" . $count++ . ' messages parsing: ' . $message->created_at; usleep(100); $this->onMessage($message); } unlink($file->getRealPath()); } }
/** * @param User $user * @param Message $message * @return static */ public function addKarmaTo(User $user, Message $message) { return Karma::create(['room_id' => \App::make(Room::class)->id, 'message_id' => $message->gitter_id, 'user_id' => $this->id, 'user_target_id' => $user->id, 'created_at' => $message->created_at]); }