|
16 | 16 |
|
17 | 17 | package net.dv8tion.jda.api.requests.restaction; |
18 | 18 |
|
19 | | -import net.dv8tion.jda.api.entities.Invite; |
20 | | -import net.dv8tion.jda.api.entities.Member; |
21 | | -import net.dv8tion.jda.api.entities.User; |
| 19 | +import net.dv8tion.jda.api.entities.*; |
22 | 20 | import net.dv8tion.jda.api.utils.MiscUtil; |
23 | 21 | import net.dv8tion.jda.internal.utils.Checks; |
24 | 22 |
|
| 23 | +import java.util.Arrays; |
| 24 | +import java.util.Collection; |
25 | 25 | import java.util.concurrent.TimeUnit; |
26 | 26 | import java.util.function.BooleanSupplier; |
27 | 27 |
|
@@ -234,4 +234,262 @@ default InviteAction setTargetStream(@Nonnull Member member) { |
234 | 234 | Checks.notNull(member, "Member"); |
235 | 235 | return setTargetStream(member.getIdLong()); |
236 | 236 | } |
| 237 | + |
| 238 | + /** |
| 239 | + * Sets the users allowed to use this invite. |
| 240 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission! |
| 241 | + * |
| 242 | + * <p>If unknown users are found, |
| 243 | + * Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}. |
| 244 | + * |
| 245 | + * @param users |
| 246 | + * The users allowed to use the invite |
| 247 | + * |
| 248 | + * @throws IllegalArgumentException |
| 249 | + * If the provided collection is or contains {@code null} |
| 250 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 251 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 252 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission |
| 253 | + * |
| 254 | + * @return This instance for chaining |
| 255 | + */ |
| 256 | + @Nonnull |
| 257 | + @CheckReturnValue |
| 258 | + InviteAction setTargetUsers(@Nonnull Collection<? extends UserSnowflake> users); |
| 259 | + |
| 260 | + /** |
| 261 | + * Sets the users allowed to use this invite. |
| 262 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission! |
| 263 | + * |
| 264 | + * <p>If unknown users are found, |
| 265 | + * Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}. |
| 266 | + * |
| 267 | + * @param users |
| 268 | + * The users allowed to use the invite |
| 269 | + * |
| 270 | + * @throws IllegalArgumentException |
| 271 | + * If the provided array is or contains {@code null} |
| 272 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 273 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 274 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission |
| 275 | + * |
| 276 | + * @return This instance for chaining |
| 277 | + */ |
| 278 | + @Nonnull |
| 279 | + @CheckReturnValue |
| 280 | + InviteAction setTargetUsers(@Nonnull UserSnowflake... users); |
| 281 | + |
| 282 | + /** |
| 283 | + * Sets IDs of users allowed to use this invite. |
| 284 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission! |
| 285 | + * |
| 286 | + * <p>If unknown users are found, |
| 287 | + * Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}. |
| 288 | + * |
| 289 | + * @param ids |
| 290 | + * IDs of users allowed to use the invite |
| 291 | + * |
| 292 | + * @throws IllegalArgumentException |
| 293 | + * If the provided collection is or contains {@code null} |
| 294 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 295 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 296 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission |
| 297 | + * |
| 298 | + * @return This instance for chaining |
| 299 | + */ |
| 300 | + @Nonnull |
| 301 | + @CheckReturnValue |
| 302 | + InviteAction setTargetUserIds(@Nonnull Collection<Long> ids); |
| 303 | + |
| 304 | + /** |
| 305 | + * Sets IDs of users allowed to use this invite. |
| 306 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission! |
| 307 | + * |
| 308 | + * <p>If unknown users are found, |
| 309 | + * Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}. |
| 310 | + * |
| 311 | + * @param ids |
| 312 | + * IDs of users allowed to use the invite |
| 313 | + * |
| 314 | + * @throws IllegalArgumentException |
| 315 | + * If the provided array is or contains {@code null} |
| 316 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 317 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 318 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission |
| 319 | + * |
| 320 | + * @return This instance for chaining |
| 321 | + */ |
| 322 | + @Nonnull |
| 323 | + @CheckReturnValue |
| 324 | + InviteAction setTargetUserIds(@Nonnull long... ids); |
| 325 | + |
| 326 | + /** |
| 327 | + * Sets IDs of users allowed to use this invite. |
| 328 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission! |
| 329 | + * |
| 330 | + * <p>If unknown users are found, |
| 331 | + * Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}. |
| 332 | + * |
| 333 | + * @param ids |
| 334 | + * IDs of users allowed to use the invite |
| 335 | + * |
| 336 | + * @throws IllegalArgumentException |
| 337 | + * <ul> |
| 338 | + * <li>If the provided array is or contains {@code null}</li> |
| 339 | + * <li>If one of the strings is empty</li> |
| 340 | + * </ul> |
| 341 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 342 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 343 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission |
| 344 | + * @throws NumberFormatException |
| 345 | + * If one of the IDs is an invalid snowflake |
| 346 | + * |
| 347 | + * @return This instance for chaining |
| 348 | + */ |
| 349 | + @Nonnull |
| 350 | + @CheckReturnValue |
| 351 | + InviteAction setTargetUserIds(@Nonnull String... ids); |
| 352 | + |
| 353 | + /** |
| 354 | + * Sets roles to be assigned when accepting the created invite. |
| 355 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission! |
| 356 | + * |
| 357 | + * @param roles |
| 358 | + * The roles to assign upon invite acceptation |
| 359 | + * |
| 360 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 361 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 362 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission |
| 363 | + * @throws net.dv8tion.jda.api.exceptions.HierarchyException |
| 364 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 365 | + * cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles |
| 366 | + * due to the role being higher than the bot's highest role |
| 367 | + * @throws IllegalArgumentException |
| 368 | + * <ul> |
| 369 | + * <li>If the provided collection is {@code null} or contains {@code null}</li> |
| 370 | + * <li>If one of the roles isn't from the target guild</li> |
| 371 | + * </ul> |
| 372 | + * |
| 373 | + * @return The current InviteAction for chaining. |
| 374 | + */ |
| 375 | + @Nonnull |
| 376 | + @CheckReturnValue |
| 377 | + InviteAction setRoles(@Nonnull Collection<? extends Role> roles); |
| 378 | + |
| 379 | + /** |
| 380 | + * Sets roles to be assigned when accepting the created invite. |
| 381 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission! |
| 382 | + * |
| 383 | + * @param roles |
| 384 | + * The roles to assign upon invite acceptation |
| 385 | + * |
| 386 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 387 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 388 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission |
| 389 | + * @throws net.dv8tion.jda.api.exceptions.HierarchyException |
| 390 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 391 | + * cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles |
| 392 | + * due to the role being higher than the bot's highest role |
| 393 | + * @throws IllegalArgumentException |
| 394 | + * <ul> |
| 395 | + * <li>If the provided array is {@code null} or contains {@code null}</li> |
| 396 | + * <li>If one of the roles isn't from the target guild</li> |
| 397 | + * </ul> |
| 398 | + * |
| 399 | + * @return The current InviteAction for chaining. |
| 400 | + */ |
| 401 | + @Nonnull |
| 402 | + @CheckReturnValue |
| 403 | + default InviteAction setRoles(@Nonnull Role... roles) { |
| 404 | + Checks.noneNull(roles, "Roles"); |
| 405 | + return setRoles(Arrays.asList(roles)); |
| 406 | + } |
| 407 | + |
| 408 | + /** |
| 409 | + * Sets IDs of roles to be assigned when accepting the created invite. |
| 410 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission! |
| 411 | + * |
| 412 | + * <p>IDs that do not point to an existing role in the targeted guild will be ignored. |
| 413 | + * |
| 414 | + * @param ids |
| 415 | + * The IDs of the roles to assign upon invite acceptation |
| 416 | + * |
| 417 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 418 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 419 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission |
| 420 | + * @throws net.dv8tion.jda.api.exceptions.HierarchyException |
| 421 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 422 | + * cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles |
| 423 | + * due to the role being higher than the bot's highest role |
| 424 | + * @throws IllegalArgumentException |
| 425 | + * If the provided collection is {@code null} or contains {@code null} |
| 426 | + * |
| 427 | + * @return The current InviteAction for chaining. |
| 428 | + */ |
| 429 | + @Nonnull |
| 430 | + @CheckReturnValue |
| 431 | + default InviteAction setRoleIds(@Nonnull Collection<Long> ids) { |
| 432 | + Checks.noneNull(ids, "IDs"); |
| 433 | + return setRoleIds(ids.stream().mapToLong(Long::longValue).toArray()); |
| 434 | + } |
| 435 | + |
| 436 | + /** |
| 437 | + * Sets IDs of roles to be assigned when accepting the created invite. |
| 438 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission! |
| 439 | + * |
| 440 | + * <p>IDs that do not point to an existing role in the targeted guild will be ignored. |
| 441 | + * |
| 442 | + * @param ids |
| 443 | + * The IDs of the roles to assign upon invite acceptation |
| 444 | + * |
| 445 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 446 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 447 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission |
| 448 | + * @throws net.dv8tion.jda.api.exceptions.HierarchyException |
| 449 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 450 | + * cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles |
| 451 | + * due to the role being higher than the bot's highest role |
| 452 | + * @throws IllegalArgumentException |
| 453 | + * If the provided array is {@code null} |
| 454 | + * |
| 455 | + * @return The current InviteAction for chaining. |
| 456 | + */ |
| 457 | + @Nonnull |
| 458 | + @CheckReturnValue |
| 459 | + InviteAction setRoleIds(@Nonnull long... ids); |
| 460 | + |
| 461 | + /** |
| 462 | + * Sets IDs of roles to be assigned when accepting the created invite. |
| 463 | + * <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission! |
| 464 | + * |
| 465 | + * <p>IDs that do not point to an existing role in the targeted guild will be ignored. |
| 466 | + * |
| 467 | + * @param ids |
| 468 | + * The IDs of the roles to assign upon invite acceptation |
| 469 | + * |
| 470 | + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException |
| 471 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 472 | + * does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission |
| 473 | + * @throws net.dv8tion.jda.api.exceptions.HierarchyException |
| 474 | + * If the {@linkplain Guild#getSelfMember() self member} |
| 475 | + * cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles |
| 476 | + * due to the role being higher than the bot's highest role |
| 477 | + * @throws IllegalArgumentException |
| 478 | + * If the provided array is {@code null}, contains {@code null}, or, has an empty string |
| 479 | + * @throws NumberFormatException |
| 480 | + * If one of the IDs is not a valid snowflake |
| 481 | + * |
| 482 | + * @return The current InviteAction for chaining. |
| 483 | + */ |
| 484 | + @Nonnull |
| 485 | + @CheckReturnValue |
| 486 | + default InviteAction setRoleIds(@Nonnull String... ids) { |
| 487 | + Checks.noneNull(ids, "IDs"); |
| 488 | + |
| 489 | + long[] arr = new long[ids.length]; |
| 490 | + for (int i = 0; i < ids.length; i++) { |
| 491 | + arr[i] = MiscUtil.parseSnowflake(ids[i]); |
| 492 | + } |
| 493 | + return setRoleIds(arr); |
| 494 | + } |
237 | 495 | } |
0 commit comments