downloadFolder = base_path($this->downloadFolder); } public function run(Browser $browser): ?JobRun { $startTime = microtime(true); Log::info("Running EldoradoRobuxPriceSentryJob"); $this->jobInfos = Job::find($this->jobId)->jobInfosTable(); $this->jobRun = new JobRun([ "job_id" => $this->jobId, "success" => false, ]); $this->jobRun->save(); dump("visiting " . microtime(true) - $startTime); $browser->visit(self::LINK); sleep(5); $this->sendPrices($browser); $this->jobRun->success = true; $this->jobRun->save(); Log::info("EldoradoRobuxPriceSentryJob run ended"); return $this->jobRun; } /** * @inheritDoc */ public function runTest(Browser $browser): ?JobRun { $this->jobInfos = Job::find($this->jobId)->jobInfosTable(); try { $browser->visit(self::LINK); sleep(5); return $this->makeSimpleJobRun( true, "Test réussi", "Datboi a réussi à charger la page Eldorado." ); } catch (\Exception $e) { return $this->makeSimpleJobRun( false, "Test échoué", "Datboi n'a pas réussi à charger la page Eldorado :\n" . $e->getMessage() ); } } private function sendPrices(Browser $browser): void { $lowestPriceElement = $browser->driver->findElement(WebDriverBy::xpath('(//eld-offer-price)[2]/strong')); $lowestPriceText = $lowestPriceElement->getText(); // Ex: " 0,00478 € " $lowestPrice = $this->textToFloat($lowestPriceText); //$lowestPrice = $lowestPrice / 1000; // Price per Robux // TODO : Look at the entire text to try to understand if it is per 1k or per single Robux $threshold = $this->textToFloat($this->jobInfos->get("eldorado_robux_price_threshold")); Log::info("EldoradoRobuxPriceSentryJob: lowest price = $lowestPrice €, threshold = $threshold €"); $this->jobRun->addArtifact(new JobArtifact([ "name" => "Trouvé le prix le plus bas", "content" => "Prix le plus bas : $lowestPrice €/Robux - Seuil défini : $threshold €/Robux" ])); if ($lowestPrice <= $threshold) { $options = []; if ($this->jobInfos->get("eldorado_robux_price_discord_webhook") !== null) { // Custom discord webhook $options["discord_webhook_url"] = $this->jobInfos->get("eldorado_robux_price_discord_webhook"); } AllNotification::send( new EldoradoRobuxPriceNotification( $this->jobId, $lowestPrice, self::LINK ), $options ); $this->jobRun->addArtifact(new JobArtifact([ "name" => "Envoyé une alerte", "content" => "" ])); Log::info("EldoradoRobuxPriceSentryJob: alert sent"); } else { Log::info("EldoradoRobuxPriceSentryJob: no alert sent"); } } private function textToFloat(string $text): float { return floatval(str_replace(["€", ","], ["", "."], trim($text))); } }