14
14
namespace App \Console \Commands ;
15
15
16
16
use App \Enums \UserGroup ;
17
- use App \Helpers \ByteUnits ;
18
17
use App \Models \Group ;
19
18
use App \Models \User ;
20
19
use App \Services \Unit3dAnnounce ;
@@ -44,11 +43,11 @@ class AutoGroup extends Command
44
43
/**
45
44
* Execute the console command.
46
45
*/
47
- public function handle (ByteUnits $ byteUnits ): void
46
+ public function handle (): void
48
47
{
49
48
$ now = now ();
50
- // Temp Hard Coding of Immune Groups (Config Files To Come)
51
49
$ current = Carbon::now ();
50
+
52
51
$ groups = Group::query ()
53
52
->where ('autogroup ' , '= ' , 1 )
54
53
->orderBy ('position ' )
@@ -64,19 +63,25 @@ public function handle(ByteUnits $byteUnits): void
64
63
$ seedtime = null ;
65
64
66
65
foreach ($ groups as $ group ) {
66
+ $ seedtime ??= DB ::table ('history ' )
67
+ ->whereNull ('deleted_at ' )
68
+ ->where ('user_id ' , '= ' , $ user ->id )
69
+ ->avg ('seedtime ' ) ?? 0 ;
70
+
71
+ $ seedsize ??= $ user ->seedingTorrents ()->sum ('size ' );
72
+
67
73
if (
68
74
//short circuit when the values are 0 or null
69
- ($ group ->min_uploaded ? $ group ->min_uploaded <= $ user ->uploaded : true )
70
- && ($ group ->min_ratio ? $ group ->min_ratio <= $ user ->ratio : true )
71
- && ($ group ->min_age ? $ user ->created_at ->addRealSeconds ($ group ->min_age )->isBefore ($ current ) : true )
72
- && ($ group ->min_avg_seedtime ? $ group ->min_avg_seedtime <= ($ seedtime ??= DB :: table ( ' history ' )-> where ( ' user_id ' , ' = ' , $ user -> id )-> avg ( ' seedtime ' ) ?? 0 ) : true )
73
- && ($ group ->min_seedsize ? $ group ->min_seedsize <= ($ seedsize ??= $ user -> seedingTorrents ()-> sum ( ' size ' )) : true )
75
+ (! $ group ->min_uploaded || $ group ->min_uploaded <= $ user ->uploaded )
76
+ && (! $ group ->min_ratio || $ group ->min_ratio <= $ user ->ratio )
77
+ && (! $ group ->min_age || $ user ->created_at ->addSeconds ($ group ->min_age )->isBefore ($ current ))
78
+ && (! $ group ->min_avg_seedtime || $ group ->min_avg_seedtime <= ($ seedtime) )
79
+ && (! $ group ->min_seedsize || $ group ->min_seedsize <= ($ seedsize) )
74
80
) {
75
81
$ user ->group_id = $ group ->id ;
76
82
77
83
// Leech ratio dropped below sites minimum
78
-
79
- if ($ user ->group_id == UserGroup::LEECH ->value ) {
84
+ if ($ user ->group_id === UserGroup::LEECH ->value ) {
80
85
$ user ->can_request = false ;
81
86
$ user ->can_invite = false ;
82
87
$ user ->can_download = false ;
@@ -96,7 +101,7 @@ public function handle(ByteUnits $byteUnits): void
96
101
}
97
102
}
98
103
99
- $ elapsed = now ()->floatDiffInSeconds ($ now );
104
+ $ elapsed = now ()->diffInSeconds ($ now );
100
105
$ this ->comment ('Automated User Group Command Complete ( ' .$ elapsed .') ' );
101
106
}
102
107
}
0 commit comments