/
WidgetUtil.java
961 lines (868 loc) · 32.7 KB
/
WidgetUtil.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
955
956
957
958
959
960
961
/*
* 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.utils;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import gnu.trove.map.TLongObjectMap;
import gnu.trove.map.hash.TLongObjectHashMap;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.IMentionable;
import net.dv8tion.jda.core.entities.ISnowflake;
import net.dv8tion.jda.core.entities.impl.UserImpl;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
import net.dv8tion.jda.core.requests.Requester;
import org.apache.http.util.Args;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* The WidgetUtil is a class for interacting with various facets of Discord's
* guild widgets
*
* @since 3.0
* @author John A. Grosh
*/
public class WidgetUtil
{
public static final String WIDGET_PNG = Requester.DISCORD_API_PREFIX + "guilds/%s/widget.png?style=%s";
public static final String WIDGET_URL = Requester.DISCORD_API_PREFIX + "guilds/%s/widget.json";
public static final String WIDGET_HTML = "<iframe src=\"https://discordapp.com/widget?id=%s&theme=%s\" width=\"%d\" height=\"%d\" allowtransparency=\"true\" frameborder=\"0\"></iframe>";
/**
* Gets the banner image for the specified guild of the specified type.
* <br>This banner will only be available if the guild in question has the
* Widget enabled.
*
* @param guild
* The guild
* @param type
* The type (visual style) of the banner
*
* @return A String containing the URL of the banner image
*/
public static String getWidgetBanner(Guild guild, BannerType type)
{
Args.notNull(guild, "Guild");
return getWidgetBanner(guild.getId(), type);
}
/**
* Gets the banner image for the specified guild of the specified type.
* <br>This banner will only be available if the guild in question has the
* Widget enabled. Additionally, this method can be used independently of
* being on the guild in question.
*
* @param guildId
* the guild ID
* @param type
* The type (visual style) of the banner
*
* @return A String containing the URL of the banner image
*/
public static String getWidgetBanner(String guildId, BannerType type)
{
Args.notNull(guildId, "GuildId");
Args.notNull(type, "BannerType");
return String.format(WIDGET_PNG, guildId, type.name().toLowerCase());
}
/**
* Gets the pre-made HTML Widget for the specified guild using the specified
* settings. The widget will only display correctly if the guild in question
* has the Widget enabled.
*
* @param guild
* the guild
* @param theme
* the theme, light or dark
* @param width
* the width of the widget
* @param height
* the height of the widget
*
* @return a String containing the pre-made widget with the supplied settings
*/
public static String getPremadeWidgetHtml(Guild guild, WidgetTheme theme, int width, int height)
{
Args.notNull(guild, "Guild");
return getPremadeWidgetHtml(guild.getId(), theme, width, height);
}
/**
* Gets the pre-made HTML Widget for the specified guild using the specified
* settings. The widget will only display correctly if the guild in question
* has the Widget enabled. Additionally, this method can be used independently
* of being on the guild in question.
*
* @param guildId
* the guild ID
* @param theme
* the theme, light or dark
* @param width
* the width of the widget
* @param height
* the height of the widget
*
* @return a String containing the pre-made widget with the supplied settings
*/
public static String getPremadeWidgetHtml(String guildId, WidgetTheme theme, int width, int height)
{
Args.notNull(guildId, "GuildId");
Args.notNull(theme, "WidgetTheme");
Args.notNegative(width, "Width");
Args.notNegative(height, "Height");
return String.format(WIDGET_HTML, guildId, theme.name().toLowerCase(), width, height);
}
/**
* Makes a GET request to get the information for a Guild's widget. This
* widget (if available) contains information about the guild, including the
* Guild's name, an invite code (if set), a list of voice channels, and a
* list of online members (plus the voice states of any members in voice
* channels).
*
* <p>This Widget can be obtained from any valid guild ID that has
* it enabled; no accounts need to be on the server to access this information.
*
* @param guildId
* The id of the Guild
*
* @throws net.dv8tion.jda.core.exceptions.RateLimitedException
* If the request was rate limited, <b>respect the timeout</b>!
* @throws java.lang.NumberFormatException
* If the provided {@code guildId} cannot be parsed by {@link Long#parseLong(String)}
*
* @return {@code null} if the provided guild ID is not a valid Discord guild ID
* <br>a Widget object with null fields and isAvailable() returning
* false if the guild ID is valid but the guild in question does not
* have the widget enabled
* <br>a filled-in Widget object if the guild ID is valid and the guild
* in question has the widget enabled.
*/
public static Widget getWidget(String guildId) throws RateLimitedException
{
return getWidget(MiscUtil.parseSnowflake(guildId));
}
/**
* Makes a GET request to get the information for a Guild's widget. This
* widget (if available) contains information about the guild, including the
* Guild's name, an invite code (if set), a list of voice channels, and a
* list of online members (plus the voice states of any members in voice
* channels).
*
* <p>This Widget can be obtained from any valid guild ID that has
* it enabled; no accounts need to be on the server to access this information.
*
* @param guildId
* The id of the Guild
*
* @throws net.dv8tion.jda.core.exceptions.RateLimitedException
* If the request was rate limited, <b>respect the timeout</b>!
*
* @return {@code null} if the provided guild ID is not a valid Discord guild ID
* <br>a Widget object with null fields and isAvailable() returning
* false if the guild ID is valid but the guild in question does not
* have the widget enabled
* <br>a filled-in Widget object if the guild ID is valid and the guild
* in question has the widget enabled.
*/
public static Widget getWidget(long guildId) throws RateLimitedException
{
Args.notNull(guildId, "GuildId");
try
{
HttpResponse<JsonNode> result = Unirest.get(String.format(WIDGET_URL, guildId)).asJson();
switch(result.getStatus())
{
case 200: return new Widget(result.getBody().getObject()); // ok
case 400: // not valid snowflake
case 404: return null; // guild not found
case 403: return new Widget(guildId); // widget disabled
case 429: // ratelimited
{
long retryAfter;
try
{
retryAfter = result.getBody().getObject().getLong("retry_after");
}
catch (Exception e)
{
retryAfter = 0;
}
throw new RateLimitedException(WIDGET_URL, retryAfter);
}
default: throw new RuntimeException("An unknown status was returned: " + result.getStatus() + " " + result.getStatusText());
}
}
catch (UnirestException ex)
{
throw new RuntimeException(ex);
}
}
/**
* Represents the available banner types
* <br>Each of these has a different appearance:
*
* <p>
* <br><b>Shield</b> - tiny, only contains Discord logo and online count
* <br><b>Banner1</b> - medium, contains server name, icon, and online count, and a "Powered by Discord" bar on the bottom
* <br><b>Banner2</b> - small, contains server name, icon, and online count, and a Discord logo on the side
* <br><b>Banner3</b> - medium, contains server name, icon, and online count, and a Discord logo with a "Chat Now" bar on the bottom
* <br><b>Banner4</b> - large, contains a very big Discord logo, server name, icon, and online count, and a big "Join My Server" button
*/
public enum BannerType
{
SHIELD, BANNER1, BANNER2, BANNER3, BANNER4
}
/**
* Represents the color scheme of the widget
* <br>These color themes match Discord's dark and light themes
*/
public enum WidgetTheme
{
LIGHT, DARK
}
public static class Widget implements ISnowflake
{
private final boolean isAvailable;
private final long id;
private final String name;
private final String invite;
private final TLongObjectMap<VoiceChannel> channels;
private final TLongObjectMap<Member> members;
/**
* Constructs an unavailable Widget
*/
private Widget(long guildId)
{
isAvailable = false;
id = guildId;
name = null;
invite = null;
channels = new TLongObjectHashMap<>();
members = new TLongObjectHashMap<>();
}
/**
* Constructs an available Widget
*
* @param json
* The {@link org.json.JSONObject JSONObject} to construct the Widget from
*/
private Widget(JSONObject json)
{
String inviteCode = json.isNull("instant_invite") ? null : json.getString("instant_invite");
if (inviteCode != null)
inviteCode = inviteCode.substring(inviteCode.lastIndexOf("/") + 1);
isAvailable = true;
id = json.getLong("id");
name = json.getString("name");
invite = inviteCode;
channels = MiscUtil.newLongMap();
members = MiscUtil.newLongMap();
JSONArray channelsJson = json.getJSONArray("channels");
for (int i = 0; i < channelsJson.length(); i++)
{
JSONObject channel = channelsJson.getJSONObject(i);
channels.put(channel.getLong("id"), new VoiceChannel(channel, this));
}
JSONArray membersJson = json.getJSONArray("members");
for (int i = 0; i<membersJson.length(); i++)
{
JSONObject memberJson = membersJson.getJSONObject(i);
Member member = new Member(memberJson, this);
if (!memberJson.isNull("channel_id")) // voice state
{
VoiceChannel channel = channels.get(memberJson.getLong("channel_id"));
member.setVoiceState(new VoiceState(channel,
memberJson.getBoolean("mute"),
memberJson.getBoolean("deaf"),
memberJson.getBoolean("suppress"),
memberJson.getBoolean("self_mute"),
memberJson.getBoolean("self_deaf"),
member,
this));
channel.addMember(member);
}
members.put(member.getIdLong(), member);
}
}
/**
* Shows whether or not the widget for a guild is available. If this
* method returns false, all other values will be null
*
* @return True, if the widget is available, false otherwise
*/
public boolean isAvailable()
{
return isAvailable;
}
@Override
public long getIdLong()
{
return id;
}
/**
* Gets the name of the guild
*
* @throws IllegalStateException
* If the widget is not {@link #isAvailable() available}
*
* @return the name of the guild
*/
public String getName()
{
checkAvailable();
return name;
}
/**
* Gets an invite code for the guild, or null if no invite channel is
* enabled in the widget
*
* @throws IllegalStateException
* If the widget is not {@link #isAvailable() available}
*
* @return an invite code for the guild, if widget invites are enabled
*/
public String getInviteCode()
{
checkAvailable();
return invite;
}
/**
* Gets the list of voice channels in the guild
*
* @throws IllegalStateException
* If the widget is not {@link #isAvailable() available}
*
* @return the list of voice channels in the guild
*/
public List<VoiceChannel> getVoiceChannels()
{
checkAvailable();
return Collections.unmodifiableList(new ArrayList<>(channels.valueCollection()));
}
/**
* Gets a voice channel with the given ID, or null if the voice channel is not found
*
* @param id
* the ID of the voice channel
*
* @throws IllegalStateException
* If the widget is not {@link #isAvailable() available}
* @throws NumberFormatException
* If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)}
*
* @return possibly-null VoiceChannel with the given ID.
*/
public VoiceChannel getVoiceChannelById(String id)
{
checkAvailable();
return channels.get(MiscUtil.parseSnowflake(id));
}
/**
* Gets a voice channel with the given ID, or {@code null} if the voice channel is not found
*
* @param id
* the ID of the voice channel
*
* @throws IllegalStateException
* If the widget is not {@link #isAvailable() available}
*
* @return possibly-null VoiceChannel with the given ID.
*/
public VoiceChannel getVoiceChannelById(long id)
{
checkAvailable();
return channels.get(id);
}
/**
* Gets a list of online members in the guild
*
* @throws IllegalStateException
* If the widget is not {@link #isAvailable() available}
*
* @return the list of members
*/
public List<Member> getMembers()
{
checkAvailable();
return Collections.unmodifiableList(new ArrayList<>(members.valueCollection()));
}
/**
* Gets a member with the given ID, or null if the member is not found
*
* @param id
* the ID of the member
*
* @throws NumberFormatException
* If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)}
* @throws IllegalStateException
* If the widget is not {@link #isAvailable() available}
*
* @return possibly-null Member with the given ID.
*/
public Member getMemberById(String id)
{
checkAvailable();
return members.get(MiscUtil.parseSnowflake(id));
}
/**
* Gets a member with the given ID, or {@code null} if the member is not found
*
* @param id
* the ID of the member
*
* @throws IllegalStateException
* If the widget is not {@link #isAvailable() available}
*
* @return possibly-null Member with the given ID.
*/
public Member getMemberById(long id)
{
checkAvailable();
return members.get(id);
}
@Override
public int hashCode() {
return Long.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Widget))
return false;
Widget oWidget = (Widget) obj;
return this == oWidget || this.id == oWidget.getIdLong();
}
@Override
public String toString()
{
return "W:" + (isAvailable() ? getName() : "") + '(' + id + ')';
}
private void checkAvailable()
{
if (!isAvailable)
throw new IllegalStateException("The widget for this Guild is unavailable!");
}
public static class Member implements ISnowflake, IMentionable
{
private final boolean bot;
private final long id;
private final String username;
private final String discriminator;
private final String avatar;
private final String nickname;
private final OnlineStatus status;
private final Game game;
private final Widget widget;
private VoiceState state;
private Member(JSONObject json, Widget widget)
{
this.widget = widget;
this.bot = !json.isNull("bot") && json.getBoolean("bot");
this.id = json.getLong("id");
this.username = json.getString("username");
this.discriminator = json.getString("discriminator");
this.avatar = json.isNull("avatar") ? null : json.getString("avatar");
this.nickname = json.isNull("nick") ? null : json.getString("nick");
this.status = OnlineStatus.fromKey(json.getString("status"));
this.game = json.isNull("game") ? null :
json.getJSONObject("game").isNull("name") || json.getJSONObject("game").getString("name").isEmpty() ? null :
Game.of(json.getJSONObject("game").getString("name"));
}
private void setVoiceState(VoiceState voiceState)
{
state = voiceState;
}
/**
* Returns whether or not the given member is a bot account
*
* @return true if the member is a bot, false otherwise
*/
public boolean isBot()
{
return bot;
}
/**
* Returns the username of the member
*
* @return the username of the member
*/
public String getName()
{
return username;
}
@Override
public long getIdLong()
{
return id;
}
@Override
public String getAsMention()
{
return "<@" + getId() + ">";
}
/**
* Gets the discriminator of the member
*
* @return the never-null discriminator of the member
*/
public String getDiscriminator()
{
return discriminator;
}
/**
* Gets the avatar hash of the member, or null if they do not have
* an avatar set.
*
* @return possibly-null String containing the avatar hash of the
* member
*/
public String getAvatarId()
{
return avatar;
}
/**
* Gets the avatar url of the member, or null if they do not have
* an avatar set.
*
* @return possibly-null String containing the avatar url of the
* member
*/
public String getAvatarUrl()
{
return getAvatarId() == null ? null : "https://cdn.discordapp.com/avatars/" + getId() + "/" + getAvatarId()
+ (getAvatarId().startsWith("a_") ? ".gif" : ".png");
}
/**
* Gets the asset id of the member's default avatar
*
* @return never-null String containing the asset id of the member's
* default avatar
*/
public String getDefaultAvatarId()
{
return UserImpl.DefaultAvatar.values()[Integer.parseInt(getDiscriminator()) % UserImpl.DefaultAvatar.values().length].toString();
}
/**
* Gets the url of the member's default avatar
*
* @return never-null String containing the url of the member's
* default avatar
*/
public String getDefaultAvatarUrl()
{
return "https://discordapp.com/assets/" + getDefaultAvatarId() + ".png";
}
/**
* The URL for the user's avatar image
* <br>If they do not have an avatar set, this will return the URL of their
* default avatar
*
* @return Never-null String containing the member's effective avatar url.
*/
public String getEffectiveAvatarUrl()
{
return getAvatarUrl() == null ? getDefaultAvatarUrl() : getAvatarUrl();
}
/**
* Gets the nickname of the member. If they do not have a nickname on
* the guild, this will return null;
*
* @return possibly-null String containing the nickname of the member
*/
public String getNickname()
{
return nickname;
}
/**
* Gets the visible name of the member. If they have a nickname set,
* this will be their nickname. Otherwise, it will be their username.
*
* @return never-null String containing the member's effective (visible) name
*/
public String getEffectiveName()
{
return nickname == null ? username : nickname;
}
/**
* Gets the online status of the member. The widget does not show
* offline members, so this status should never be offline
*
* @return the {@link net.dv8tion.jda.core.OnlineStatus OnlineStatus} of the member
*/
public OnlineStatus getOnlineStatus()
{
return status;
}
/**
* The game that the member is currently playing.
* <br>This game cannot be a stream.
* If the user is not currently playing a game, this will return null.
*
* @return Possibly-null {@link net.dv8tion.jda.core.entities.Game Game} containing the game
* that the member is currently playing.
*/
public Game getGame()
{
return game;
}
/**
* The current voice state of the member.
* <br>If the user is not in voice, this will return a VoiceState with a null channel.
*
* @return never-null VoiceState of the member
*/
public VoiceState getVoiceState()
{
return state == null ? new VoiceState(this, widget) : state;
}
/**
* Gets the widget that to which this member belongs
*
* @return the Widget that holds this member
*/
public Widget getWidget()
{
return widget;
}
@Override
public int hashCode() {
return (widget.getId() + ' ' + id).hashCode();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Member))
return false;
Member oMember = (Member) obj;
return this == oMember || (this.id == oMember.getIdLong() && this.widget.getIdLong() == oMember.getWidget().getIdLong());
}
@Override
public String toString()
{
return "W.M:" + getName() + '(' + id + ')';
}
}
public static class VoiceChannel implements ISnowflake
{
private final int position;
private final long id;
private final String name;
private final List<Member> members;
private final Widget widget;
private VoiceChannel(JSONObject json, Widget widget)
{
this.widget = widget;
this.position = json.getInt("position");
this.id = json.getLong("id");
this.name = json.getString("name");
this.members = new ArrayList<>();
}
private void addMember(Member member)
{
members.add(member);
}
/**
* Gets the integer position of the channel
*
* @return integer position of the channel
*/
public int getPosition()
{
return position;
}
@Override
public long getIdLong()
{
return id;
}
/**
* Gets the name of the channel
*
* @return name of the channel
*/
public String getName()
{
return name;
}
/**
* Gets a list of all members in the channel
*
* @return never-null, possibly-empty list of members in the channel
*/
public List<Member> getMembers()
{
return members;
}
/**
* Gets the Widget to which this voice channel belongs
*
* @return the Widget object that holds this voice channel
*/
public Widget getWidget()
{
return widget;
}
@Override
public int hashCode() {
return Long.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof VoiceChannel))
return false;
VoiceChannel oVChannel = (VoiceChannel) obj;
return this == oVChannel || this.id == oVChannel.getIdLong();
}
@Override
public String toString()
{
return "W.VC:" + getName() + '(' + id + ')';
}
}
public static class VoiceState
{
private final VoiceChannel channel;
private final boolean muted;
private final boolean deafened;
private final boolean suppress;
private final boolean selfMute;
private final boolean selfDeaf;
private final Member member;
private final Widget widget;
private VoiceState(Member member, Widget widget)
{
this(null, false, false, false, false, false, member, widget);
}
private VoiceState(VoiceChannel channel, boolean muted, boolean deafened, boolean suppress, boolean selfMute, boolean selfDeaf, Member member, Widget widget)
{
this.channel = channel;
this.muted = muted;
this.deafened = deafened;
this.suppress = suppress;
this.selfMute = selfMute;
this.selfDeaf = selfDeaf;
this.member = member;
this.widget = widget;
}
/**
* Gets the channel the member is in
*
* @return never-null VoiceChannel
*/
public VoiceChannel getChannel()
{
return channel;
}
/**
* Used to determine if the member is currently in a voice channel.
* <br>If this is false, getChannel() will return null
*
* @return True, if the member is in a voice channel
*/
public boolean inVoiceChannel()
{
return channel != null;
}
/**
* Whether the member is muted by an admin
*
* @return True, if the member is muted
*/
public boolean isGuildMuted()
{
return muted;
}
/**
* Whether the member is deafened by an admin
*
* @return True, if the member is deafened
*/
public boolean isGuildDeafened()
{
return deafened;
}
/**
* Whether the member is suppressed
*
* @return True, if the member is suppressed
*/
public boolean isSuppressed()
{
return suppress;
}
/**
* Whether the member is self-muted
*
* @return True, if the member is self-muted
*/
public boolean isSelfMuted()
{
return selfMute;
}
/**
* Whether the member is self-deafened
*
* @return True, if the member is self-deafened
*/
public boolean isSelfDeafened()
{
return selfDeaf;
}
/**
* Whether the member is muted, either by an admin or self-muted
*
* @return True, if the member is self-muted or guild-muted
*/
public boolean isMuted()
{
return selfMute || muted;
}
/**
* Whether the member is deafened, either by an admin or self-deafened
*
* @return True, if the member is self-deafened or guild-deafened
*/
public boolean isDeafened()
{
return selfDeaf || deafened;
}
public Member getMember()
{
return member;
}
public Widget getWidget()
{
return widget;
}
@Override
public int hashCode() {
return member.hashCode();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof VoiceState))
return false;
VoiceState oState = (VoiceState) obj;
return this == oState || (this.member.equals(oState.getMember()) && this.widget.equals(oState.getWidget()));
}
@Override
public String toString() {
return "VS:" + widget.getName() + ':' + member.getEffectiveName();
}
}
}
}