Implement creator studio and upload updates
This commit is contained in:
38
app/Services/Moderation/Rules/RegexPatternRule.php
Normal file
38
app/Services/Moderation/Rules/RegexPatternRule.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Moderation\Rules;
|
||||
|
||||
use App\Contracts\Moderation\ModerationRuleInterface;
|
||||
use App\Services\Moderation\ModerationRuleRegistryService;
|
||||
|
||||
class RegexPatternRule implements ModerationRuleInterface
|
||||
{
|
||||
public function analyze(string $content, string $normalized, array $context = []): array
|
||||
{
|
||||
$registry = \app(ModerationRuleRegistryService::class);
|
||||
$findings = [];
|
||||
|
||||
foreach ($registry->regexRules() as $rule) {
|
||||
$pattern = (string) ($rule['pattern'] ?? '');
|
||||
if ($pattern === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$matched = @preg_match($pattern, $content) === 1 || @preg_match($pattern, $normalized) === 1;
|
||||
if (! $matched) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$findings[] = [
|
||||
'rule' => 'regex_pattern',
|
||||
'score' => (int) ($rule['weight'] ?? \app('config')->get('content_moderation.weights.regex_pattern', 30)),
|
||||
'reason' => 'Matched custom moderation regex rule',
|
||||
'links' => [],
|
||||
'domains' => [],
|
||||
'keywords' => [$pattern],
|
||||
];
|
||||
}
|
||||
|
||||
return $findings;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user