Skip to content

Commit

Permalink
Merge pull request #3370 from HDInnovations/7.x.x
Browse files Browse the repository at this point in the history
(Release) v7.2.1
  • Loading branch information
HDVinnie authored Jan 11, 2024
2 parents 154fe2b + 1677906 commit 340cd6f
Show file tree
Hide file tree
Showing 397 changed files with 5,991 additions and 10,519 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/larastan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
operating-system:
- ubuntu-22.04
php-version:
- '8.2'
- '8.3'
name: php ${{ matrix.php-version }} on ${{ matrix.operating-system }}
services:
mysql:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
operating-system:
- ubuntu-22.04
php-version:
- '8.2'
- '8.3'
name: php ${{ matrix.php-version }} on ${{ matrix.operating-system }}
services:
mysql:
Expand Down
21 changes: 12 additions & 9 deletions app/Bots/IRCAnnounceBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
class IRCAnnounceBot
{
/**
* @var false|resource
* @var resource
*/
private $socket;

private const RPL_WELCOME = 001;

public function __construct()
{
$this->socket = fsockopen(config('irc-bot.server'), config('irc-bot.port'), $_, $_, 5);
$socket = fsockopen(config('irc-bot.server'), config('irc-bot.port'), $_, $_, 5);

if ($this->socket === false) {
if (!\is_resource($socket)) {
return;
}

$this->socket = $socket;
$this->nick(config('irc-bot.username'));
$this->user(config('irc-bot.username'), config('irc-bot.hostname'), config('irc-bot.server'), config('irc-bot.username'));

Expand All @@ -44,18 +45,18 @@ public function __construct()

public function __destruct()
{
if ($this->socket) {
sleep(2);
sleep(2);

$this->quit();
$this->quit();

if (\is_resource($this->socket)) {
fclose($this->socket);
}
}

private function connect(): void
{
while ($message = fgets($this->socket)) {
while (\is_resource($this->socket) && $message = fgets($this->socket)) {
flush();

if ($message[0] === ':') {
Expand Down Expand Up @@ -95,12 +96,14 @@ private function authenticate(string $username, string $password): void

private function send(string $data): void
{
fwrite($this->socket, $data."\r\n");
if (\is_resource($this->socket)) {
fwrite($this->socket, $data."\r\n");
}
}

public function message(string $receiver, string $message): void
{
if ($this->socket === false) {
if (!\is_resource($this->socket)) {
return;
}

Expand Down
38 changes: 19 additions & 19 deletions app/Console/Commands/AutoGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace App\Console\Commands;

use App\Enums\UserGroups;
use App\Enums\UserGroup;
use App\Helpers\ByteUnits;
use App\Models\Group;
use App\Models\History;
Expand Down Expand Up @@ -56,62 +56,62 @@ public function handle(ByteUnits $byteUnits): void
// Temp Hard Coding of Group Requirements (Config Files To Come) (Upload in Bytes!) (Seedtime in Seconds!)

// Leech ratio dropped below sites minimum
if ($user->ratio < config('other.ratio') && $user->group_id != UserGroups::LEECH->value) {
$user->group_id = UserGroups::LEECH->value;
if ($user->ratio < config('other.ratio') && $user->group_id != UserGroup::LEECH->value) {
$user->group_id = UserGroup::LEECH->value;
$user->can_request = false;
$user->can_invite = false;
$user->can_download = false;
$user->save();
}

// User >= 0 and ratio above sites minimum
if ($user->uploaded >= 0 && $user->ratio >= config('other.ratio') && $user->group_id != UserGroups::USER->value) {
$user->group_id = UserGroups::USER->value;
if ($user->uploaded >= 0 && $user->ratio >= config('other.ratio') && $user->group_id != UserGroup::USER->value) {
$user->group_id = UserGroup::USER->value;
$user->can_request = true;
$user->can_invite = true;
$user->can_download = true;
$user->save();
}

// PowerUser >= 1TiB and account 1 month old
if ($user->uploaded >= $byteUnits->bytesFromUnit('1TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(30)->toDateTimeString() && $user->group_id != UserGroups::POWERUSER->value) {
$user->group_id = UserGroups::POWERUSER->value;
if ($user->uploaded >= $byteUnits->bytesFromUnit('1TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(30)->toDateTimeString() && $user->group_id != UserGroup::POWERUSER->value) {
$user->group_id = UserGroup::POWERUSER->value;
$user->save();
}

// SuperUser >= 5TiB and account 2 month old
if ($user->uploaded >= $byteUnits->bytesFromUnit('5TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(60)->toDateTimeString() && $user->group_id != UserGroups::SUPERUSER->value) {
$user->group_id = UserGroups::SUPERUSER->value;
if ($user->uploaded >= $byteUnits->bytesFromUnit('5TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(60)->toDateTimeString() && $user->group_id != UserGroup::SUPERUSER->value) {
$user->group_id = UserGroup::SUPERUSER->value;
$user->save();
}

// ExtremeUser >= 20TiB and account 3 month old
if ($user->uploaded >= $byteUnits->bytesFromUnit('20TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(90)->toDateTimeString() && $user->group_id != UserGroups::EXTREMEUSER->value) {
$user->group_id = UserGroups::EXTREMEUSER->value;
if ($user->uploaded >= $byteUnits->bytesFromUnit('20TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(90)->toDateTimeString() && $user->group_id != UserGroup::EXTREMEUSER->value) {
$user->group_id = UserGroup::EXTREMEUSER->value;
$user->save();
}

// InsaneUser >= 50TiB and account 6 month old
if ($user->uploaded >= $byteUnits->bytesFromUnit('50TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(180)->toDateTimeString() && $user->group_id != UserGroups::INSANEUSER->value) {
$user->group_id = UserGroups::INSANEUSER->value;
if ($user->uploaded >= $byteUnits->bytesFromUnit('50TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(180)->toDateTimeString() && $user->group_id != UserGroup::INSANEUSER->value) {
$user->group_id = UserGroup::INSANEUSER->value;
$user->save();
}

// Seeder Seedsize >= 5TiB and account 1 month old and seedtime average 30 days or better
if ($user->seedingTorrents()->sum('size') >= $byteUnits->bytesFromUnit('5TiB') && $user->ratio >= 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->value) {
$user->group_id = UserGroups::SEEDER->value;
if ($user->seedingTorrents()->sum('size') >= $byteUnits->bytesFromUnit('5TiB') && $user->ratio >= 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 != UserGroup::SEEDER->value) {
$user->group_id = UserGroup::SEEDER->value;
$user->save();
}

// Veteran >= 100TiB and account 1 year old
if ($user->uploaded >= $byteUnits->bytesFromUnit('100TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(365)->toDateTimeString() && $user->group_id != UserGroups::VETERAN->value) {
$user->group_id = UserGroups::VETERAN->value;
if ($user->uploaded >= $byteUnits->bytesFromUnit('100TiB') && $user->ratio >= config('other.ratio') && $user->created_at < $current->copy()->subDays(365)->toDateTimeString() && $user->group_id != UserGroup::VETERAN->value) {
$user->group_id = UserGroup::VETERAN->value;
$user->save();
}

// Archivist Seedsize >= 10TiB and account 3 month old and seedtime average 60 days or better
if ($user->seedingTorrents()->sum('size') >= $byteUnits->bytesFromUnit('10TiB') && $user->ratio >= 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->value) {
$user->group_id = UserGroups::ARCHIVIST->value;
if ($user->seedingTorrents()->sum('size') >= $byteUnits->bytesFromUnit('10TiB') && $user->ratio >= 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 != UserGroup::ARCHIVIST->value) {
$user->group_id = UserGroup::ARCHIVIST->value;
$user->save();
}

Expand Down
143 changes: 55 additions & 88 deletions app/Console/Commands/AutoSoftDeleteDisabledUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

namespace App\Console\Commands;

use App\Enums\UserGroup;
use App\Jobs\SendDeleteUserMail;
use App\Models\Comment;
use App\Models\FailedLoginAttempt;
use App\Models\FreeleechToken;
use App\Models\Group;
use App\Models\History;
Expand All @@ -30,7 +32,6 @@
use App\Models\User;
use App\Services\Unit3dAnnounce;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Exception;

/**
Expand Down Expand Up @@ -61,108 +62,74 @@ public function handle(): void
{
if (config('pruning.user_pruning')) {
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
$prunedGroup = cache()->rememberForever('pruned_group', fn () => Group::where('slug', '=', 'pruned')->pluck('id'));

$current = Carbon::now();
$users = User::where('group_id', '=', $disabledGroup[0])
->where('disabled_at', '<', $current->copy()->subDays(config('pruning.soft_delete'))->toDateTimeString())
->where('disabled_at', '<', now()->copy()->subDays(config('pruning.soft_delete'))->toDateTimeString())
->get();

foreach ($users as $user) {
// Send Email
dispatch(new SendDeleteUserMail($user));

$user->can_upload = false;
$user->can_download = false;
$user->can_comment = false;
$user->can_invite = false;
$user->can_request = false;
$user->can_chat = false;
$user->group_id = $prunedGroup[0];
$user->deleted_by = 1;
$user->save();

cache()->forget('user:'.$user->passkey);
Unit3dAnnounce::addUser($user);

// Removes UserID from Torrents if any and replaces with System UserID (1)
foreach (Torrent::withoutGlobalScope(ApprovedScope::class)->where('user_id', '=', $user->id)->get() as $tor) {
$tor->user_id = 1;
$tor->save();
}

// Removes UserID from Comments if any and replaces with System UserID (1)
foreach (Comment::where('user_id', '=', $user->id)->get() as $com) {
$com->user_id = 1;
$com->save();
}

// Removes UserID from Posts if any and replaces with System UserID (1)
foreach (Post::where('user_id', '=', $user->id)->get() as $post) {
$post->user_id = 1;
$post->save();
}

// Removes UserID from Topic Creators if any and replaces with System UserID (1)
foreach (Topic::where('first_post_user_id', '=', $user->id)->get() as $topic) {
$topic->first_post_user_id = 1;
$topic->save();
}

// Removes UserID from Topic if any and replaces with System UserID (1)
foreach (Topic::where('last_post_user_id', '=', $user->id)->get() as $topic) {
$topic->last_post_user_id = 1;
$topic->save();
}

// Removes UserID from PM if any and replaces with System UserID (1)
foreach (PrivateMessage::where('sender_id', '=', $user->id)->get() as $sent) {
$sent->sender_id = 1;
$sent->save();
}

// Removes UserID from PM if any and replaces with System UserID (1)
foreach (PrivateMessage::where('receiver_id', '=', $user->id)->get() as $received) {
$received->receiver_id = 1;
$received->save();
}

// Removes all Posts made by User from the shoutbox
foreach (Message::where('user_id', '=', $user->id)->get() as $shout) {
$shout->delete();
}

// Removes all likes for user
foreach (Like::where('user_id', '=', $user->id)->get() as $like) {
$like->delete();
}

// Removes all thanks for user
foreach (Thank::where('user_id', '=', $user->id)->get() as $thank) {
$thank->delete();
}
$user->update([
'can_upload' => false,
'can_download' => false,
'can_comment' => false,
'can_invite' => false,
'can_request' => false,
'can_chat' => false,
'group_id' => UserGroup::PRUNED->value,
'deleted_by' => User::SYSTEM_USER_ID,
]);

Torrent::withoutGlobalScope(ApprovedScope::class)->where('user_id', '=', $user->id)->update([
'user_id' => User::SYSTEM_USER_ID,
]);

Comment::where('user_id', '=', $user->id)->update([
'user_id' => User::SYSTEM_USER_ID,
]);

Post::where('user_id', '=', $user->id)->update([
'user_id' => User::SYSTEM_USER_ID,
]);

Topic::where('first_post_user_id', '=', $user->id)->update([
'first_post_user_id' => User::SYSTEM_USER_ID,
]);

Topic::where('last_post_user_id', '=', $user->id)->update([
'last_post_user_id' => User::SYSTEM_USER_ID,
]);

PrivateMessage::where('sender_id', '=', $user->id)->update([
'sender_id' => User::SYSTEM_USER_ID,
]);

PrivateMessage::where('receiver_id', '=', $user->id)->update([
'receiver_id' => User::SYSTEM_USER_ID,
]);

Message::where('user_id', '=', $user->id)->delete();
Like::where('user_id', '=', $user->id)->delete();
Thank::where('user_id', '=', $user->id)->delete();
Peer::where('user_id', '=', $user->id)->delete();
History::where('user_id', '=', $user->id)->delete();
FailedLoginAttempt::where('user_id', '=', $user->id)->delete();

// Removes all follows for user
$user->followers()->detach();
$user->following()->detach();

// Removes all Peers for user
foreach (Peer::where('user_id', '=', $user->id)->get() as $peer) {
$peer->delete();
}

// Remove all History records for user
foreach (History::where('user_id', '=', $user->id)->get() as $history) {
$history->delete();
}

// Removes all FL Tokens for user
foreach (FreeleechToken::where('user_id', '=', $user->id)->get() as $token) {
$token->delete();

cache()->forget('freeleech_token:'.$token->user_id.':'.$token->torrent_id);
cache()->forget('freeleech_token:'.$user->id.':'.$token->torrent_id);
}

cache()->forget('user:'.$user->passkey);

Unit3dAnnounce::removeUser($user);

dispatch(new SendDeleteUserMail($user));

$user->delete();
}
}
Expand Down
20 changes: 10 additions & 10 deletions app/Enums/Occupations.php → app/Enums/Occupation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace App\Enums;

enum Occupations: int
enum Occupation: int
{
case CREATOR = 1;
case DIRECTOR = 2;
Expand All @@ -28,17 +28,17 @@ enum Occupations: int
case ART_DIRECTOR = 9;
case ACTOR = 10;

public static function from_tmdb_job($job_name): ?static
public static function from_tmdb_job(string $job_name): ?Occupation
{
return match ($job_name) {
"Director" => static::DIRECTOR,
"Screenplay" => static::WRITER,
"Producer", "Co-Producer", "Associate Producer" => static::PRODUCER,
"Original Music Composer" => static::COMPOSER,
"Director of Photography" => static::CINEMATOGRAPHER,
"Editor" => static::EDITOR,
"Production Design" => static::PRODUCTION_DESIGNER,
"Art Direction" => static::ART_DIRECTOR,
"Director" => self::DIRECTOR,
"Screenplay" => self::WRITER,
"Producer", "Co-Producer", "Associate Producer" => self::PRODUCER,
"Original Music Composer" => self::COMPOSER,
"Director of Photography" => self::CINEMATOGRAPHER,
"Editor" => self::EDITOR,
"Production Design" => self::PRODUCTION_DESIGNER,
"Art Direction" => self::ART_DIRECTOR,
default => null,
};
}
Expand Down
2 changes: 1 addition & 1 deletion app/Enums/UserGroups.php → app/Enums/UserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace App\Enums;

enum UserGroups: int
enum UserGroup: int
{
case VALIDATING = 1;
case GUEST = 2;
Expand Down
Loading

0 comments on commit 340cd6f

Please sign in to comment.