mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-04-26 02:00:32 -05:00
Added Database Table for detected bad chat messages and add them automatically if the profanity filter detects something.
This commit is contained in:
parent
4e81dec317
commit
b411a34189
19
Deathgarden Rebirth Bruno/Moderation/Check Chat Message.bru
Normal file
19
Deathgarden Rebirth Bruno/Moderation/Check Chat Message.bru
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
meta {
|
||||
name: Check Chat Message
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{base_url}}/moderation/check/chat
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"userId": "9b70b902-1a13-474b-b5d3-4de3d07ad971",
|
||||
"language": "en",
|
||||
"message": "Fuck"
|
||||
}
|
||||
}
|
||||
|
|
@ -3,20 +3,37 @@
|
|||
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 Illuminate\Http\Request;
|
||||
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)
|
||||
public function checkUsername(CheckUsernameRequest $request): mixed
|
||||
{
|
||||
return json_encode(new CheckUsernameResponse($request->userId, $request->username));
|
||||
}
|
||||
|
||||
public function checkChatMessage()
|
||||
public function checkChatMessage(CheckChatMessageRequest $request): mixed
|
||||
{
|
||||
return ['message' => 'TEst'];
|
||||
$checker = Builder::blocker($request->message);
|
||||
|
||||
if($checker->clean())
|
||||
return response('{}');
|
||||
|
||||
$this->logBadMessage(Auth::user(), $request->message);
|
||||
return response('Bad Message >:(');
|
||||
}
|
||||
|
||||
public function logBadMessage(User $user, string $message): void {
|
||||
$badMessage = new BadChatMessage();
|
||||
$badMessage->user()->associate($user);
|
||||
$badMessage->message = $message;
|
||||
$badMessage->save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
44
dist/app/Http/Requests/Api/Moderation/CheckChatMessageRequest.php
vendored
Normal file
44
dist/app/Http/Requests/Api/Moderation/CheckChatMessageRequest.php
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api\Moderation;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CheckChatMessageRequest extends FormRequest
|
||||
{
|
||||
public string $userId;
|
||||
|
||||
public string $language;
|
||||
|
||||
public string $message;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'userId' => 'required|string',
|
||||
'language' => 'required|string',
|
||||
'message' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
protected function passedValidation()
|
||||
{
|
||||
$this->userId = $this->input('userId');
|
||||
$this->language = $this->input('language');
|
||||
$this->message = $this->input('message');
|
||||
}
|
||||
}
|
||||
18
dist/app/Models/Admin/BadChatMessage.php
vendored
Normal file
18
dist/app/Models/Admin/BadChatMessage.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Admin;
|
||||
|
||||
use App\Models\User\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperBadChatMessage
|
||||
*/
|
||||
class BadChatMessage extends Model
|
||||
{
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
1
dist/composer.json
vendored
1
dist/composer.json
vendored
|
|
@ -6,6 +6,7 @@
|
|||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"consoletvs/profanity": "^3.5",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"inertiajs/inertia-laravel": "^0.6.11",
|
||||
"laravel/framework": "^10.10",
|
||||
|
|
|
|||
52
dist/composer.lock
generated
vendored
52
dist/composer.lock
generated
vendored
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "bc7340d8711858868364f6bc0b967874",
|
||||
"content-hash": "84fc198222d09443ec024ca2075cf0f8",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
|
|
@ -130,6 +130,56 @@
|
|||
],
|
||||
"time": "2023-12-11T17:09:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "consoletvs/profanity",
|
||||
"version": "3.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ConsoleTVs/Profanity.git",
|
||||
"reference": "88569bd5cd95ef90f672288b2c99099fccf298e6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ConsoleTVs/Profanity/zipball/88569bd5cd95ef90f672288b2c99099fccf298e6",
|
||||
"reference": "88569bd5cd95ef90f672288b2c99099fccf298e6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/support": "5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*|10.*|11.*"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"ConsoleTVs\\Profanity\\ProfanityServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Profanity": "ConsoleTVs\\Profanity\\Facades\\Profanity"
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ConsoleTVs\\Profanity\\": "."
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Erik Campobadal",
|
||||
"email": "ConsoleTVs@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "PHP library to block bad words in a string",
|
||||
"support": {
|
||||
"issues": "https://github.com/ConsoleTVs/Profanity/issues",
|
||||
"source": "https://github.com/ConsoleTVs/Profanity/tree/3.5.0"
|
||||
},
|
||||
"time": "2024-07-03T20:59:42+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dflydev/dot-access-data",
|
||||
"version": "v3.0.2",
|
||||
|
|
|
|||
31
dist/database/migrations/2024_07_23_194650_create_bad_chat_messages_table.php
vendored
Normal file
31
dist/database/migrations/2024_07_23_194650_create_bad_chat_messages_table.php
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
Schema::create('bad_chat_messages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignUuid('user_id')->constrained();
|
||||
$table->text('message');
|
||||
$table->boolean('handled')->default(false);
|
||||
$table->text('consequences')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bad_chat_messages');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user