Skip to content

Commit

Permalink
Merge pull request #3788 from HDInnovations/Commands
Browse files Browse the repository at this point in the history
(Update) Commands
  • Loading branch information
HDVinnie committed May 6, 2024
2 parents 7a8490f + 99f5f33 commit 3b550fa
Show file tree
Hide file tree
Showing 52 changed files with 244 additions and 765 deletions.
1 change: 0 additions & 1 deletion .env.example
Expand Up @@ -15,7 +15,6 @@ DB_PORT=3306
DB_DATABASE=unit3d
DB_USERNAME=root
DB_PASSWORD=
#PRISTINE_DB_FILE=/home/vagrant/code/database/unit3d_test.sql

BROADCAST_CONNECTION=redis
CACHE_STORE=redis
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoBanDisposableUsers.php
Expand Up @@ -22,10 +22,8 @@
use App\Services\Unit3dAnnounce;
use Illuminate\Console\Command;
use Exception;
use Throwable;

/**
* @see \Tests\Todo\Unit\Console\Commands\AutoBanDisposableUsersTest
*/
class AutoBanDisposableUsers extends Command
{
/**
Expand All @@ -45,9 +43,9 @@ class AutoBanDisposableUsers extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$bannedGroup = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));

Expand Down
7 changes: 3 additions & 4 deletions app/Console/Commands/AutoCacheRandomMediaIds.php
Expand Up @@ -18,6 +18,7 @@
use Illuminate\Console\Command;
use Exception;
use Illuminate\Support\Facades\Redis;
use Throwable;

class AutoCacheRandomMediaIds extends Command
{
Expand All @@ -38,9 +39,9 @@ class AutoCacheRandomMediaIds extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$movieIds = Movie::query()
->select('id')
Expand All @@ -55,11 +56,9 @@ public function handle(): void
->pluck('id');

$cacheKey = config('cache.prefix').':random-media-movie-ids';

Redis::connection('cache')->command('SADD', [$cacheKey, ...$movieIds]);

$cacheKey = config('cache.prefix').':random-media-tv-ids';

Redis::connection('cache')->command('SADD', [$cacheKey, ...$tvIds]);

$this->comment($movieIds->count().' movie ids and '.$tvIds->count().' tv ids cached.');
Expand Down
5 changes: 3 additions & 2 deletions app/Console/Commands/AutoCacheUserLeechCounts.php
Expand Up @@ -16,6 +16,7 @@
use App\Models\User;
use Illuminate\Console\Command;
use Exception;
use Throwable;

class AutoCacheUserLeechCounts extends Command
{
Expand All @@ -36,9 +37,9 @@ class AutoCacheUserLeechCounts extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$peerCounts = User::withoutGlobalScopes()
->selectRaw("CONCAT('user-leeching-count:', id) as cacheKey")
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoCorrectHistory.php
Expand Up @@ -18,10 +18,8 @@
use Illuminate\Support\Carbon;
use Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoCorrectHistoryTest
*/
class AutoCorrectHistory extends Command
{
/**
Expand All @@ -41,9 +39,9 @@ class AutoCorrectHistory extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
History::select(['id', 'active', 'updated_at'])
->where('active', '=', 1)
Expand Down
9 changes: 5 additions & 4 deletions app/Console/Commands/AutoDeactivateWarning.php
Expand Up @@ -18,12 +18,11 @@
use App\Notifications\UserWarningExpire;
use App\Services\Unit3dAnnounce;
use Carbon\Carbon;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoDeactivateWarningTest
*/
class AutoDeactivateWarning extends Command
{
/**
Expand All @@ -42,8 +41,10 @@ class AutoDeactivateWarning extends Command

/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$current = Carbon::now();
$warnings = Warning::with(['warneduser', 'torrenttitle'])
Expand Down
14 changes: 10 additions & 4 deletions app/Console/Commands/AutoDeleteStoppedPeers.php
Expand Up @@ -13,9 +13,10 @@

namespace App\Console\Commands;

use App\Models\Peer;
use Illuminate\Console\Command;
use Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

class AutoDeleteStoppedPeers extends Command
{
Expand All @@ -36,11 +37,16 @@ class AutoDeleteStoppedPeers extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
Peer::where('active', '=', 0)->where('updated_at', '>', now()->subHours(2))->delete();
DB::transaction(static function (): void {
DB::table('peers')
->where('active', '=', 0)
->where('updated_at', '>', now()->subHours(2))
->delete();
}, 5);

$this->comment('Automated delete stopped peers command complete');
}
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoDisableInactiveUsers.php
Expand Up @@ -20,10 +20,8 @@
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Exception;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoDisableInactiveUsersTest
*/
class AutoDisableInactiveUsers extends Command
{
/**
Expand All @@ -43,9 +41,9 @@ class AutoDisableInactiveUsers extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
if (config('pruning.user_pruning')) {
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoFlushPeers.php
Expand Up @@ -19,10 +19,8 @@
use Illuminate\Support\Carbon;
use Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoFlushPeersTest
*/
class AutoFlushPeers extends Command
{
/**
Expand All @@ -42,9 +40,9 @@ class AutoFlushPeers extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$carbon = new Carbon();
$peers = Peer::select(['id', 'torrent_id', 'user_id', 'seeder', 'updated_at'])
Expand Down
9 changes: 5 additions & 4 deletions app/Console/Commands/AutoGroup.php
Expand Up @@ -17,13 +17,12 @@
use App\Models\Group;
use App\Models\User;
use App\Services\Unit3dAnnounce;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoGroupTest
*/
class AutoGroup extends Command
{
/**
Expand All @@ -42,8 +41,10 @@ class AutoGroup extends Command

/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$now = now();
$current = Carbon::now();
Expand Down
9 changes: 5 additions & 4 deletions app/Console/Commands/AutoHighspeedTag.php
Expand Up @@ -17,12 +17,11 @@
use App\Models\Scopes\ApprovedScope;
use App\Models\Seedbox;
use App\Models\Torrent;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoHighspeedTagTest
*/
class AutoHighspeedTag extends Command
{
/**
Expand All @@ -41,8 +40,10 @@ class AutoHighspeedTag extends Command

/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$seedboxIps = Seedbox::all()
->pluck('ip')
Expand Down
42 changes: 20 additions & 22 deletions app/Console/Commands/AutoNerdStat.php
Expand Up @@ -13,18 +13,12 @@

namespace App\Console\Commands;

use App\Models\Ban;
use App\Models\Peer;
use App\Models\Torrent;
use App\Models\User;
use App\Models\Warning;
use App\Repositories\ChatRepository;
use Illuminate\Console\Command;
use Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Todo\Unit\Console\Commands\AutoNerdStatTest
*/
class AutoNerdStat extends Command
{
/**
Expand Down Expand Up @@ -52,11 +46,13 @@ public function __construct(private readonly ChatRepository $chatRepository)
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
// Check if the nerd bot is enabled in the configuration.
if (config('chat.nerd_bot')) {
// Define the possible stats.
$stats = collect([
'birthday',
'logins',
Expand All @@ -73,27 +69,29 @@ public function handle(): void
'king',
])->random();

// Generate the message based on the selected stat.
$message = match ($stats) {
'birthday' => config('other.title').' Birthday Is [b]'.config('other.birthdate').'[/b]!',
'logins' => 'In The Last 24 Hours [color=#93c47d][b]'.User::whereNotNull('last_login')->where('last_login', '>', now()->subDay())->count().'[/b][/color] Unique Users Have Logged Into '.config('other.title').'!',
'uploads' => 'In The Last 24 Hours [color=#93c47d][b]'.Torrent::where('created_at', '>', now()->subDay())->count().'[/b][/color] Torrents Have Been Uploaded To '.config('other.title').'!',
'users' => 'In The Last 24 Hours [color=#93c47d][b]'.User::where('created_at', '>', now()->subDay())->count().'[/b][/color] Users Have Registered To '.config('other.title').'!',
'fl25' => 'There Are Currently [color=#93c47d][b]'.Torrent::where('free', '=', 25)->count().'[/b][/color] 25% Freeleech Torrents On '.config('other.title').'!',
'fl50' => 'There Are Currently [color=#93c47d][b]'.Torrent::where('free', '=', 50)->count().'[/b][/color] 50% Freeleech Torrents On '.config('other.title').'!',
'fl75' => 'There Are Currently [color=#93c47d][b]'.Torrent::where('free', '=', 75)->count().'[/b][/color] 75% Freeleech Torrents On '.config('other.title').'!',
'fl100' => 'There Are Currently [color=#93c47d][b]'.Torrent::where('free', '=', 100)->count().'[/b][/color] 100% Freeleech Torrents On '.config('other.title').'!',
'du' => 'There Are Currently [color=#93c47d][b]'.Torrent::where('doubleup', '=', 1)->count().'[/b][/color] Double Upload Torrents On '.config('other.title').'!',
'peers' => 'Currently There Are [color=#93c47d][b]'.Peer::where('active', '=', 1)->count().'[/b][/color] Peers On '.config('other.title').'!',
'bans' => 'In The Last 24 Hours [color=#dd7e6b][b]'.Ban::whereNull('unban_reason')->whereNull('removed_at')->where('created_at', '>', now()->subDay())->count().'[/b][/color] Users Have Been Banned From '.config('other.title').'!',
'warnings' => 'In The Last 24 Hours [color=#dd7e6b][b]'.Warning::where('created_at', '>', now()->subDay())->count().'[/b][/color] Hit and Run Warnings Have Been Issued On '.config('other.title').'!',
'logins' => 'In The Last 24 Hours [color=#93c47d][b]'.DB::table('users')->whereNotNull('last_login')->where('last_login', '>', now()->subDay())->count().'[/b][/color] Unique Users Have Logged Into '.config('other.title').'!',
'uploads' => 'In The Last 24 Hours [color=#93c47d][b]'.DB::table('torrents')->where('created_at', '>', now()->subDay())->count().'[/b][/color] Torrents Have Been Uploaded To '.config('other.title').'!',
'users' => 'In The Last 24 Hours [color=#93c47d][b]'.DB::table('users')->where('created_at', '>', now()->subDay())->count().'[/b][/color] Users Have Registered To '.config('other.title').'!',
'fl25' => 'There Are Currently [color=#93c47d][b]'.DB::table('torrents')->where('free', '=', 25)->count().'[/b][/color] 25% Freeleech Torrents On '.config('other.title').'!',
'fl50' => 'There Are Currently [color=#93c47d][b]'.DB::table('torrents')->where('free', '=', 50)->count().'[/b][/color] 50% Freeleech Torrents On '.config('other.title').'!',
'fl75' => 'There Are Currently [color=#93c47d][b]'.DB::table('torrents')->where('free', '=', 75)->count().'[/b][/color] 75% Freeleech Torrents On '.config('other.title').'!',
'fl100' => 'There Are Currently [color=#93c47d][b]'.DB::table('torrents')->where('free', '=', 100)->count().'[/b][/color] 100% Freeleech Torrents On '.config('other.title').'!',
'du' => 'There Are Currently [color=#93c47d][b]'.DB::table('torrents')->where('doubleup', '=', 1)->count().'[/b][/color] Double Upload Torrents On '.config('other.title').'!',
'peers' => 'Currently There Are [color=#93c47d][b]'.DB::table('peers')->where('active', '=', 1)->count().'[/b][/color] Peers On '.config('other.title').'!',
'bans' => 'In The Last 24 Hours [color=#dd7e6b][b]'.DB::table('bans')->whereNull('unban_reason')->whereNull('removed_at')->where('created_at', '>', now()->subDay())->count().'[/b][/color] Users Have Been Banned From '.config('other.title').'!',
'warnings' => 'In The Last 24 Hours [color=#dd7e6b][b]'.DB::table('warnings')->where('created_at', '>', now()->subDay())->count().'[/b][/color] Hit and Run Warnings Have Been Issued On '.config('other.title').'!',
'king' => config('other.title').' Is King!',
default => 'Nerd Stat Error!',
};

// Auto Shout Nerd Stat
// Post the message to the chatbox.
$this->chatRepository->systemMessage($message);
}

// Output a success message to the console.
$this->comment('Automated Nerd Stat Command Complete');
}
}
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoPreWarning.php
Expand Up @@ -19,10 +19,8 @@
use Carbon\Carbon;
use Illuminate\Console\Command;
use Exception;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoPreWarningTest
*/
class AutoPreWarning extends Command
{
/**
Expand All @@ -42,9 +40,9 @@ class AutoPreWarning extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
if (config('hitrun.enabled') === true) {
$carbon = new Carbon();
Expand Down
9 changes: 5 additions & 4 deletions app/Console/Commands/AutoRecycleAudits.php
Expand Up @@ -14,12 +14,11 @@
namespace App\Console\Commands;

use App\Models\Audit;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoRecycleAuditsTest
*/
class AutoRecycleAudits extends Command
{
/**
Expand All @@ -38,8 +37,10 @@ class AutoRecycleAudits extends Command

/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$current = Carbon::now();
$audits = Audit::where('created_at', '<', $current->copy()->subDays(config('audit.recycle'))->toDateTimeString())->get();
Expand Down

0 comments on commit 3b550fa

Please sign in to comment.