-
-
Notifications
You must be signed in to change notification settings - Fork 364
/
autoWarning.php
88 lines (77 loc) · 3.25 KB
/
autoWarning.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* NOTICE OF LICENSE
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
* @license https://choosealicense.com/licenses/gpl-3.0/ GNU General Public License v3.0
* @author Mr.G
*/
namespace App\Console\Commands;
use App\Torrent;
use App\History;
use App\PrivateMessage;
use App\User;
use App\Warning;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class autoWarning extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'autoWarning';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Automatically Post Warnings To Users Accounts and Warnings Table';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (config('hitrun.enabled') == true) {
$current = new Carbon();
$hitrun = History::with(['user', 'torrent'])
->where('actual_downloaded', '>', 0)
->where('active', '=', 0)
->where('seedtime', '<=', config('hitrun.seedtime'))
->where('updated_at', '<', $current->copy()->subDays(config('hitrun.grace'))->toDateTimeString())
->get();
foreach ($hitrun as $hr) {
if (!$hr->user->group->is_immune) {
if ($hr->actual_downloaded > ($hr->torrent->size * (config('hitrun.buffer') / 100))) {
$exsist = Warning::where('torrent', '=', $hr->torrent->id)->where('user_id', '=', $hr->user->id)->first();
// Insert Warning Into Warnings Table if doesnt already exsist
if (!$exsist) {
$warning = new Warning();
$warning->user_id = $hr->user->id;
$warning->warned_by = "1";
$warning->torrent = $hr->torrent->id;
$warning->reason = "Hit and Run Warning For Torrent {$hr->torrent->name}";
$warning->expires_on = $current->copy()->addDays(config('hitrun.expire'));
$warning->active = "1";
$warning->save();
// Add +1 To Users Warnings Count In Users Table
$hr->user->hitandruns++;
$hr->user->save();
// Send PM To The Offender
PrivateMessage::create(['sender_id' => "1", 'reciever_id' => $hr->user->id, 'subject' => "Hit and Run Warning Recieved", '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]"]);
}
unset($exist);
}
}
}
}
}
}