Skip to content

Commit

Permalink
Merge pull request #2480 from HDInnovations/6.x.x
Browse files Browse the repository at this point in the history
(Release) v6.5.0
  • Loading branch information
HDVinnie authored Dec 13, 2022
2 parents ae31422 + f3989a7 commit 235fa69
Show file tree
Hide file tree
Showing 259 changed files with 14,006 additions and 13,054 deletions.
81 changes: 0 additions & 81 deletions app/Console/Commands/AutoBan.php

This file was deleted.

47 changes: 31 additions & 16 deletions app/Console/Commands/AutoDeactivateWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

namespace App\Console\Commands;

use App\Models\PrivateMessage;
use App\Models\Warning;
use App\Notifications\UserManualWarningExpire;
use App\Notifications\UserWarningExpire;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;

/**
* @see \Tests\Unit\Console\Commands\AutoDeactivateWarningTest
Expand All @@ -43,25 +45,38 @@ class AutoDeactivateWarning extends Command
public function handle(): void
{
$current = Carbon::now();
$warnings = Warning::with(['warneduser', 'torrenttitle'])->where('active', '=', 1)->where('expires_on', '<', $current)->get();
$warnings = Warning::with(['warneduser', 'torrenttitle'])
->where('active', '=', 1)
->get();

foreach ($warnings as $warning) {
// Set Records Active To 0 in warnings table
$warning->active = '0';
$warning->save();
if ($warning->expires_on <= $current || ($warning->torrenttitle && $warning->torrenttitle->history()->where('user_id', '=', $warning->warneduser->id)->first()->seedtime >= \config('hitrun.seedtime'))) {
// Set Records Active To 0 in warnings table
$warning->active = '0';
$warning->save();

// Send Private Message
$pm = new PrivateMessage();
$pm->sender_id = 1;
$pm->receiver_id = $warning->warneduser->id;
$pm->subject = 'Hit and Run Warning Deactivated';
if (isset($warning->torrent)) {
$pm->message = 'The [b]WARNING[/b] you received relating to Torrent '.$warning->torrenttitle->name.' has expired! Try not to get more! [color=red][b]THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]';
} else {
$pm->message = 'The [b]WARNING[/b] you received: "'.$warning->reason.'" has expired! [color=red][b]THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]';
// Send Notifications
if ($warning->torrenttitle) {
$warning->warneduser->notify(new UserWarningExpire($warning->warneduser, $warning->torrenttitle));
} else {
$warning->warneduser->notify(new UserManualWarningExpire($warning->warneduser, $warning));
}
}
}

// Calculate User Warning Count and Enable DL Priv If Required.
$warnings = Warning::with('warneduser')
->select(DB::raw('user_id, count(*) as value'))
->where('active', '=', 1)
->groupBy('user_id')
->having('value', '<', \config('hitrun.max_warnings'))
->get();

$pm->save();
foreach ($warnings as $warning) {
if ($warning->warneduser->can_download === 0) {
$warning->warneduser->can_download = 1;
$warning->warneduser->save();
}
}

$this->comment('Automated Warning Deativation Command Complete');
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/AutoDisableInactiveUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle(): void
->all();

foreach ($users as $user) {
if ($user->getSeeding() === 0) {
if ($user->seedingTorrents()->count() === 0) {
$user->group_id = $disabledGroup[0];
$user->can_upload = 0;
$user->can_download = 0;
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/AutoGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function handle(ByteUnits $byteUnits): void
}

// Seeder Seedsize >= 5TiB and account 1 month old and seedtime average 30 days or better
if ($user->getTotalSeedSize() >= $byteUnits->bytesFromUnit('5TiB') && $user->getRatio() >= \config('other.ratio') && \round($user->getTotalSeedTime() / \max(1, $hiscount)) > 2_592_000 && $user->created_at < $current->copy()->subDays(30)->toDateTimeString() && $user->group_id != UserGroups::SEEDER) {
if ($user->seedingTorrents()->sum('size') >= $byteUnits->bytesFromUnit('5TiB') && $user->getRatio() >= \config('other.ratio') && \round($user->history()->sum('seedtime') / \max(1, $hiscount)) > 2_592_000 && $user->created_at < $current->copy()->subDays(30)->toDateTimeString() && $user->group_id != UserGroups::SEEDER) {
$user->group_id = UserGroups::SEEDER;
$user->save();
}
Expand All @@ -108,7 +108,7 @@ public function handle(ByteUnits $byteUnits): void
}

// Archivist Seedsize >= 10TiB and account 3 month old and seedtime average 60 days or better
if ($user->getTotalSeedSize() >= $byteUnits->bytesFromUnit('10TiB') && $user->getRatio() >= \config('other.ratio') && \round($user->getTotalSeedTime() / \max(1, $hiscount)) > 2_592_000 * 2 && $user->created_at < $current->copy()->subDays(90)->toDateTimeString() && $user->group_id != UserGroups::ARCHIVIST) {
if ($user->seedingTorrents()->sum('size') >= $byteUnits->bytesFromUnit('10TiB') && $user->getRatio() >= \config('other.ratio') && \round($user->history()->sum('seedtime') / \max(1, $hiscount)) > 2_592_000 * 2 && $user->created_at < $current->copy()->subDays(90)->toDateTimeString() && $user->group_id != UserGroups::ARCHIVIST) {
$user->group_id = UserGroups::ARCHIVIST;
$user->save();
}
Expand Down
15 changes: 4 additions & 11 deletions app/Console/Commands/AutoPreWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
namespace App\Console\Commands;

use App\Models\History;
use App\Models\PrivateMessage;
use App\Models\Warning;
use App\Notifications\UserPreWarning;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;

/**
* @see \Tests\Unit\Console\Commands\AutoPreWarningTest
Expand Down Expand Up @@ -73,15 +73,8 @@ public function handle(): void
if ($exsist === null) {
$timeleft = \config('hitrun.grace') - \config('hitrun.prewarn');

// Send Private Message
$pm = new PrivateMessage();
$pm->sender_id = 1;
$pm->receiver_id = $pre->user->id;
$pm->subject = 'Hit and Run Warning Incoming';
$pm->message = 'You have received a automated [b]PRE-WARNING PM[/b] from the system because [b]you have been disconnected for '.\config('hitrun.prewarn').\sprintf(' days on Torrent %s
and have not yet met the required seedtime rules set by ', $pre->torrent->name).\config('other.title').\sprintf('. If you fail to seed it within %s day(s) you will receive a automated WARNING which will last ', $timeleft).\config('hitrun.expire').' days![/b]
[color=red][b] THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]';
$pm->save();
// Send Notifications
$pre->user->notify(new UserPreWarning($pre->user, $pre->torrent));

// Set History Prewarn
$pre->prewarn = 1;
Expand Down
69 changes: 0 additions & 69 deletions app/Console/Commands/AutoRevokePermissions.php

This file was deleted.

54 changes: 54 additions & 0 deletions app/Console/Commands/AutoTorrentBalance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author Roardom <[email protected]>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

namespace App\Console\Commands;

use App\Models\Torrent;
use App\Models\History;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class AutoTorrentBalance extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'auto:torrent_balance';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Calculate balance for all torrents.';

/**
* Execute the console command.
*/
public function handle(): void
{
Torrent::joinSub(
History::query()
->select('torrent_id')
->selectRaw('SUM(actual_uploaded) - SUM(actual_downloaded) AS balance')
->groupBy('torrent_id'),
'balances',
fn ($join) => $join->on('balances.torrent_id', '=', 'torrents.id')
)
->update(['torrents.balance' => DB::raw('balances.balance')]);

$this->comment('Torrent balance calculations completed.');
}
}
25 changes: 15 additions & 10 deletions app/Console/Commands/AutoWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
namespace App\Console\Commands;

use App\Models\History;
use App\Models\PrivateMessage;
use App\Models\Warning;
use App\Notifications\UserWarning;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;

/**
* @see \Tests\Unit\Console\Commands\AutoWarningTest
Expand Down Expand Up @@ -79,19 +80,23 @@ public function handle(): void
$hr->user->hitandruns++;
$hr->user->save();

// Send Private Message
$pm = new PrivateMessage();
$pm->sender_id = 1;
$pm->receiver_id = $hr->user->id;
$pm->subject = 'Hit and Run Warning Received';
$pm->message = 'You have received a automated [b]WARNING[/b] from the system because [b]you failed to follow the Hit and Run rules in relation to Torrent '.$hr->torrent->name.'[/b]
[color=red][b]THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]';
$pm->save();
// Send Notifications
$hr->user->notify(new UserWarning($hr->user, $hr->torrent));

$hr->save();
}
}
}

// Calculate User Warning Count and Disable DL Priv If Required.
$warnings = 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 ($warnings as $warning) {
if ($warning->warneduser->can_download === 1) {
$warning->warneduser->can_download = 0;
$warning->warneduser->save();
}
}
}

$this->comment('Automated User Warning Command Complete');
Expand Down
3 changes: 1 addition & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ protected function schedule(Schedule $schedule): void
$schedule->command('auto:prewarning')->hourly();
$schedule->command('auto:warning')->daily();
$schedule->command('auto:deactivate_warning')->hourly();
$schedule->command('auto:revoke_permissions')->hourly();
$schedule->command('auto:ban')->hourly();
$schedule->command('auto:flush_peers')->hourly();
$schedule->command('auto:bon_allocation')->hourly();
$schedule->command('auto:remove_personal_freeleech')->hourly();
Expand All @@ -48,6 +46,7 @@ protected function schedule(Schedule $schedule): void
$schedule->command('auto:reset_user_flushes')->daily();
$schedule->command('auto:stats_clients')->daily();
$schedule->command('auto:remove_torrent_buffs')->hourly();
$schedule->command('auto:torrent_balance')->hourly();
//$schedule->command('auto:ban_disposable_users')->weekends();
//$schedule->command('backup:clean')->daily();
//$schedule->command('backup:run')->daily();
Expand Down
Loading

0 comments on commit 235fa69

Please sign in to comment.