/
ChannelManager.java
493 lines (468 loc) · 20.9 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
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
/*
* Copyright 2015-2020 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.managers;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
/**
* Manager providing functionality to update one or more fields for a {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}.
*
* <p><b>Example</b>
* <pre>{@code
* manager.setName("github-log")
* .setTopic("logs for github commits")
* .setNSFW(false)
* .queue();
* manager.reset(ChannelManager.TOPIC | ChannelManager.NAME)
* .setName("nsfw-commits")
* .setTopic(null)
* .setNSFW(true)
* .queue();
* }</pre>
*
* @see net.dv8tion.jda.api.entities.GuildChannel#getManager()
*/
public interface ChannelManager extends Manager<ChannelManager>
{
/** Used to reset the name field */
long NAME = 0x1;
/** Used to reset the parent field */
long PARENT = 0x2;
/** Used to reset the topic field */
long TOPIC = 0x4;
/** Used to reset the position field */
long POSITION = 0x8;
/** Used to reset the nsfw field */
long NSFW = 0x10;
/** Used to reset the userlimit field */
long USERLIMIT = 0x20;
/** Used to reset the bitrate field */
long BITRATE = 0x40;
/** Used to reset the permission field */
long PERMISSION = 0x80;
/** Used to reset the rate-limit per user field */
long SLOWMODE = 0x100;
/** Used to reset the channel type field */
long NEWS = 0x200;
/**
* Resets the fields specified by the provided bit-flag pattern.
* You can specify a combination by using a bitwise OR concat of the flag constants.
* <br>Example: {@code manager.reset(ChannelManager.NAME | ChannelManager.PARENT);}
*
* <p><b>Flag Constants:</b>
* <ul>
* <li>{@link #NAME}</li>
* <li>{@link #PARENT}</li>
* <li>{@link #TOPIC}</li>
* <li>{@link #POSITION}</li>
* <li>{@link #NSFW}</li>
* <li>{@link #SLOWMODE}</li>
* <li>{@link #USERLIMIT}</li>
* <li>{@link #BITRATE}</li>
* <li>{@link #PERMISSION}</li>
* <li>{@link #NEWS}</li>
* </ul>
*
* @param fields
* Integer value containing the flags to reset.
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@Override
ChannelManager reset(long fields);
/**
* Resets the fields specified by the provided bit-flag patterns.
* <br>Example: {@code manager.reset(ChannelManager.NAME, ChannelManager.PARENT);}
*
* <p><b>Flag Constants:</b>
* <ul>
* <li>{@link #NAME}</li>
* <li>{@link #PARENT}</li>
* <li>{@link #TOPIC}</li>
* <li>{@link #POSITION}</li>
* <li>{@link #NSFW}</li>
* <li>{@link #USERLIMIT}</li>
* <li>{@link #BITRATE}</li>
* <li>{@link #PERMISSION}</li>
* <li>{@link #NEWS}</li>
* </ul>
*
* @param fields
* Integer values containing the flags to reset.
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@Override
ChannelManager reset(long... fields);
/**
* The {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel} that will
* be modified by this Manager instance
*
* @return The {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}
*/
@Nonnull
GuildChannel getChannel();
/**
* The {@link net.dv8tion.jda.api.entities.ChannelType ChannelType}
*
* @return The ChannelType
*/
@Nonnull
default ChannelType getType()
{
return getChannel().getType();
}
/**
* The {@link net.dv8tion.jda.api.entities.Guild Guild} this Manager's
* {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel} is in.
* <br>This is logically the same as calling {@code getChannel().getGuild()}
*
* @return The parent {@link net.dv8tion.jda.api.entities.Guild Guild}
*/
@Nonnull
default Guild getGuild()
{
return getChannel().getGuild();
}
/**
* Clears the overrides added via {@link #putPermissionOverride(IPermissionHolder, Collection, Collection)}.
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager clearOverridesAdded();
/**
* Clears the overrides removed via {@link #removePermissionOverride(IPermissionHolder)}.
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager clearOverridesRemoved();
/**
* Adds an override for the specified {@link net.dv8tion.jda.api.entities.IPermissionHolder IPermissionHolder}
* with the provided raw bitmasks as allowed and denied permissions. If the permission holder already
* had an override on this channel it will be replaced instead.
*
* @param permHolder
* The permission holder
* @param allow
* The bitmask to grant
* @param deny
* The bitmask to deny
*
* @throws java.lang.IllegalArgumentException
* If the provided permission holder is {@code null}
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_PERMISSIONS Permission.MANAGE_PERMISSIONS}
* in this channel, or tries to set permissions it does not have without having {@link Permission#MANAGE_PERMISSIONS Permission.MANAGE_PERMISSIONS} explicitly for this channel through an override.
*
* @return ChannelManager for chaining convenience
*
* @see #putPermissionOverride(IPermissionHolder, Collection, Collection)
* @see net.dv8tion.jda.api.Permission#getRaw(Permission...) Permission.getRaw(Permission...)
*/
@Nonnull
@CheckReturnValue
ChannelManager putPermissionOverride(@Nonnull IPermissionHolder permHolder, long allow, long deny);
/**
* Adds an override for the specified {@link net.dv8tion.jda.api.entities.IPermissionHolder IPermissionHolder}
* with the provided permission sets as allowed and denied permissions. If the permission holder already
* had an override on this channel it will be replaced instead.
* <br>Example: {@code putPermissionOverride(guild.getSelfMember(), EnumSet.of(Permission.MESSAGE_WRITE, Permission.MESSAGE_READ), null)}
*
* @param permHolder
* The permission holder
* @param allow
* The permissions to grant, or null
* @param deny
* The permissions to deny, or null
*
* @throws java.lang.IllegalArgumentException
* If the provided permission holder is {@code null}
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_PERMISSIONS Permission.MANAGE_PERMISSIONS}
* in this channel, or tries to set permissions it does not have without having {@link Permission#MANAGE_PERMISSIONS Permission.MANAGE_PERMISSIONS} explicitly for this channel through an override.
*
* @return ChannelManager for chaining convenience
*
* @see #putPermissionOverride(IPermissionHolder, long, long)
* @see java.util.EnumSet EnumSet
*/
@Nonnull
@CheckReturnValue
default ChannelManager putPermissionOverride(@Nonnull IPermissionHolder permHolder, @Nullable Collection<Permission> allow, @Nullable Collection<Permission> deny)
{
long allowRaw = allow == null ? 0 : Permission.getRaw(allow);
long denyRaw = deny == null ? 0 : Permission.getRaw(deny);
return putPermissionOverride(permHolder, allowRaw, denyRaw);
}
/**
* Removes the {@link net.dv8tion.jda.api.entities.PermissionOverride PermissionOverride} for the specified
* {@link net.dv8tion.jda.api.entities.IPermissionHolder IPermissionHolder}. If no override existed for this member
* this does nothing.
*
* @param permHolder
* The permission holder
*
* @throws java.lang.IllegalArgumentException
* If the provided permission holder is {@code null}
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_PERMISSIONS Permission.MANAGE_PERMISSIONS}
* in this channel
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager removePermissionOverride(@Nonnull IPermissionHolder permHolder);
/**
* Syncs all {@link net.dv8tion.jda.api.entities.PermissionOverride PermissionOverrides} of this GuildChannel with
* its parent ({@link net.dv8tion.jda.api.entities.Category Category}).
*
* <p>After this operation, all {@link net.dv8tion.jda.api.entities.PermissionOverride PermissionOverrides}
* will be exactly the same as the ones from the parent.
* <br><b>That means that all current PermissionOverrides are lost!</b>
*
* <p>This behaves as if calling {@link #sync(net.dv8tion.jda.api.entities.GuildChannel)} with this GuildChannel's {@link net.dv8tion.jda.api.entities.GuildChannel#getParent() Parent}.
*
* @throws java.lang.IllegalStateException
* If this GuildChannel has no parent
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_PERMISSIONS Permission.MANAGE_PERMISSIONS}
* in this channel or {@link IPermissionHolder#canSync(GuildChannel, GuildChannel)} is false for the self member.
*
* @return ChannelManager for chaining convenience
*
* @see <a href="https://discord.com/developers/docs/topics/permissions#permission-syncing" target="_blank">Discord Documentation - Permission Syncing</a>
*/
@Nonnull
@CheckReturnValue
default ChannelManager sync()
{
if (getChannel().getParent() == null)
throw new IllegalStateException("sync() requires a parent category");
return sync(getChannel().getParent());
}
/**
* Syncs all {@link net.dv8tion.jda.api.entities.PermissionOverride PermissionOverrides} of this GuildChannel with
* the given ({@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}).
*
* <p>After this operation, all {@link net.dv8tion.jda.api.entities.PermissionOverride PermissionOverrides}
* will be exactly the same as the ones from the syncSource.
* <br><b>That means that all current PermissionOverrides are lost!</b>
*
* <p>This will only work for Channels of the same {@link net.dv8tion.jda.api.entities.Guild Guild}!.
*
* @param syncSource
* The GuildChannel from where all PermissionOverrides should be copied from
*
* @throws java.lang.IllegalArgumentException
* If the given snySource is {@code null}, this GuildChannel or from a different Guild.
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_PERMISSIONS Permission.MANAGE_PERMISSIONS}
* in this channel or {@link IPermissionHolder#canSync(GuildChannel, GuildChannel)} is false for the self member.
*
* @return ChannelManager for chaining convenience
*
* @see <a href="https://discord.com/developers/docs/topics/permissions#permission-syncing" target="_blank">Discord Documentation - Permission Syncing</a>
*/
@Nonnull
@CheckReturnValue
ChannelManager sync(@Nonnull GuildChannel syncSource);
/**
* Sets the <b><u>name</u></b> of the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}.
*
* <p>A channel name <b>must not</b> be {@code null} nor empty 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 for text channels!
*
* @param name
* The new name for the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}
*
* @throws IllegalArgumentException
* If the provided name is {@code null} or not between 1-100 characters long
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager setName(@Nonnull String name);
/**
* Sets the <b><u>{@link net.dv8tion.jda.api.entities.Category Parent Category}</u></b>
* of the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}.
*
*
* @param category
* The new parent for the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}
*
* @throws IllegalStateException
* If the target is a category itself
* @throws IllegalArgumentException
* If the provided category is not from the same Guild
*
* @return ChannelManager for chaining convenience
*
* @since 3.4.0
*/
@Nonnull
@CheckReturnValue
ChannelManager setParent(@Nullable Category category);
/**
* Sets the <b><u>position</u></b> of the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}.
*
* <p><b>To modify multiple channels you should use
* <code>Guild.{@link net.dv8tion.jda.api.entities.Guild#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.api.entities.GuildChannel GuildChannel}
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager setPosition(int position);
/**
* Sets the <b><u>topic</u></b> of the selected {@link net.dv8tion.jda.api.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.api.entities.TextChannel TextChannels}</b>
*
* @param topic
* The new topic for the selected {@link net.dv8tion.jda.api.entities.TextChannel TextChannel},
* {@code null} or empty String to reset
*
* @throws UnsupportedOperationException
* If the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}'s type is not {@link net.dv8tion.jda.api.entities.ChannelType#TEXT TEXT}
* @throws IllegalArgumentException
* If the provided topic is greater than {@code 1024} in length
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager setTopic(@Nullable String topic);
/**
* Sets the <b><u>nsfw flag</u></b> of the selected {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
*
* @param nsfw
* The new nsfw flag for the selected {@link net.dv8tion.jda.api.entities.TextChannel TextChannel},
*
* @throws IllegalStateException
* If the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}'s type is not {@link net.dv8tion.jda.api.entities.ChannelType#TEXT TEXT}
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager setNSFW(boolean nsfw);
/**
* Sets the <b><u>slowmode</u></b> of the selected {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
* <br>Provide {@code 0} to reset the slowmode of the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}
*
* <p>A channel slowmode <b>must not</b> be negative nor greater than {@link net.dv8tion.jda.api.entities.TextChannel#MAX_SLOWMODE TextChannel.MAX_SLOWMODE}!
* <br><b>This is only available to {@link net.dv8tion.jda.api.entities.TextChannel TextChannels}</b>
*
* <p>Note: Bots are unaffected by this.
* <br>Having {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE MESSAGE_MANAGE} or
* {@link net.dv8tion.jda.api.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} permission also
* grants immunity to slowmode.
*
* @param slowmode
* The new slowmode for the selected {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}
*
* @throws IllegalStateException
* If the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}'s type is not {@link net.dv8tion.jda.api.entities.ChannelType#TEXT TEXT}
* @throws IllegalArgumentException
* If the provided slowmode is negative or greater than {@link net.dv8tion.jda.api.entities.TextChannel#MAX_SLOWMODE TextChannel.MAX_SLOWMODE}
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager setSlowmode(int slowmode);
/**
* Sets the <b><u>user-limit</u></b> of the selected {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}.
* <br>Provide {@code 0} to reset the user-limit of the {@link net.dv8tion.jda.api.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.api.entities.VoiceChannel VoiceChannels}</b>
*
* @param userLimit
* The new user-limit for the selected {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}
*
* @throws IllegalStateException
* If the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}'s type is not {@link net.dv8tion.jda.api.entities.ChannelType#VOICE VOICE}
* @throws IllegalArgumentException
* If the provided user-limit is negative or greater than {@code 99}
*
* @return ChannelManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
ChannelManager setUserLimit(int userLimit);
/**
* Sets the <b><u>bitrate</u></b> of the selected {@link net.dv8tion.jda.api.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 {@link Guild#getMaxBitrate()}!
* <br><b>This is only available to {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannels}</b>
*
* @param bitrate
* The new bitrate for the selected {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}
*
* @throws IllegalStateException
* If the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}'s type is not {@link net.dv8tion.jda.api.entities.ChannelType#VOICE VOICE}
* @throws IllegalArgumentException
* If the provided bitrate is less than 8000 or greater than {@link net.dv8tion.jda.api.entities.Guild#getMaxBitrate()}.
*
* @return ChannelManager for chaining convenience
*
* @see net.dv8tion.jda.api.entities.Guild#getFeatures()
*/
@Nonnull
@CheckReturnValue
ChannelManager setBitrate(int bitrate);
/**
* Sets the <b><u>news flag</u></b> of the selected {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
* Announcement-/News-Channels can be used to crosspost messages to other guilds.
*
* @param news
* The new news flag for the selected {@link net.dv8tion.jda.api.entities.TextChannel TextChannel},
*
* @throws IllegalStateException
* If the selected {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}'s type is not {@link net.dv8tion.jda.api.entities.ChannelType#TEXT TEXT}
* @throws IllegalStateException
* If {@code news} is {@code true} and the guild doesn't have the NEWS feature
*
* @return ChannelManager for chaining convenience
*
* @see net.dv8tion.jda.api.entities.Guild#getFeatures()
* @see net.dv8tion.jda.api.entities.TextChannel#isNews()
*/
@Nonnull
@CheckReturnValue
ChannelManager setNews(boolean news);
}