-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
ChannelManager.java
281 lines (266 loc) · 13.2 KB
/
ChannelManager.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
/*
* 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.managers;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.Category;
import net.dv8tion.jda.core.entities.Channel;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction;
import javax.annotation.CheckReturnValue;
/**
* Facade for a {@link net.dv8tion.jda.core.managers.ChannelManagerUpdatable ChannelManagerUpdatable} instance.
* <br>Simplifies managing flow for convenience.
*
* <p>This decoration allows to modify a single field by automatically building an update {@link net.dv8tion.jda.core.requests.RestAction RestAction}
*/
public class ChannelManager
{
protected final ChannelManagerUpdatable updatable;
/**
* Creates a new ChannelManager instance
*
* @param channel
* {@link net.dv8tion.jda.core.entities.Channel Channel} that should be modified
* <br>Either {@link net.dv8tion.jda.core.entities.VoiceChannel Voice}- or {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}
*/
public ChannelManager(Channel channel)
{
this.updatable = new ChannelManagerUpdatable(channel);
}
/**
* The {@link net.dv8tion.jda.core.JDA JDA} instance of this Manager
*
* @return the corresponding JDA instance
*/
public JDA getJDA()
{
return updatable.getJDA();
}
/**
* The {@link net.dv8tion.jda.core.entities.Channel Channel} that will
* be modified by this Manager instance
*
* @return The {@link net.dv8tion.jda.core.entities.Channel Channel}
*
* @see ChannelManagerUpdatable#getChannel()
*/
public Channel getChannel()
{
return updatable.getChannel();
}
/**
* The {@link net.dv8tion.jda.core.entities.Guild Guild} this Manager's
* {@link net.dv8tion.jda.core.entities.Channel Channel} is in.
* <br>This is logically the same as calling {@code getChannel().getGuild()}
*
* @return The parent {@link net.dv8tion.jda.core.entities.Guild Guild}
*
* @see ChannelManagerUpdatable#getGuild()
*/
public Guild getGuild()
{
return updatable.getGuild();
}
/**
* Sets the <b><u>name</u></b> of the selected {@link net.dv8tion.jda.core.entities.Channel Channel}.
*
* <p>A channel name <b>must not</b> be {@code null} nor less than 2 characters or more than 100 characters long!
* <br>TextChannel names may only be populated with alphanumeric (with underscore and dash).
*
* <p><b>Example</b>: {@code mod-only} or {@code generic_name}
* <br>Characters will automatically be lowercased by Discord!
*
* @param name
* The new name for the selected {@link net.dv8tion.jda.core.entities.Channel Channel}
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL}
* @throws IllegalArgumentException
* If the provided name is {@code null} or not between 2-100 characters long
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link ChannelManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#getNameField()
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#update()
*/
@CheckReturnValue
public AuditableRestAction<Void> setName(String name)
{
return updatable.getNameField().setValue(name).update();
}
/**
* Sets the <b><u>{@link net.dv8tion.jda.core.entities.Category Parent Category}</u></b>
* of the selected {@link net.dv8tion.jda.core.entities.Channel Channel}.
*
*
* @param category
* The new parent for the selected {@link net.dv8tion.jda.core.entities.Channel Channel}
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL}
* @throws IllegalArgumentException
* If the provided category is not from the same Guild
* @throws UnsupportedOperationException
* If the target is a category itself
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link ChannelManagerUpdatable#update() #update()}
*
* @since 3.4.0
*
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#getParentField()
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#update()
*/
@CheckReturnValue
public AuditableRestAction<Void> setParent(Category category)
{
return updatable.getParentField().setValue(category).update();
}
/**
* Sets the <b><u>position</u></b>
* of the selected {@link net.dv8tion.jda.core.entities.Channel Channel}.
*
* <p><b>To modify multiple channels you should use
* <code>Guild.{@link net.dv8tion.jda.core.managers.GuildController getController()}.{@link GuildController#modifyTextChannelPositions() modifyTextChannelPositions()}</code>
* instead! This is not the same as looping through channels and using this to update positions!</b>
*
* @param position
* The new position for the selected {@link net.dv8tion.jda.core.entities.Channel Channel}
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission
* {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} in the Guild!
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link ChannelManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#getPositionField()
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#update()
*/
@CheckReturnValue
public AuditableRestAction<Void> setPosition(int position)
{
return updatable.getPositionField().setValue(position).update();
}
/**
* Sets the <b><u>topic</u></b> of the selected {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}.
*
* <p>A channel topic <b>must not</b> be more than {@code 1024} characters long!
* <br><b>This is only available to {@link net.dv8tion.jda.core.entities.TextChannel TextChannels}</b>
*
* @param topic
* The new topic for the selected {@link net.dv8tion.jda.core.entities.TextChannel TextChannel},
* {@code null} or empty String to reset
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL}
* @throws UnsupportedOperationException
* If the selected {@link net.dv8tion.jda.core.entities.Channel Channel}'s type is not {@link net.dv8tion.jda.core.entities.ChannelType#TEXT TEXT}
* @throws IllegalArgumentException
* If the provided topic is greater than {@code 1024} in length
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link ChannelManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#getTopicField()
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#update()
*/
@CheckReturnValue
public AuditableRestAction<Void> setTopic(String topic)
{
return updatable.getTopicField().setValue(topic).update();
}
/**
* Sets the <b><u>nsfw flag</u></b> of the selected {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}.
*
* @param nsfw
* The new nsfw flag for the selected {@link net.dv8tion.jda.core.entities.TextChannel TextChannel},
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL}
* @throws UnsupportedOperationException
* If the selected {@link net.dv8tion.jda.core.entities.Channel Channel}'s type is not {@link net.dv8tion.jda.core.entities.ChannelType#TEXT TEXT}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link ChannelManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#getNSFWField()
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#update()
*/
public AuditableRestAction<Void> setNSFW(boolean nsfw)
{
return updatable.getNSFWField().setValue(nsfw).update();
}
/**
* Sets the <b><u>user-limit</u></b> of the selected {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}.
* <br>Provide {@code 0} to reset the user-limit of the {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}
*
* <p>A channel user-limit <b>must not</b> be negative nor greater than {@code 99}!
* <br><b>This is only available to {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannels}</b>
*
* @param userLimit
* The new user-limit for the selected {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL}
* @throws UnsupportedOperationException
* If the selected {@link net.dv8tion.jda.core.entities.Channel Channel}'s type is not {@link net.dv8tion.jda.core.entities.ChannelType#VOICE VOICE}
* @throws IllegalArgumentException
* If the provided user-limit is negative or greater than {@code 99}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link ChannelManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#getUserLimitField()
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#update()
*/
@CheckReturnValue
public AuditableRestAction<Void> setUserLimit(int userLimit)
{
return updatable.getUserLimitField().setValue(userLimit).update();
}
/**
* Sets the <b><u>bitrate</u></b> of the selected {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}.
* <br>The default value is {@code 64000}
*
* <p>A channel bitrate <b>must not</b> be less than {@code 8000} nor greater than {@code 96000} (for non-vip Guilds)!
* {@link net.dv8tion.jda.core.entities.Guild#getFeatures() VIP Guilds} allow a bitrate for up to {@code 128000}.
* <br><b>This is only available to {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannels}</b>
*
* @param bitrate
* The new bitrate for the selected {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL}
* @throws UnsupportedOperationException
* If the selected {@link net.dv8tion.jda.core.entities.Channel Channel}'s type is not {@link net.dv8tion.jda.core.entities.ChannelType#VOICE VOICE}
* @throws IllegalArgumentException
* If the provided bitrate is not between 8000-96000 (or 128000 for VIP Guilds)
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link ChannelManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.entities.Guild#getFeatures()
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#getBitrateField()
* @see net.dv8tion.jda.core.managers.ChannelManagerUpdatable#update()
*/
@CheckReturnValue
public AuditableRestAction<Void> setBitrate(int bitrate)
{
return updatable.getBitrateField().setValue(bitrate).update();
}
}