-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDiscordEmbed-v7.0.php
178 lines (163 loc) · 3.01 KB
/
DiscordEmbed-v7.0.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* Discord Embed is a part of DiscordWebhook library.
*/
final class DiscordEmbed
{
protected $title;
protected $type = "rich";
protected $description;
protected $url;
protected $timestamp;
protected $color;
protected $footer;
protected $image;
protected $thumbnail;
protected $video;
protected $provider;
protected $author;
protected $fields;
/**
* Set the title and the url
*
* @param string $title
* @param string $url
* @return self|null
*/
function setTitle($title, $url = "") {
$this->title = $title;
$this->url = $url;
return $this;
}
/**
* Set description
*
* @param string $description
* @return self
*/
function setDescription($description) {
$this->description = $description;
return $this;
}
/**
* Set timestamp of the embed
*
* @param [type] $timestamp
* @return self
*/
function setTimestamp($timestamp) {
$this->timestamp = $timestamp;
return $this;
}
/**
* Set border color
*
* @param string $color
* @return self
*/
function setColor($color) {
$this->color = is_int($color) ? $color : hexdec($color);
return $this;
}
/**
* Set url
*
* @param string $url
* @return self
*/
function setUrl($url) {
$this->url = $url;
return $this;
}
/**
* Set footer
*
* @param string $text
* @param string $icon_url
* @return self
*/
function setFooter($text, $icon_url = "") {
$this->footer = [
"text" => $text,
"icon_url" => $icon_url,
];
return $this;
}
/**
* Set image
*
* @param string $url
* @return self
*/
function setImage($url) {
$this->image = [
"url" => $url,
];
return $this;
}
/**
* Set thumbnail
*
* @param string $url
* @return self
*/
function setThumbnail($url) {
$this->thumbnail = [
"url" => $url,
];
return $this;
}
/**
* Set author
*
* @param string $name
* @param string $url
* @param string $icon_url
* @return self
*/
function setAuthor($name, $url = "", $icon_url = "") {
$this->author = [
"name" => $name,
"url" => $url,
"icon_url" => $icon_url,
];
return $this;
}
/**
* Set field
*
* @param string $name
* @param string $value
* @param boolean $inline
* @return self
*/
function setField($name, $value = "", $inline = false) {
$this->fields[] = [
'name' => $name,
'value' => $value,
'inline' => boolval($inline),
];
return $this;
}
/**
* Get fields as an array
*
* @return array
*/
function toArray() {
return [
'title' => $this->title,
'type' => $this->type,
'description' => $this->description,
'url' => $this->url,
'color' => $this->color,
'footer' => $this->footer,
'image' => $this->image,
'thumbnail' => $this->thumbnail,
'timestamp' => $this->timestamp,
'author' => $this->author,
'fields' => $this->fields
];
}
}
?>