-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
MessageEmbedImpl.java
278 lines (246 loc) · 6.88 KB
/
MessageEmbedImpl.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
/*
* Copyright 2015-2016 Austin Keener & Michael Ritter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dv8tion.jda.core.entities.impl;
import java.awt.Color;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import net.dv8tion.jda.core.entities.EmbedType;
import net.dv8tion.jda.core.entities.MessageEmbed;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONString;
public class MessageEmbedImpl implements MessageEmbed, JSONString
{
private String url;
private String title;
private String description;
private EmbedType type;
private OffsetDateTime timestamp;
private Color color;
private Thumbnail thumbnail;
private Provider siteProvider;
private AuthorInfo author;
private VideoInfo videoInfo;
private Footer footer;
private ImageInfo image;
private List<Field> fields;
@Override
public String getUrl()
{
return url;
}
@Override
public String getTitle()
{
return title;
}
@Override
public String getDescription()
{
return description;
}
@Override
public EmbedType getType()
{
return type;
}
@Override
public Thumbnail getThumbnail()
{
return thumbnail;
}
@Override
public Provider getSiteProvider()
{
return siteProvider;
}
@Override
public AuthorInfo getAuthor()
{
return author;
}
@Override
public VideoInfo getVideoInfo()
{
return videoInfo;
}
@Override
public Footer getFooter() {
return footer;
}
@Override
public ImageInfo getImage() {
return image;
}
@Override
public List<Field> getFields() {
return Collections.unmodifiableList(fields);
}
@Override
public Color getColor() {
return color;
}
@Override
public OffsetDateTime getTimestamp() {
return timestamp;
}
public MessageEmbedImpl setUrl(String url)
{
this.url = url;
return this;
}
public MessageEmbedImpl setTitle(String title)
{
this.title = title;
return this;
}
public MessageEmbedImpl setDescription(String description)
{
this.description = description;
return this;
}
public MessageEmbedImpl setType(EmbedType type)
{
this.type = type;
return this;
}
public MessageEmbedImpl setThumbnail(Thumbnail thumbnail)
{
this.thumbnail = thumbnail;
return this;
}
public MessageEmbedImpl setSiteProvider(Provider siteProvider)
{
this.siteProvider = siteProvider;
return this;
}
public MessageEmbedImpl setAuthor(AuthorInfo author)
{
this.author = author;
return this;
}
public MessageEmbedImpl setVideoInfo(VideoInfo videoInfo)
{
this.videoInfo = videoInfo;
return this;
}
public MessageEmbedImpl setFooter(Footer footer)
{
this.footer = footer;
return this;
}
public MessageEmbedImpl setImage(ImageInfo image)
{
this.image = image;
return this;
}
public MessageEmbedImpl setFields(List<Field> fields)
{
this.fields = fields;
return this;
}
public MessageEmbedImpl setColor(Color color)
{
this.color = color;
return this;
}
public MessageEmbedImpl setTimestamp(OffsetDateTime timestamp)
{
this.timestamp = timestamp;
return this;
}
@Override
public boolean equals(Object o)
{
if (!(o instanceof MessageEmbed))
return false;
MessageEmbed oMsg = (MessageEmbed) o;
return this == oMsg;
}
@Override
public int hashCode()
{
return getUrl().hashCode();
}
@Override
public String toString()
{
return "EmbedMessage";
}
@Override
public String toJSONString()
{
JSONObject obj = new JSONObject();
if (url != null)
obj.put("url", url);
if (title != null)
obj.put("title", title);
if (description != null)
obj.put("description", description);
if (timestamp != null)
obj.put("timestamp", timestamp.format(DateTimeFormatter.ISO_INSTANT));
if (color != null)
obj.put("color", color.getRGB() & 0xFFFFFF);
if (thumbnail != null)
obj.put("thumbnail", new JSONObject().put("url", thumbnail.getUrl()));
if (siteProvider != null)
{
JSONObject siteProviderObj = new JSONObject();
if (siteProvider.getName() != null)
siteProviderObj.put("name", siteProvider.getName());
if (siteProvider.getUrl() != null)
siteProviderObj.put("url", siteProvider.getUrl());
obj.put("provider", siteProviderObj);
}
if (author != null)
{
JSONObject authorObj = new JSONObject();
if (author.getName() != null)
authorObj.put("name", author.getName());
if (author.getUrl() != null)
authorObj.put("url", author.getUrl());
if (author.getIconUrl() != null)
authorObj.put("icon_url", author.getIconUrl());
obj.put("author", authorObj);
}
if (videoInfo != null)
obj.put("video", new JSONObject().put("url", videoInfo.getUrl()));
if (footer != null)
{
JSONObject footerObj = new JSONObject();
if (footer.getText() != null)
footerObj.put("text", footer.getText());
if (footer.getIconUrl() != null)
footerObj.put("icon_url", footer.getIconUrl());
obj.put("footer", footerObj);
}
if (image != null)
obj.put("image", new JSONObject().put("url", image.getUrl()));
if (!fields.isEmpty())
{
JSONArray fieldsArray = new JSONArray();
fields.stream().forEach(field ->
fieldsArray.put(new JSONObject()
.put("name", field.getName())
.put("value", field.getValue())
.put("inline",field.isInline())));
obj.put("fields", fieldsArray);
}
return obj.toString();
}
}