-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscordEmbed.java
327 lines (264 loc) · 7.78 KB
/
DiscordEmbed.java
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
package *;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.TimeZone;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class DiscordEmbed {
private String title = ""; // title of embed(string)
private String type = "rich"; // type of embed(string)
private String description = ""; // description of embed(string)
private String url = "https://jaoafa.com/"; // url of embed(string)
private String timestamp = ""; // timestamp of embed content(ISO8601)
private int color = 65280; // color code of the embed(integer)
private FooterEmbed footer = null; // footer infomation(footer object)
private ImageEmbed image = null; // image infomation(image object)
private ThumbnailEmbed thumbnail = null; // thumbnail infomation(thumbnail object)
private VideoEmbed video = null; // video infomation(video object)
private ProviderEmbed provider = null; // provider infomation(provider object)
private AuthorEmbed author = null; // author infomation(author object)
private Set<FieldEmbed> fields = new LinkedHashSet<>(); // fields infomation(fields object)
public DiscordEmbed(){
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
timestamp = df.format(new Date());
}
public String getTitle(){
return this.title;
}
public void setTitle(String title){
this.title = title;
}
public String getType(){
return this.type;
}
public void setType(String type){
this.type = type;
}
public String getDescription(){
return this.description;
}
public void setDescription(String description){
this.description = description;
}
public String getUrl(){
return this.url;
}
public void setUrl(String url){
this.url = url;
}
public String getTimestamp(){
return this.timestamp;
}
public void setTimestamp(String timestamp){
this.timestamp = timestamp;
}
public int getColor(){
return this.color;
}
public void setColor(int color){
this.color = color;
}
public FooterEmbed getFooter(){
return this.footer;
}
@SuppressWarnings("unchecked")
public JSONObject getFooterJSON(){
JSONObject json = new JSONObject();
json.put("text", footer.getText());
json.put("icon_url", footer.getIcon_url());
json.put("proxy_icon_url", footer.getProxy_icon_url());
return json;
}
public void setFooter(FooterEmbed footer){
this.footer = footer;
}
public void setFooter(String text, String icon_url, String proxy_icon_url){
FooterEmbed footer = new FooterEmbed(text, icon_url, proxy_icon_url);
setFooter(footer);
}
public ImageEmbed getImage() {
return image;
}
@SuppressWarnings("unchecked")
public JSONObject getImageJSON(){
JSONObject json = new JSONObject();
json.put("url", image.getUrl());
json.put("proxy_url", image.getProxy_url());
json.put("height", image.getHeight());
json.put("width", image.getWidth());
return json;
}
public void setImage(ImageEmbed image) {
this.image = image;
}
public void setImage(String url, String proxy_url, int height, int width){
ImageEmbed image = new ImageEmbed(url, proxy_url, height, width);
setImage(image);
}
public ThumbnailEmbed getThumbnail() {
return thumbnail;
}
@SuppressWarnings("unchecked")
public JSONObject getThumbnailJSON(){
JSONObject json = new JSONObject();
json.put("url", thumbnail.getUrl());
json.put("proxy_url", thumbnail.getProxy_url());
json.put("height", thumbnail.getHeight());
json.put("width", thumbnail.getWidth());
return json;
}
public void setThumbnail(ThumbnailEmbed thumbnail) {
this.thumbnail = thumbnail;
}
public void setThumbnail(String url, String proxy_url, int height, int width){
ThumbnailEmbed thumbnail = new ThumbnailEmbed(url, proxy_url, height, width);
setThumbnail(thumbnail);
}
public VideoEmbed getVideo() {
return video;
}
@SuppressWarnings("unchecked")
public JSONObject getVideoJSON(){
JSONObject json = new JSONObject();
json.put("url", video.getUrl());
json.put("height", video.getHeight());
json.put("width", video.getWidth());
return json;
}
public void setVideo(VideoEmbed video) {
this.video = video;
}
public void setVideo(String url, int height, int width) {
VideoEmbed thumbnail = new VideoEmbed(url, height, width);
setVideo(thumbnail);
}
public ProviderEmbed getProvider() {
return provider;
}
@SuppressWarnings("unchecked")
public JSONObject getProviderJSON(){
JSONObject json = new JSONObject();
json.put("name", provider.getName());
json.put("url", provider.getUrl());
return json;
}
public void setProvider(ProviderEmbed provider) {
this.provider = provider;
}
public void setProvider(String name, String url) {
ProviderEmbed provider = new ProviderEmbed(name, url);
setProvider(provider);
}
public AuthorEmbed getAuthor() {
return author;
}
@SuppressWarnings("unchecked")
public JSONObject getAuthorJSON(){
JSONObject json = new JSONObject();
json.put("name", author.getName());
json.put("url", author.getUrl());
json.put("icon_url", author.getIcon_url());
json.put("proxy_icon_url", author.getProxy_icon_url());
return json;
}
public void setAuthor(AuthorEmbed author) {
this.author = author;
}
public void setAuthor(String name, String url, String icon_url, String proxy_icon_url) {
AuthorEmbed author = new AuthorEmbed(name, url, icon_url, proxy_icon_url);
setAuthor(author);
}
public Set<FieldEmbed> getFields() {
return fields;
}
@SuppressWarnings("unchecked")
public JSONArray getFieldsJSON(){
JSONArray json = new JSONArray();
for(FieldEmbed field : getFields()){
JSONObject one = new JSONObject();
one.put("name", field.getName());
one.put("value", field.getValue());
one.put("inline", field.getInline());
json.add(one);
}
return json;
}
public void setFields(Set<FieldEmbed> fields) {
this.fields = fields;
}
public void addFields(FieldEmbed field) {
this.fields.add(field);
}
public void addFields(String name, String value, boolean inline) {
FieldEmbed field = new FieldEmbed(name, value, inline);
this.fields.add(field);
}
@SuppressWarnings("unchecked")
public String build(){
JSONObject json = new JSONObject();
json.put("title", getTitle());
json.put("type", getType());
json.put("description", getDescription());
json.put("url", getUrl());
json.put("timestamp", getTimestamp());
json.put("color", getColor());
if(getFooter() != null){
json.put("footer", getFooterJSON());
}
if(getImage() != null){
json.put("image", getImageJSON());
}
if(getThumbnail() != null){
json.put("thumbnail", getThumbnailJSON());
}
if(getVideo() != null){
json.put("video", getVideoJSON());
}
if(getProvider() != null){
json.put("provider", getProviderJSON());
}
if(getAuthor() != null){
json.put("author", getAuthorJSON());
}
if(getFields().size() != 0){
json.put("fields", getFieldsJSON());
}
return json.toJSONString();
}
@SuppressWarnings("unchecked")
public JSONObject buildJSON(){
JSONObject json = new JSONObject();
json.put("title", getTitle());
json.put("type", getType());
json.put("description", getDescription());
json.put("url", getUrl());
json.put("timestamp", getTimestamp());
json.put("color", getColor());
if(getFooter() != null){
json.put("footer", getFooterJSON());
}
if(getImage() != null){
json.put("image", getImageJSON());
}
if(getThumbnail() != null){
json.put("thumbnail", getThumbnailJSON());
}
if(getVideo() != null){
json.put("video", getVideoJSON());
}
if(getProvider() != null){
json.put("provider", getProviderJSON());
}
if(getAuthor() != null){
json.put("author", getAuthorJSON());
}
if(getFields().size() != 0){
json.put("fields", getFieldsJSON());
}
return json;
}
}