Skip to content

Commit 7075598

Browse files
cjmaxikThorErik
authored andcommitted
Update Ban.php (#8)
Return `null` for permanent bans, also set `active` as false for bans with expired date > now
1 parent 9748822 commit 7075598

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Types/Ban.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Ban
99
/**
1010
* Time and Date when the ban expires.
1111
*
12-
* @var Carbon
12+
* @var Carbon|null
1313
*/
1414
public $expires;
1515

@@ -55,9 +55,23 @@ class Ban
5555
*/
5656
public function __construct($ban)
5757
{
58-
$this->expires = new Carbon($ban['expiration'], 'UTC');
58+
// Expiration
59+
if ($ban['expiration'] === null) {
60+
$this->expires = null;
61+
} else {
62+
$this->expires = new Carbon($ban['expiration'], 'UTC');
63+
}
64+
65+
// Time Added
5966
$this->created = new Carbon($ban['timeAdded'], 'UTC');
60-
$this->active = $ban['active'];
67+
68+
// Active
69+
$this->active = $ban['active'];
70+
if (!is_null($this->expires) && $this->active) {
71+
if (!$this->expires->greaterThan(Carbon::now('UTC'))) {
72+
$this->active = false;
73+
}
74+
}
6175

6276
$this->reason = $ban['reason'];
6377
$this->adminName = $ban['adminName'];

0 commit comments

Comments
 (0)