Added Hellcase Battle job
All checks were successful
Push image to registry / build-image (push) Successful in 5m59s
All checks were successful
Push image to registry / build-image (push) Successful in 5m59s
Still need testing and making proper notifications
This commit is contained in:
@ -25,12 +25,12 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
private const STEAM_LOGIN_THRESHOLD = 5 * 60; // 5 minutes
|
private const STEAM_LOGIN_THRESHOLD = 5 * 60; // 5 minutes
|
||||||
private const APPROXIMATIVE_RUNNING_MINUTES = 2;
|
private const APPROXIMATIVE_RUNNING_MINUTES = 2;
|
||||||
|
|
||||||
private JobRun $jobRun;
|
protected JobRun $jobRun;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct($jobId = 2)
|
||||||
{
|
{
|
||||||
Log::info("Constructing HellcaseJob");
|
Log::info("Constructing HellcaseJob");
|
||||||
parent::__construct(2);
|
parent::__construct($jobId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(Browser $browser): ?JobRun
|
public function run(Browser $browser): ?JobRun
|
||||||
@ -89,7 +89,7 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function signin(Browser $browser)
|
protected function signin(Browser $browser)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$browser->clickAtXPath('//button[.//span[text() = "Sign in"]]');
|
$browser->clickAtXPath('//button[.//span[text() = "Sign in"]]');
|
||||||
@ -390,7 +390,7 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
$browser->clickAtXPath('//*[contains(text(), "Edit Profile")]');
|
$browser->clickAtXPath('//*[contains(text(), "Edit Profile")]');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removePopups(Browser $browser)
|
protected function removePopups(Browser $browser)
|
||||||
{
|
{
|
||||||
// $browser->script('document.querySelector("div.app-modal")[0].remove();');
|
// $browser->script('document.querySelector("div.app-modal")[0].remove();');
|
||||||
// $browser->driver->executeScript('document.querySelector("div.app-modal")[0].remove();');
|
// $browser->driver->executeScript('document.querySelector("div.app-modal")[0].remove();');
|
||||||
|
145
app/Browser/Jobs/HellcaseBattles/HellcaseBattlesJob.php
Normal file
145
app/Browser/Jobs/HellcaseBattles/HellcaseBattlesJob.php
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Browser\Jobs\HellcaseBattles;
|
||||||
|
|
||||||
|
use App\Browser\Jobs\Hellcase\HellcaseJob;
|
||||||
|
use App\Models\HellcaseBattle;
|
||||||
|
use App\Models\Job;
|
||||||
|
use App\Models\JobRun;
|
||||||
|
use App\Notification\Notifications\JobDebugNotification;
|
||||||
|
use App\Notification\Providers\AllNotification;
|
||||||
|
use Exception;
|
||||||
|
use Facebook\WebDriver\WebDriver;
|
||||||
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
|
||||||
|
class HellcaseBattlesJob extends HellcaseJob implements ShouldBeUniqueUntilProcessing
|
||||||
|
{
|
||||||
|
private Collection $jobInfos;
|
||||||
|
private array $battlesToAdd = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
Log::info("Constructing HellcaseBattlesJob");
|
||||||
|
parent::__construct(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run(Browser $browser): ?JobRun
|
||||||
|
{
|
||||||
|
$this->jobInfos = Job::find($this->jobId)->jobInfosTable();
|
||||||
|
Log::info("Running HellcaseBattlesJob");
|
||||||
|
$this->jobRun = new JobRun([
|
||||||
|
"job_id" => $this->jobId,
|
||||||
|
"success" => false,
|
||||||
|
]);
|
||||||
|
$this->jobRun->save();
|
||||||
|
|
||||||
|
$browser->visit('https://hellcase.com');
|
||||||
|
$browser->waitForText("CASES", 30, true);
|
||||||
|
$this->removePopups($browser);
|
||||||
|
sleep(5);
|
||||||
|
$this->signin($browser);
|
||||||
|
|
||||||
|
$this->saveInterestingBattles($browser);
|
||||||
|
|
||||||
|
$this->sendFinishedBattles($browser);
|
||||||
|
|
||||||
|
$this->createNewBattles();
|
||||||
|
|
||||||
|
$this->jobRun->success = true;
|
||||||
|
$this->jobRun->save();
|
||||||
|
|
||||||
|
Log::info("HellcaseBattlesJob run ended");
|
||||||
|
|
||||||
|
return $this->jobRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save current cases battles to database for later processing
|
||||||
|
* @param \Laravel\Dusk\Browser $browser
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function saveInterestingBattles(Browser $browser)
|
||||||
|
{
|
||||||
|
$battleIndex = 0; // Index of the battle to get info from
|
||||||
|
$running = true;
|
||||||
|
while ($running) {
|
||||||
|
$browser->visit('https://hellcase.com/casebattle');
|
||||||
|
$browser->waitForText("CASES", 30, true);
|
||||||
|
|
||||||
|
AllNotification::send(new JobDebugNotification($this->jobId, "I hate niggers"));
|
||||||
|
|
||||||
|
// Sort by price
|
||||||
|
try {
|
||||||
|
$sortByPriceDiv = $browser->driver->findElement(WebDriverBy::xpath("//*[span[contains(text(), 'Value')]]"));
|
||||||
|
$sortByPriceDiv->click();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
AllNotification::send(new JobDebugNotification($this->jobId, "Failed to sort by price"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
$battles = $browser->driver->findElements(WebDriverBy::xpath("//*[contains(@class, 'casebattle-table__item')]"));
|
||||||
|
$battle = $battles[$battleIndex];
|
||||||
|
$battleIndex++;
|
||||||
|
$browser->scrollIntoView(".casebattle-table__item:nth-child(" . max($battleIndex -1, 1) . ")");
|
||||||
|
sleep(2);
|
||||||
|
$battleValue = floatval(
|
||||||
|
explode(
|
||||||
|
"\n",
|
||||||
|
$battle->findElement(WebDriverBy::xpath("./div/div[contains(@class, 'core-price')]"))->getDomProperty("innerText")
|
||||||
|
)[1]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($battleValue < floatval($this->jobInfos->get("hellcase_battles_minimum_value"))) {
|
||||||
|
$running = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$battleLinkButton = $battle->findElement(WebDriverBy::xpath('./div//button[text() = "watch"]'));
|
||||||
|
$battleLinkButton->sendKeys("\n");
|
||||||
|
sleep(3);
|
||||||
|
$battleLink = $browser->driver->getCurrentURL();
|
||||||
|
|
||||||
|
$this->battlesToAdd[$battleLink] = $battleValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendFinishedBattles(Browser $browser) {
|
||||||
|
// foreach battle that we didn"t already planned to add with $this->battlesToAdd
|
||||||
|
foreach (HellcaseBattle::all() as $battle) {
|
||||||
|
dump($battle);
|
||||||
|
if (!array_key_exists($battle->getUrl(), $this->battlesToAdd)) {
|
||||||
|
dump("finished");
|
||||||
|
$browser->visit($battle->getUrl());
|
||||||
|
|
||||||
|
try {
|
||||||
|
$browser->waitForText("Started at");
|
||||||
|
// Send the battle
|
||||||
|
$this->sendBattle($browser, $battle);
|
||||||
|
} catch (Exception $e) { // Battle is not finished or error (like battle cancelled)
|
||||||
|
}
|
||||||
|
|
||||||
|
$battle->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendBattle(Browser $browser, HellcaseBattle $battle) {
|
||||||
|
AllNotification::send(new JobDebugNotification($this->jobId, "Battle sent" . $battle->getUrl()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createNewBattles() {
|
||||||
|
foreach ($this->battlesToAdd as $battleLink => $battleValue) {
|
||||||
|
$battleLink = explode("/", $battleLink);
|
||||||
|
HellcaseBattle::firstOrCreate([
|
||||||
|
"battle_id" => $battleLink[count($battleLink) - 1],
|
||||||
|
"value" => $battleValue,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
app/Models/HellcaseBattle.php
Normal file
17
app/Models/HellcaseBattle.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class HellcaseBattle extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
"battle_id",
|
||||||
|
"value",
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getUrl() {
|
||||||
|
return "https://hellcase.com/casebattle/{$this->battle_id}";
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,16 @@ class Job extends Model
|
|||||||
return $this->hasMany(JobInfo::class)->with("jobInfoType")->orderBy("created_at");
|
return $this->hasMany(JobInfo::class)->with("jobInfoType")->orderBy("created_at");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an associative collection of the job infos with their values
|
||||||
|
* @return \Illuminate\Database\Eloquent\Collection<string, string>>
|
||||||
|
*/
|
||||||
|
public function jobInfosTable() {
|
||||||
|
return $this->jobInfos->mapWithKeys(function ($jobInfo) {
|
||||||
|
return [$jobInfo->key => $jobInfo->value];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function jobRuns()
|
public function jobRuns()
|
||||||
{
|
{
|
||||||
return $this->hasMany(JobRun::class)->orderBy("created_at");
|
return $this->hasMany(JobRun::class)->orderBy("created_at");
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Job;
|
||||||
|
use App\Models\JobInfo;
|
||||||
|
use App\Models\JobInfoType;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$newJobId = 3;
|
||||||
|
Job::forceCreate([
|
||||||
|
"id" => $newJobId,
|
||||||
|
"name" => "Hellcase Battles",
|
||||||
|
"description" => "Envoie les meilleures battles d'Hellcase",
|
||||||
|
]);
|
||||||
|
|
||||||
|
JobInfo::forceCreate([
|
||||||
|
"key" => "hellcase_battles_discord_webhook_url",
|
||||||
|
"name" => "Webhook Discord",
|
||||||
|
"description" => "Le lien discord webhook utilisé pour envoyer les meilleures battles d'Hellcase.\nSi aucun n'est spécifié, le webhook Discord des paramètres généraux sera utilisé.",
|
||||||
|
"placeholder" => "https://discord.com/api/webhooks/...",
|
||||||
|
"is_required" => false,
|
||||||
|
"job_info_type_id" => 4,
|
||||||
|
"job_id" => $newJobId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
JobInfoType::forceCreate([
|
||||||
|
"id" => 5,
|
||||||
|
"name" => "number",
|
||||||
|
]);
|
||||||
|
JobInfoType::forceCreate([
|
||||||
|
"id" => 6,
|
||||||
|
"name" => "boolean",
|
||||||
|
]);
|
||||||
|
|
||||||
|
JobInfo::forceCreate([
|
||||||
|
"key" => "hellcase_battles_minimum_value",
|
||||||
|
"name" => "Valeur minimum des battles",
|
||||||
|
"description" => "La valeur minimale qu'une battle doit avoir pour être envoyée, en euros.",
|
||||||
|
"placeholder" => "1000",
|
||||||
|
"job_info_type_id" => 5,
|
||||||
|
"job_id" => $newJobId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
JobInfo::forceCreate([
|
||||||
|
"key" => "hellcase_battles_allow_bots",
|
||||||
|
"name" => "Autoriser les battles avec bots",
|
||||||
|
"description" => "Envoyer les battles avec un seul joueur et des bots.",
|
||||||
|
"is_required" => false,
|
||||||
|
"job_info_type_id" => 6,
|
||||||
|
"job_id" => $newJobId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Schema::create('hellcase_battles', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
|
||||||
|
$table->string("battle_id")->unique();
|
||||||
|
$table->float("value");
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Job::where("id", 3)->delete();
|
||||||
|
JobInfo::where("job_id", 3)->delete();
|
||||||
|
JobInfoType::whereIn("id", [5, 6])->delete();
|
||||||
|
|
||||||
|
Schema::dropIfExists('hellcase_battles');
|
||||||
|
}
|
||||||
|
};
|
@ -18,7 +18,7 @@ const jobInfoType = props.jobInfo.job_info_type.name;
|
|||||||
<div>
|
<div>
|
||||||
<Label :for="'' + jobInfo.id" class="text">{{ jobInfo.name }}<span v-if="jobInfo.is_required" class="cursor-help" title="Requis" aria-label="Requis">*</span></Label>
|
<Label :for="'' + jobInfo.id" class="text">{{ jobInfo.name }}<span v-if="jobInfo.is_required" class="cursor-help" title="Requis" aria-label="Requis">*</span></Label>
|
||||||
<Description>{{ jobInfo.description }}</Description>
|
<Description>{{ jobInfo.description }}</Description>
|
||||||
<Input v-if="jobInfoType != 'checkbox'" :type="jobInfoType" :id="'' + jobInfo.id" :name="'' + jobInfo.id" :placeholder="jobInfo.placeholder" v-model="jobInfo.value as string" :required="jobInfo.is_required" />
|
<Input v-if="['text', 'email', 'password', 'url', 'number'].includes(jobInfoType)" :type="jobInfoType" :id="'' + jobInfo.id" :name="'' + jobInfo.id" :placeholder="jobInfo.placeholder" v-model="jobInfo.value as string" :required="jobInfo.is_required" />
|
||||||
<VModelCheckbox v-else :id="'' + jobInfo.id" :class="''" v-model="jobInfo.value as boolean" />
|
<VModelCheckbox v-else :id="'' + jobInfo.id" :class="''" v-model="jobInfo.value as boolean" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ Route::get('/jobs', function (Request $request) {
|
|||||||
|
|
||||||
Route::get('/test/{id}', function (Request $request, $id, BrowserJobsInstances $BrowserJobsInstances) {
|
Route::get('/test/{id}', function (Request $request, $id, BrowserJobsInstances $BrowserJobsInstances) {
|
||||||
$log = $BrowserJobsInstances->getJobInstance($id)->execute();
|
$log = $BrowserJobsInstances->getJobInstance($id)->execute();
|
||||||
|
dump($log);
|
||||||
return response()->json(['message' => 'Job ' . $id . ' ran', 'jobRun' => $log->load('artifacts')]);
|
return response()->json(['message' => 'Job ' . $id . ' ran', 'jobRun' => $log->load('artifacts')]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Browser\Jobs\Hellcase\HellcaseJob;
|
use App\Browser\Jobs\Hellcase\HellcaseJob;
|
||||||
|
use App\Browser\Jobs\HellcaseBattles\HellcaseBattlesJob;
|
||||||
use App\Jobs\PruneOldJobRuns;
|
use App\Jobs\PruneOldJobRuns;
|
||||||
use App\Services\BrowserJobsInstances;
|
use App\Services\BrowserJobsInstances;
|
||||||
use Illuminate\Foundation\Inspiring;
|
use Illuminate\Foundation\Inspiring;
|
||||||
@ -21,3 +22,4 @@ Schedule::job(new PruneOldJobRuns)->monthly()->onOneServer()->withoutOverlapping
|
|||||||
// Jobs
|
// Jobs
|
||||||
Schedule::job(new HellcaseJob)->daily()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job');
|
Schedule::job(new HellcaseJob)->daily()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job');
|
||||||
// Schedule::job(new HellcaseJob)->everyMinute()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job');
|
// Schedule::job(new HellcaseJob)->everyMinute()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job');
|
||||||
|
Schedule::job(new HellcaseBattlesJob)->hourly()->onOneServer()->withoutOverlapping()->name('hellcase_battles')->description('Hellcase battles job');
|
||||||
|
3
todo.md
3
todo.md
@ -13,6 +13,9 @@
|
|||||||
- Websocket installé
|
- Websocket installé
|
||||||
- Serveur php plus propre (nginx, apache, n'importe)
|
- Serveur php plus propre (nginx, apache, n'importe)
|
||||||
- Epic games
|
- Epic games
|
||||||
|
Pas l'air possible avec cloudflare
|
||||||
|
- Petit bug, quand l'on enregistre un formulaire avec une erreur, l'url a un argument GET ?error=mon%24erreur
|
||||||
|
Du coup dans la nav le job actuel n'est plus reconnu
|
||||||
|
|
||||||
## Pour deploy Lama
|
## Pour deploy Lama
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user