Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

HDInnovations/UNIT3D-Community-Edition

2239 stars
1 code files
View HDInnovations/UNIT3D-Community-Edition on GitHub

app/Console/Commands/AutoBan.php

Open in GitHub
use App\Mail\BanUser;
use App\Models\Ban;
use App\Models\Group;
use App\Models\Warning;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
 
class AutoBan extends Command
{
protected $signature = 'auto:ban';
 
public function handle()
{
$bannedGroup = \cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
 
$bans = Warning::with('warneduser')->select(DB::raw('user_id, count(*) as value'))->where('active', '=', 1)->groupBy('user_id')->having('value', '>=', \config('hitrun.max_warnings'))->get();
 
foreach ($bans as $ban) {
if ($ban->warneduser->group_id != $bannedGroup[0] && ! $ban->warneduser->group->is_immune) {
$ban->warneduser->group_id = $bannedGroup[0];
$ban->warneduser->can_upload = 0;
$ban->warneduser->can_download = 0;
$ban->warneduser->can_comment = 0;
$ban->warneduser->can_invite = 0;
$ban->warneduser->can_request = 0;
$ban->warneduser->can_chat = 0;
$ban->warneduser->save();
 
$logban = new Ban();
$logban->owned_by = $ban->warneduser->id;
$logban->created_by = 1;
$logban->ban_reason = 'Warning Limit Reached, has '.$ban->value.' warnings.';
$logban->unban_reason = '';
$logban->save();
 
Mail::to($ban->warneduser->email)->send(new BanUser($ban->warneduser->email, $logban));
}
}
$this->comment('Automated User Banning Command Complete');
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.