mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-12-05 08:44:59 -06:00
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\Moderation\CheckChatMessageRequest;
|
|
use App\Http\Requests\Api\Player\CheckUsernameRequest;
|
|
use App\Http\Responses\Api\Player\CheckUsernameResponse;
|
|
use App\Models\Admin\BadChatMessage;
|
|
use App\Models\User\User;
|
|
use ConsoleTVs\Profanity\Builder;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ModerationController extends Controller
|
|
{
|
|
|
|
public function checkUsername(CheckUsernameRequest $request): mixed
|
|
{
|
|
return json_encode(new CheckUsernameResponse($request->userId, $request->username));
|
|
}
|
|
|
|
public function checkChatMessage(CheckChatMessageRequest $request): mixed
|
|
{
|
|
// Lobby Host that send the request to check the message. We log him too since only the lobby host checks the messages in teh backend.
|
|
$hostUser = Auth::user();
|
|
// User that send the chat message
|
|
$messageUser = User::find($request->userId);
|
|
|
|
$checker = Builder::blocker($request->message);
|
|
|
|
if($checker->clean())
|
|
return response('{}');
|
|
|
|
$this->logBadMessage($hostUser, $messageUser, $request->message);
|
|
return response('Bad Message >:(');
|
|
}
|
|
|
|
public function logBadMessage(User $hostUser, User $messageUser, string $message): void {
|
|
$badMessage = new BadChatMessage();
|
|
$badMessage->hostUser()->associate($hostUser);
|
|
$badMessage->user()->associate($messageUser);
|
|
$badMessage->message = $message;
|
|
$badMessage->save();
|
|
}
|
|
}
|