/
ChannelType.java
224 lines (206 loc) · 5.72 KB
/
ChannelType.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
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* 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.api.entities.channel;
import net.dv8tion.jda.api.entities.channel.concrete.*;
import javax.annotation.Nonnull;
import java.util.EnumSet;
/**
* Enum used to differentiate between the different types of Discord channels.
*/
public enum ChannelType
{
/**
* A {@link TextChannel TextChannel}, Guild-Only.
*/
TEXT(0, 0, true),
/**
* A {@link PrivateChannel PrivateChannel}.
*/
PRIVATE(1, -1),
/**
* A {@link VoiceChannel VoiceChannel}, Guild-Only.
*/
VOICE(2, 1, true),
/**
* A Group. (unused)
*/
GROUP(3, -1),
/**
* A {@link Category Category}, Guild-Only.
*/
CATEGORY(4, 2, true),
/**
* A {@link NewsChannel NewsChannel}, Guild-Only.
*/
NEWS(5, 0, true),
/**
* A {@link StageChannel StageChannel}, Guild-Only.
*/
STAGE(13, 1, true),
GUILD_NEWS_THREAD(10, -1, true),
GUILD_PUBLIC_THREAD(11, -1, true),
GUILD_PRIVATE_THREAD(12, -1, true),
/**
* A {@link net.dv8tion.jda.api.entities.channel.concrete.ForumChannel ForumChannel}, Guild-Only.
*/
FORUM(15, 0, true),
/**
* Unknown Discord channel type. Should never happen and would only possibly happen if Discord implemented a new
* channel type and JDA had yet to implement support for it.
*/
UNKNOWN(-1, -2);
private final int sortBucket;
private final int id;
private final boolean isGuild;
ChannelType(int id, int sortBucket)
{
this(id, sortBucket, false);
}
ChannelType(int id, int sortBucket, boolean isGuild)
{
this.id = id;
this.sortBucket = sortBucket;
this.isGuild = isGuild;
}
/**
* The sorting bucket for this channel type.
*
* @return The sorting bucket
*/
public int getSortBucket()
{
return sortBucket;
}
/**
* The Discord id key used to represent the channel type.
*
* @return The id key used by discord for this channel type.
*/
public int getId()
{
return id;
}
/**
* Whether this ChannelType is present for a {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel GuildChannel}
*
* @return Whether or not this a GuildChannel
*/
public boolean isGuild()
{
return isGuild;
}
/**
* Whether channels of this type support audio connections.
*
* @return True, if channels of this type support audio
*/
public boolean isAudio()
{
switch (this)
{
case VOICE:
case STAGE:
return true;
default:
return false;
}
}
/**
* Whether channels of this type support message sending.
*
* @return True, if channels of this type support messages
*/
public boolean isMessage()
{
switch (this)
{
case TEXT:
case VOICE:
case STAGE:
case NEWS:
case PRIVATE:
case GROUP:
return true;
default:
return isThread();
}
}
/**
* Whether channels of this type are {@link ThreadChannel ThreadChannels}.
* This mostly exists to make handling threads simpler than having to check 3 separate ChannelTypes every time.
*
* @return True, if channels of this type are {@link ThreadChannel ThreadChannel}
*/
public boolean isThread()
{
switch (this)
{
case GUILD_NEWS_THREAD:
case GUILD_PUBLIC_THREAD:
case GUILD_PRIVATE_THREAD:
return true;
default:
return false;
}
}
/**
* All the channel types for a {@link net.dv8tion.jda.api.entities.Guild Guild}.
*
* @return {@link EnumSet} of {@link ChannelType}
*/
@Nonnull
public static EnumSet<ChannelType> guildTypes()
{
return EnumSet.complementOf(EnumSet.of(PRIVATE, GROUP, UNKNOWN));
}
/**
* Static accessor for retrieving a channel type based on its Discord id key.
*
* @param id
* The id key of the requested channel type.
*
* @return The ChannelType that is referred to by the provided key. If the id key is unknown, {@link #UNKNOWN} is returned.
*/
@Nonnull
public static ChannelType fromId(int id)
{
for (ChannelType type : values())
{
if (type.id == id)
return type;
}
return UNKNOWN;
}
/**
* An {@link java.util.EnumSet} populated with all channel types using the provided sorting bucket.
*
* @param bucket
* The sorting bucket
*
* @return Possibly-empty {@link java.util.EnumSet} for the bucket
*/
@Nonnull
public static EnumSet<ChannelType> fromSortBucket(int bucket)
{
EnumSet<ChannelType> types = EnumSet.noneOf(ChannelType.class);
for (ChannelType type : values())
{
if (type.getSortBucket() == bucket)
types.add(type);
}
return types;
}
}