Skip to content

Commit

Permalink
Add support for guild scheduled events v2 (#2047)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitmocc committed Oct 23, 2022
1 parent 8520369 commit daf17d1
Show file tree
Hide file tree
Showing 46 changed files with 3,772 additions and 24 deletions.
81 changes: 81 additions & 0 deletions src/main/java/net/dv8tion/jda/api/JDA.java
Expand Up @@ -1238,6 +1238,87 @@ default List<Role> getRolesByName(@Nonnull String name, boolean ignoreCase)
{
return getRoleCache().getElementsByName(name, ignoreCase);
}
/**
* {@link SnowflakeCacheView} of
* all cached {@link ScheduledEvent ScheduledEvents} visible to this JDA session.
*
* @return {@link SnowflakeCacheView}
*/
@Nonnull
SnowflakeCacheView<ScheduledEvent> getScheduledEventCache();

/**
* An unmodifiable list of all {@link ScheduledEvent ScheduledEvents} of all connected
* {@link net.dv8tion.jda.api.entities.Guild Guilds}.
*
* <p>This copies the backing store into a list. This means every call
* creates a new list with O(n) complexity. It is recommended to store this into
* a local variable or use {@link #getScheduledEventCache()} and use its more efficient
* versions of handling these values.
*
* @return Possibly-empty immutable list of all known {@link ScheduledEvent ScheduledEvents}.
*/
@Nonnull
default List<ScheduledEvent> getScheduledEvents()
{
return getScheduledEventCache().asList();
}

/**
* This returns the {@link ScheduledEvent} which has the same id as the one provided.
* <br>If there is no known {@link ScheduledEvent} with an id that matches the provided
* one, then this returns {@code null}.
*
* @param id
* The id of the {@link ScheduledEvent}.
*
* @throws java.lang.NumberFormatException
* If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)}
*
* @return Possibly-null {@link ScheduledEvent} with a matching id.
*/
@Nullable
default ScheduledEvent getScheduledEventById(@Nonnull String id)
{
return getScheduledEventCache().getElementById(id);
}

/**
* This returns the {@link ScheduledEvent} which has the same id as the one provided.
* <br>If there is no known {@link ScheduledEvent} with an id that matches the provided
* one, then this returns {@code null}.
*
* @param id
* The id of the {@link ScheduledEvent}.
*
* @return Possibly-null {@link ScheduledEvent} with a matching id.
*/
@Nullable
default ScheduledEvent getScheduledEventById(long id)
{
return getScheduledEventCache().getElementById(id);
}

/**
* An unmodifiable list of all {@link ScheduledEvent ScheduledEvents} that have the same name as the one provided.
* <br>If there are no {@link ScheduledEvent ScheduledEvents} with the provided name, then this returns an empty list.
*
* @param name
* The name of the requested {@link ScheduledEvent}.
* @param ignoreCase
* Whether to ignore case or not when comparing the provided name to each {@link ScheduledEvent#getName()}.
*
* @throws IllegalArgumentException
* If the provided name is null.
*
* @return Possibly-empty immutable list of all the {@link ScheduledEvent ScheduledEvents} that all have the
* same name as the provided name.
*/
@Nonnull
default List<ScheduledEvent> getScheduledEventsByName(@Nonnull String name, boolean ignoreCase)
{
return getScheduledEventCache().getElementsByName(name, ignoreCase);
}

@Nullable
@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/dv8tion/jda/api/Permission.java
Expand Up @@ -38,6 +38,7 @@ public enum Permission
MANAGE_PERMISSIONS( 28, false, true, "Manage Permissions"),
MANAGE_WEBHOOKS( 29, true, true, "Manage Webhooks"),
MANAGE_EMOJIS_AND_STICKERS(30, true, false, "Manage Emojis and Stickers"),
MANAGE_EVENTS( 33, true, true, "Manage Events"),

// Membership Permissions
CREATE_INSTANT_INVITE(0, true, true, "Create Instant Invite"),
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/dv8tion/jda/api/audit/ActionType.java
Expand Up @@ -17,6 +17,7 @@
package net.dv8tion.jda.api.audit;

import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.ScheduledEvent;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;

Expand Down Expand Up @@ -494,6 +495,21 @@ public enum ActionType
*/
STAGE_INSTANCE_DELETE(85, TargetType.STAGE_INSTANCE),

/**
* A user created a {@link ScheduledEvent ScheduledEvent}
*/
SCHEDULED_EVENT_CREATE(100, TargetType.SCHEDULED_EVENT),

/**
* A user updated a {@link ScheduledEvent ScheduledEvent}
*/
SCHEDULED_EVENT_UPDATE(101, TargetType.SCHEDULED_EVENT),

/**
* A user deleted/cancelled a {@link ScheduledEvent ScheduledEvent}
*/
SCHEDULED_EVENT_DELETE(102, TargetType.SCHEDULED_EVENT),

/**
* An Administrator created a {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildSticker}.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/dv8tion/jda/api/audit/TargetType.java
Expand Up @@ -42,5 +42,6 @@ public enum TargetType
STAGE_INSTANCE,
STICKER,
THREAD,
SCHEDULED_EVENT,
UNKNOWN
}

0 comments on commit daf17d1

Please sign in to comment.