-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBan.php
97 lines (78 loc) · 2.5 KB
/
Ban.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
89
90
91
92
93
94
95
96
97
<?php
/*
* DiscordBot, PocketMine-MP Plugin.
*
* Licensed under the Open Software License version 3.0 (OSL-3.0)
* Copyright (C) 2020-present JaxkDev
*
* Discord :: JaxkDev
* Email :: [email protected]
*/
namespace JaxkDev\DiscordBot\Models;
use JaxkDev\DiscordBot\Communication\BinarySerializable;
use JaxkDev\DiscordBot\Communication\BinaryStream;
use JaxkDev\DiscordBot\Plugin\Utils;
/**
* @implements BinarySerializable<Ban>
* @link https://discord.com/developers/docs/resources/guild#ban-object
*/
final class Ban implements BinarySerializable{
public const SERIALIZE_ID = 4;
/** Guild the user is banned from */
private string $guild_id;
/** The banned user */
private string $user_id;
/** The reason for the ban */
private ?string $reason;
/**
* @internal See API::banMember()
* @see API::banMember()
*/
public function __construct(string $guild_id, string $user_id, ?string $reason = null){
$this->setGuildId($guild_id);
$this->setUserId($user_id);
$this->setReason($reason);
}
public function getId(): string{
return $this->guild_id . "." . $this->user_id;
}
public function getGuildId(): string{
return $this->guild_id;
}
public function setGuildId(string $guild_id): void{
if(!Utils::validDiscordSnowflake($guild_id)){
throw new \AssertionError("Guild ID '$guild_id' is invalid.");
}
$this->guild_id = $guild_id;
}
public function getUserId(): string{
return $this->user_id;
}
public function setUserId(string $user_id): void{
if(!Utils::validDiscordSnowflake($user_id)){
throw new \AssertionError("User ID '$user_id' is invalid.");
}
$this->user_id = $user_id;
}
public function getReason(): ?string{
return $this->reason;
}
public function setReason(?string $reason): void{
$this->reason = $reason;
}
//----- Serialization -----//
public function binarySerialize(): BinaryStream{
$stream = new BinaryStream();
$stream->putString($this->guild_id);
$stream->putString($this->user_id);
$stream->putNullableString($this->reason);
return $stream;
}
public static function fromBinary(BinaryStream $stream): self{
return new self(
$stream->getString(), // guild_id
$stream->getString(), // user_id
$stream->getNullableString() // reason
);
}
}