diff --git a/src/main/java/net/dv8tion/jda/api/entities/ScheduledEvent.java b/src/main/java/net/dv8tion/jda/api/entities/ScheduledEvent.java index cd9a139288..f2c5e391db 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/ScheduledEvent.java +++ b/src/main/java/net/dv8tion/jda/api/entities/ScheduledEvent.java @@ -37,6 +37,12 @@ */ public interface ScheduledEvent extends ISnowflake, Comparable { + + /** + * Template for {@link #getJumpUrl()}. Args: .../guild_id/event_id + */ + String JUMP_URL = "https://discord.com/events/%s/%s"; + /** * The maximum allowed length for an event's name. */ @@ -201,6 +207,14 @@ default String getCreatorId() @Nonnull String getLocation(); + /** + * Returns the jump-to URL of the event. Clicking this URL in the Discord client will open the event. + * + * @return A String representing the jump-to URL of the event. + */ + @Nonnull + String getJumpUrl(); + /** * Deletes this Scheduled Event. * diff --git a/src/main/java/net/dv8tion/jda/internal/entities/ScheduledEventImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/ScheduledEventImpl.java index c3c3516fdd..de81ebc4da 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/ScheduledEventImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/ScheduledEventImpl.java @@ -29,6 +29,8 @@ import net.dv8tion.jda.internal.requests.restaction.AuditableRestActionImpl; import net.dv8tion.jda.internal.requests.restaction.pagination.ScheduledEventMembersPaginationActionImpl; import net.dv8tion.jda.internal.utils.Checks; +import net.dv8tion.jda.internal.utils.Helpers; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -133,6 +135,12 @@ public String getLocation() return location; } + @NotNull + @Override + public String getJumpUrl(){ + return Helpers.format(ScheduledEvent.JUMP_URL, getGuild().getId(), getId()); + } + @Override public int getInterestedUserCount() { diff --git a/src/test/java/net/dv8tion/jda/test/entities/scheduledevent/ScheduledEventTest.java b/src/test/java/net/dv8tion/jda/test/entities/scheduledevent/ScheduledEventTest.java new file mode 100644 index 0000000000..8b9445127a --- /dev/null +++ b/src/test/java/net/dv8tion/jda/test/entities/scheduledevent/ScheduledEventTest.java @@ -0,0 +1,29 @@ +package net.dv8tion.jda.test.entities.scheduledevent; + +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.ScheduledEvent; +import net.dv8tion.jda.internal.JDAImpl; +import net.dv8tion.jda.internal.entities.GuildImpl; +import net.dv8tion.jda.internal.entities.ScheduledEventImpl; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ScheduledEventTest{ + + @Test + void testGetJumpUrl(){ + + long guildId = 7777777; + long eventId = 333; + + String expected = "https://discord.com/events/" + guildId + "/" + eventId; + + Guild guild = new GuildImpl(new JDAImpl(null), guildId); + + ScheduledEvent scheduledEvent = new ScheduledEventImpl(eventId, guild); + + Assertions.assertEquals(expected, scheduledEvent.getJumpUrl()); + + } + +}