-
-
Notifications
You must be signed in to change notification settings - Fork 724
/
MessageEmbed.java
954 lines (876 loc) · 30.9 KB
/
MessageEmbed.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
/*
* Copyright 2015-2017 Austin Keener & Michael Ritter & Florian Spieß
*
* 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;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.core.utils.Helpers;
import org.json.JSONArray;
import org.json.JSONObject;
import java.awt.Color;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Represents an embed displayed by Discord.
* <br>A visual representation of an Embed can be found at:
* <a href="http://imgur.com/a/yOb5n" target="_blank">http://imgur.com/a/yOb5n</a>
* <br>This class has many possibilities for null values, so be careful!
*/
public class MessageEmbed
{
/**
* The maximum length an embed title can have
*
* @see net.dv8tion.jda.core.EmbedBuilder#setTitle(String) EmbedBuilder.setTitle(title)
* @see net.dv8tion.jda.core.EmbedBuilder#addField(String, String, boolean) EmbedBuilder.addField(title, value, inline)
*/
public static final int TITLE_MAX_LENGTH = 256;
/**
* The maximum length an embed field value can have
*
* @see net.dv8tion.jda.core.EmbedBuilder#addField(String, String, boolean) EmbedBuilder.addField(title, value, inline)
*/
public static final int VALUE_MAX_LENGTH = 1024;
/**
* The maximum length the description and footer of an embed can have
*
* @see net.dv8tion.jda.core.EmbedBuilder#setFooter(String, String) EmbedBuilder.setFooter(text, iconUrl)
* @see net.dv8tion.jda.core.EmbedBuilder#setDescription(CharSequence) EmbedBuilder.setDescription(text)
*/
public static final int TEXT_MAX_LENGTH = 2048;
/**
* The maximum length any URL can have inside an embed
*
* @see net.dv8tion.jda.core.EmbedBuilder#setTitle(String, String) EmbedBuilder.setTitle(text, url)
* @see net.dv8tion.jda.core.EmbedBuilder#setAuthor(String, String, String) EmbedBuilder.setAuthor(text, url, iconUrl)
* @see net.dv8tion.jda.core.EmbedBuilder#setFooter(String, String) EmbedBuilder.setFooter(text, url)
*/
public static final int URL_MAX_LENGTH = 2000;
/**
* The maximum amount of total visible characters an embed can have
* <br>This limit depends on the current {@link net.dv8tion.jda.core.AccountType AccountType} and applies to BOT
*
* @see net.dv8tion.jda.core.EmbedBuilder#setDescription(CharSequence)
* @see net.dv8tion.jda.core.EmbedBuilder#setTitle(String)
* @see net.dv8tion.jda.core.EmbedBuilder#setFooter(String, String)
* @see net.dv8tion.jda.core.EmbedBuilder#addField(String, String, boolean)
*/
public static final int EMBED_MAX_LENGTH_BOT = 6000;
/**
* The maximum amount of total visible characters an embed can have
* <br>This limit depends on the current {@link net.dv8tion.jda.core.AccountType AccountType} and applies to CLIENT
*
* @see net.dv8tion.jda.core.EmbedBuilder#setDescription(CharSequence)
* @see net.dv8tion.jda.core.EmbedBuilder#setTitle(String)
* @see net.dv8tion.jda.core.EmbedBuilder#setFooter(String, String)
* @see net.dv8tion.jda.core.EmbedBuilder#addField(String, String, boolean)
*/
public static final int EMBED_MAX_LENGTH_CLIENT = 2000;
protected final Object mutex = new Object();
protected final String url;
protected final String title;
protected final String description;
protected final EmbedType type;
protected final OffsetDateTime timestamp;
protected final Color color;
protected final Thumbnail thumbnail;
protected final Provider siteProvider;
protected final AuthorInfo author;
protected final VideoInfo videoInfo;
protected final Footer footer;
protected final ImageInfo image;
protected final List<Field> fields;
protected volatile int length = -1;
protected volatile JSONObject json = null;
protected MessageEmbed(
String url, String title, String description, EmbedType type, OffsetDateTime timestamp,
Color color, Thumbnail thumbnail, Provider siteProvider, AuthorInfo author,
VideoInfo videoInfo, Footer footer, ImageInfo image, List<Field> fields)
{
this.url = url;
this.title = title;
this.description = description;
this.type = type;
this.timestamp = timestamp;
this.color = color;
this.thumbnail = thumbnail;
this.siteProvider = siteProvider;
this.author = author;
this.videoInfo = videoInfo;
this.footer = footer;
this.image = image;
this.fields = fields != null && !fields.isEmpty()
? Collections.unmodifiableList(fields) : Collections.emptyList();
}
/**
* The that was originally placed into chat that spawned this embed.
*
* @return Never-null String containing the original message url.
*/
public String getUrl()
{
return url;
}
/**
* The title of the embed. Typically this will be the html title of the webpage that is being embedded.<br>
* If no title could be found, like the case of {@link EmbedType EmbedType} = {@link net.dv8tion.jda.core.entities.EmbedType#IMAGE IMAGE},
* this method will return null.
*
* @return Possibly-null String containing the title of the embedded resource.
*/
public String getTitle()
{
return title;
}
/**
* The description of the embedded resource.
* <br>This is provided only if Discord could find a description for the embedded resource using the provided url.
* <br>Commonly, this is null. Be careful when using it.
*
* @return Possibly-null String containing a description of the embedded resource.
*/
public String getDescription()
{
return description;
}
/**
* The {@link net.dv8tion.jda.core.entities.EmbedType EmbedType} of this embed.
*
* @return The {@link net.dv8tion.jda.core.entities.EmbedType EmbedType} of this embed.
*/
public EmbedType getType()
{
return type;
}
/**
* The information about the {@link net.dv8tion.jda.core.entities.MessageEmbed.Thumbnail Thumbnail} image to be displayed with the embed.
* <br>If a {@link net.dv8tion.jda.core.entities.MessageEmbed.Thumbnail Thumbnail} was not part of this embed, this returns null.
*
* @return Possibly-null {@link net.dv8tion.jda.core.entities.MessageEmbed.Thumbnail Thumbnail} instance
* containing general information on the displayable thumbnail.
*/
public Thumbnail getThumbnail()
{
return thumbnail;
}
/**
* The information on site from which the embed was generated from.
* <br>If Discord did not generate any deliverable information about the site, this returns null.
*
* @return Possibly-null {@link net.dv8tion.jda.core.entities.MessageEmbed.Provider Provider}
* containing site information.
*/
public Provider getSiteProvider()
{
return siteProvider;
}
/**
* The information on the creator of the embedded content.
* <br>This is typically used to represent the account on the providing site.
*
* @return Possibly-null {@link net.dv8tion.jda.core.entities.MessageEmbed.AuthorInfo AuthorInfo}
* containing author information.
*/
public AuthorInfo getAuthor()
{
return author;
}
/**
* The information about the video which should be displayed as an embed.
* <br>This is used when sites with HTML5 players are linked and embedded. Most commonly Youtube.
* <br>If this {@link net.dv8tion.jda.core.entities.EmbedType EmbedType} != {@link net.dv8tion.jda.core.entities.EmbedType#VIDEO VIDEO}
* this will always return null.
*
* @return Possibly-null {@link net.dv8tion.jda.core.entities.MessageEmbed.VideoInfo VideoInfo}
* containing the information about the video which should be embedded.
*/
public VideoInfo getVideoInfo()
{
return videoInfo;
}
/**
* The footer (bottom) of the embedded content.
* <br>This is typically used for timestamps or site icons.
*
* @return Possibly-null {@link net.dv8tion.jda.core.entities.MessageEmbed.Footer Footer}
* containing the embed footer content.
*/
public Footer getFooter()
{
return footer;
}
/**
* The information about the image in the message embed
*
* @return Possibly-null {@link net.dv8tion.jda.core.entities.MessageEmbed.ImageInfo ImageInfo}
* containing image information.
*/
public ImageInfo getImage()
{
return image;
}
/**
* The fields in a message embed.
* <br>Message embeds can contain multiple fields, each with a name, value, and a boolean
* to determine if it will fall in-line with other fields. If the embed contains no
* fields, an empty list will be returned.
*
* @return Never-null (but possibly empty) List of {@link net.dv8tion.jda.core.entities.MessageEmbed.Field Field} objects
* containing field information.
*/
public List<Field> getFields()
{
return fields;
}
/**
* The color of the stripe on the side of the embed.
* <br>If the color is 0 (no color), this will return null.
*
* @return Possibly-null Color.
*/
public Color getColor()
{
return color;
}
/**
* The timestamp of the embed.
*
* @return Possibly-null OffsetDateTime object representing the timestamp.
*/
public OffsetDateTime getTimestamp()
{
return timestamp;
}
/**
* Whether this embed is empty.
*
* @return True, if this embed has no content
*/
public boolean isEmpty()
{
return getLength() == 0
&& getImage() == null
&& getThumbnail() == null;
}
/**
* The total amount of characters that is displayed when this embed is displayed by the Discord client.
*
* <p>An Embed can only have, at max, {@value #EMBED_MAX_LENGTH_BOT} displayable text characters for {@link net.dv8tion.jda.core.AccountType#BOT AccountType.BOT}
* accounts or {@value #EMBED_MAX_LENGTH_CLIENT} displayable text characters for {@link net.dv8tion.jda.core.AccountType#CLIENT AccountType.CLIENT} accounts.
*
* <p>Both of these values are defined by {@link #EMBED_MAX_LENGTH_BOT EMBED_MAX_LENGTH_BOT} and
* {@link #EMBED_MAX_LENGTH_CLIENT EMBED_MAX_LENGTH_CLIENT} respectively.
*
* @return A never-negative sum of all displayed text characters.
*/
public int getLength()
{
if (length > -1)
return length;
synchronized (mutex)
{
if (length > -1)
return length;
length = 0;
if (title != null)
length += title.length();
if (description != null)
length += description.length();
if (author != null)
length += author.getName().length();
if (footer != null)
length += footer.getText().length();
if (fields != null)
{
for (Field f : fields)
length += f.getName().length() + f.getValue().length();
}
return length;
}
}
/**
* Whether this MessageEmbed can be used in a message.
* <br>This applies to {@link net.dv8tion.jda.core.AccountType#BOT Bot}- and {@link net.dv8tion.jda.core.AccountType#CLIENT Client Accounts}
*
* <p>Total Character Limits
* <ul>
* <li>Bot: {@value #EMBED_MAX_LENGTH_BOT}</li>
* <li>Client: {@value #EMBED_MAX_LENGTH_CLIENT}</li>
* </ul>
*
* @param type
* The {@link net.dv8tion.jda.core.AccountType AccountType} to inspect
*
* @throws java.lang.IllegalArgumentException
* If the provided AccountType is {@code null} or not supported by this operation
*
* @return True, if this MessageEmbed can be used to send messages for this specified AccountType
*
* @see #getLength()
*/
public boolean isSendable(AccountType type)
{
Checks.notNull(type, "AccountType");
final int length = getLength();
if (isEmpty())
return false;
switch (type)
{
case BOT: return length <= EMBED_MAX_LENGTH_BOT;
case CLIENT: return length <= EMBED_MAX_LENGTH_CLIENT;
default: throw new IllegalArgumentException(String.format("Cannot check against AccountType '%s'!", type));
}
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof MessageEmbed))
return false;
if (obj == this)
return true;
MessageEmbed other = (MessageEmbed) obj;
return Objects.equals(url, other.url)
&& Objects.equals(title, other.title)
&& Objects.equals(description, other.description)
&& Objects.equals(type, other.type)
&& Objects.equals(thumbnail, other.thumbnail)
&& Objects.equals(siteProvider, other.siteProvider)
&& Objects.equals(author, other.author)
&& Objects.equals(videoInfo, other.videoInfo)
&& Objects.equals(footer, other.footer)
&& Objects.equals(image, other.image)
&& Objects.equals(color, other.color)
&& Objects.equals(timestamp, other.timestamp)
&& Helpers.deepEquals(fields, other.fields);
}
/**
* Creates a new {@link org.json.JSONObject JSONObject}
* used for sending.
*
* @return JSONObject for this embed
*/
public JSONObject toJSONObject()
{
if (json != null)
return json;
synchronized (mutex)
{
if (json != null)
return json;
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();
for (Field field : fields)
{
fieldsArray
.put(new JSONObject()
.put("name", field.getName())
.put("value", field.getValue())
.put("inline", field.isInline()));
}
obj.put("fields", fieldsArray);
}
return json = obj;
}
}
/**
* Represents the information Discord provided about a thumbnail image that should be
* displayed with an embed message.
*/
public static class Thumbnail
{
protected final String url;
protected final String proxyUrl;
protected final int width;
protected final int height;
public Thumbnail(String url, String proxyUrl, int width, int height)
{
this.url = url;
this.proxyUrl = proxyUrl;
this.width = width;
this.height = height;
}
/**
* The web url of this thumbnail image.
*
* @return Never-null String containing the url of the displayed image.
*/
public String getUrl()
{
return url;
}
/**
* The Discord proxied url of the thumbnail image.
* <br>This url is used to access the image through Discord instead of directly to prevent ip scraping.
*
* @return Never-null String containing the proxied url of this image.
*/
public String getProxyUrl()
{
return proxyUrl;
}
/**
* The width of the thumbnail image.
*
* @return Never-negative, Never-zero int containing the width of the image.
*/
public int getWidth()
{
return width;
}
/**
* The height of the thumbnail image.
*
* @return Never-negative, Never-zero int containing the height of the image.
*/
public int getHeight()
{
return height;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof Thumbnail))
return false;
Thumbnail thumbnail = (Thumbnail) obj;
return thumbnail == this || (Objects.equals(thumbnail.url, url)
&& Objects.equals(thumbnail.proxyUrl, proxyUrl)
&& thumbnail.width == width
&& thumbnail.height == height);
}
}
/**
* Multipurpose class that represents a provider of content,
* whether directly through creation or indirectly through hosting.
*/
public static class Provider
{
protected final String name;
protected final String url;
public Provider(String name, String url)
{
this.name = name;
this.url = url;
}
/**
* The name of the provider.
* <br>If this is an author, most likely the author's username.
* <br>If this is a website, most likely the site's name.
*
* @return Never-null String containing the name of the provider.
*/
public String getName()
{
return name;
}
/**
* The url of the provider.
*
* @return Possibly-null String containing the url of the provider.
*/
public String getUrl()
{
return url;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof Provider))
return false;
Provider provider = (Provider) obj;
return provider == this || (Objects.equals(provider.name, name)
&& Objects.equals(provider.url, url));
}
}
/**
* Represents the information provided to embed a video.
* <br>The videos represented are expected to be played using an HTML5 player from the
* site which the url belongs to.
*/
public static class VideoInfo
{
protected final String url;
protected final int width;
protected final int height;
public VideoInfo(String url, int width, int height)
{
this.url = url;
this.width = width;
this.height = height;
}
/**
* The url of the video.
*
* @return Never-null String containing the video url.
*/
public String getUrl()
{
return url;
}
/**
* The width of the video.
* <br>This usually isn't the actual video width, but instead the starting embed window size.
*
* <p>Basically: Don't rely on this to represent the actual video's quality or size.
*
* @return Non-negative, Non-zero int containing the width of the embedded video.
*/
public int getWidth()
{
return width;
}
/**
* The height of the video.
* <br>This usually isn't the actual video height, but instead the starting embed window size.
*
* <p>Basically: Don't rely on this to represent the actual video's quality or size.
*
* @return
* Non-negative, Non-zero int containing the height of the embedded video.
*/
public int getHeight()
{
return height;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof VideoInfo))
return false;
VideoInfo video = (VideoInfo) obj;
return video == this || (Objects.equals(video.url, url)
&& video.width == width
&& video.height == height);
}
}
/**
* Represents the information provided to embed an image.
*/
public static class ImageInfo
{
protected final String url;
protected final String proxyUrl;
protected final int width;
protected final int height;
public ImageInfo(String url, String proxyUrl, int width, int height)
{
this.url = url;
this.proxyUrl = proxyUrl;
this.width = width;
this.height = height;
}
/**
* The url of the image.
*
* @return Never-null String containing the image url.
*/
public String getUrl()
{
return url;
}
/**
* The url of the image, proxied by Discord
* <br>This url is used to access the image through Discord instead of directly to prevent ip scraping.
*
* @return Never-null String containing the proxied image url.
*/
public String getProxyUrl()
{
return proxyUrl;
}
/**
* The width of the image.
*
* @return Non-negative, Non-zero int containing the width of the embedded image.
*/
public int getWidth()
{
return width;
}
/**
* The height of the image.
*
* @return Non-negative, Non-zero int containing the height of the embedded image.
*/
public int getHeight()
{
return height;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof ImageInfo))
return false;
ImageInfo image = (ImageInfo) obj;
return image == this || (Objects.equals(image.url, url)
&& Objects.equals(image.proxyUrl, proxyUrl)
&& image.width == width
&& image.height == height);
}
}
/**
* Class that represents the author of content, possibly including an icon
* that Discord proxies.
*/
public static class AuthorInfo
{
protected final String name;
protected final String url;
protected final String iconUrl;
protected final String proxyIconUrl;
public AuthorInfo(String name, String url, String iconUrl, String proxyIconUrl)
{
this.name = name;
this.url = url;
this.iconUrl = iconUrl;
this.proxyIconUrl = proxyIconUrl;
}
/**
* The name of the Author.
* <br>This is most likely the name of the account associated with the embed
*
* @return Possibly-null String containing the name of the author.
*/
public String getName()
{
return name;
}
/**
* The url of the author.
*
* @return Possibly-null String containing the url of the author.
*/
public String getUrl()
{
return url;
}
/**
* The url of the author's icon.
*
* @return Possibly-null String containing the author's icon url.
*/
public String getIconUrl()
{
return iconUrl;
}
/**
* The url of the author's icon, proxied by Discord
* <br>This url is used to access the image through Discord instead of directly to prevent ip scraping.
*
* @return Possibly-null String containing the proxied icon url.
*/
public String getProxyIconUrl()
{
return proxyIconUrl;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof AuthorInfo))
return false;
AuthorInfo author = (AuthorInfo) obj;
return author == this || (Objects.equals(author.name, name)
&& Objects.equals(author.url, url)
&& Objects.equals(author.iconUrl, iconUrl)
&& Objects.equals(author.proxyIconUrl, proxyIconUrl));
}
}
/**
* Class that represents a footer at the bottom of an embed
*/
public static class Footer
{
protected final String text;
protected final String iconUrl;
protected final String proxyIconUrl;
public Footer(String text, String iconUrl, String proxyIconUrl)
{
this.text = text;
this.iconUrl = iconUrl;
this.proxyIconUrl = proxyIconUrl;
}
/**
* The text in the footer
*
* @return Possibly-null String containing the text in the footer.
*/
public String getText()
{
return text;
}
/**
* The url of the footer's icon.
*
* @return Possibly-null String containing the footer's icon url.
*/
public String getIconUrl()
{
return iconUrl;
}
/**
* The url of the footer's icon, proxied by Discord
* <br>This url is used to access the image through Discord instead of directly to prevent ip scraping.
*
* @return Possibly-null String containing the proxied icon url.
*/
public String getProxyIconUrl()
{
return proxyIconUrl;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof Footer))
return false;
Footer footer = (Footer) obj;
return footer == this || (Objects.equals(footer.text, text)
&& Objects.equals(footer.iconUrl, iconUrl)
&& Objects.equals(footer.proxyIconUrl, proxyIconUrl));
}
}
/**
* Represents a field in an embed. A single embed contains an array of
* embed fields, each with a name and value, and a boolean determining if
* the field can display on the same line as previous fields if there is
* enough space horizontally.
*
* @since 3.0
* @author John A. Grosh
*/
public static class Field
{
protected final String name;
protected final String value;
protected final boolean inline;
protected Field(String name, String value, boolean inline, boolean checked)
{
if (checked)
{
if (name == null || value == null)
throw new IllegalArgumentException("Both Name and Value must be set!");
else if (name.length() > TITLE_MAX_LENGTH)
throw new IllegalArgumentException("Name cannot be longer than " + TITLE_MAX_LENGTH + " characters.");
else if (value.length() > VALUE_MAX_LENGTH)
throw new IllegalArgumentException("Value cannot be longer than " + VALUE_MAX_LENGTH + " characters.");
if (name.isEmpty())
this.name = EmbedBuilder.ZERO_WIDTH_SPACE;
else
this.name = name;
if (value.isEmpty())
this.value = EmbedBuilder.ZERO_WIDTH_SPACE;
else
this.value = value;
this.inline = inline;
}
else
{
this.name = name;
this.value = value;
this.inline = inline;
}
}
public Field(String name, String value, boolean inline)
{
this(name, value, inline, true);
}
/**
* The name of the field
*
* @return Possibly-null String containing the name of the field.
*/
public String getName()
{
return name;
}
/**
* The value of the field
*
* @return Possibly-null String containing the value (contents) of the field.
*/
public String getValue()
{
return value;
}
/**
* If the field is in line.
*
* @return true if the field can be in line with other fields, false otherwise.
*/
public boolean isInline()
{
return inline;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof Field))
return false;
final Field field = (Field) obj;
return field == this || (field.inline == inline
&& Objects.equals(field.name, name)
&& Objects.equals(field.value, value));
}
}
}