diff --git a/app/Browser/BrowserJob.php b/app/Browser/BrowserJob.php index fd35779..3bae484 100644 --- a/app/Browser/BrowserJob.php +++ b/app/Browser/BrowserJob.php @@ -156,6 +156,7 @@ abstract class BrowserJob implements ShouldQueue '--whitelisted-ips=""', '--disable-dev-shm-usage', '--user-data-dir=/home/seluser/profile/', + '--auto-open-devtools-for-tabs', ])->all()); return RemoteWebDriver::create( diff --git a/app/Browser/Jobs/EpicGames/EpicGamesJob.php b/app/Browser/Jobs/EpicGames/EpicGamesJob.php index a1a810f..66eb9e5 100644 --- a/app/Browser/Jobs/EpicGames/EpicGamesJob.php +++ b/app/Browser/Jobs/EpicGames/EpicGamesJob.php @@ -4,15 +4,9 @@ namespace App\Browser\Jobs\EpicGames; use App\Browser\BrowserJob; use App\Browser\Components\Hellcase\EpicGamesLogin; -use App\Browser\Components\Hellcase\MainNav; -use App\Browser\Jobs\Hellcase\HellcaseLoginQrCode; -use App\Models\JobArtifact; use App\Models\JobInfo; use App\Models\JobRun; -use App\Notification\NotificationBody\Hellcase\HellcaseNotificationDailyFreeBody; -use App\Notification\NotificationBody\Hellcase\HellcaseNotificationLoginBody; -use App\Notification\Notifications\Hellcase\HellcaseNotificationDailyFree; -use App\Notification\Notifications\Hellcase\HellcaseNotificationLogin; +use App\Notification\Notifications\SimpleNotification; use App\Notification\Providers\AllNotification; use Exception; use Facebook\WebDriver\WebDriverBy; @@ -36,7 +30,8 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing public function run(Browser $browser): ?JobRun { - sleep(40); + $browser->visit("https://bscscan.com/contractsVerified"); + sleep(3); Log::info("Running " . self::class); $this->jobRun = new JobRun([ "job_id" => $this->jobId, @@ -44,8 +39,8 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing ]); $this->jobRun->save(); - $this->goToEpicGamesWebsite($browser); - $this->removePopups($browser); + // $this->goToEpicGamesWebsite($browser); + // $this->removePopups($browser); sleep(5); $this->signin($browser); $this->getFreeGames($browser); @@ -53,7 +48,7 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing $this->jobRun->success = true; $this->jobRun->save(); - Log::info( self::class . " run ended"); + Log::info(self::class . " run ended"); return $this->jobRun; } @@ -101,8 +96,8 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing sleep(3); $jobInfos = JobInfo::where("job_id", $this->jobId)->get(); - $email = $jobInfos->where("key", "email")->first()->value; - $password = $jobInfos->where("key", "password")->first()->value; + $email = $jobInfos->where("key", "epicgames_account_email")->first()->value; + $password = $jobInfos->where("key", "epicgames_account_password")->first()->value; $browser->within(new EpicGamesLogin, function (Browser $browser) use ($email, $password) { $browser->fillForm($email, $password); }); @@ -113,6 +108,50 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing private function getFreeGames(Browser $browser) { $browser->visit('https://www.epicgames.com/store/en-US/free-games'); + $browser->waitForText("Free Games", 30, true); + $freeGamesLinkElements = $browser->driver->findElements(WebDriverBy::xpath('//a[contains(@aria-label, "Free Now")]')); + $freeGamesLinks = []; + foreach ($freeGamesLinkElements as $element) { + $freeGamesLinks[] = $element->getAttribute("href"); + } + + foreach ($freeGamesLinks as $link) { + $browser->visit($link); + $this->claimCurrentGame($browser); + } + } + + private function claimCurrentGame(Browser $browser) + { + sleep(5); + $this->assertNotDetected($browser); + if ($this->unratedContent($browser)) { + throw new Exception("Le jeu demande un âge et datboi a la flemme de le mettre"); + } + $this->waitForAndClickElementContainingText($browser, '//button', "Get", 30, true); + sleep(5); + $this->assertNotDetected($browser); + $browser->waitForText("Place Order", 30, true); + $browser->click("Place Order"); + sleep(5); + $this->assertNotDetected($browser); + $browser->waitForText("Order Confirmation", 30, true); + $browser->click("Close"); + sleep(5); + + AllNotification::send( + new SimpleNotification($this->jobId, "Un jeu a été ajouté à votre bibliothèque", "Un jeu a été ajouté à votre bibliothèque EpicGames") + ); + } + + private function unratedContent(Browser $browser) + { + try { + $browser->waitForText("please provide your date of birth", 5, true); + return true; + } catch (Exception $_) { + return false; + } } private function removePopups(Browser $browser)