Skip to content

Commit

Permalink
Add ScheduledEvent::getJumpUrl (#2736)
Browse files Browse the repository at this point in the history
  • Loading branch information
raul1ro authored Oct 5, 2024
1 parent 5644b5e commit 57f7c0a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/ScheduledEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
*/
public interface ScheduledEvent extends ISnowflake, Comparable<ScheduledEvent>
{

/**
* 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.
*/
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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());

}

}

0 comments on commit 57f7c0a

Please sign in to comment.