Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Activity(Type) #1798

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/main/java/net/dv8tion/jda/api/entities/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ public interface Activity
* @throws IllegalArgumentException
* if the specified name is null, empty, blank or longer than 128 characters
*
* @return A valid Activity instance with the provided name with {@link net.dv8tion.jda.api.entities.Activity.ActivityType#DEFAULT}
* @return A valid Activity instance with the provided name with {@link net.dv8tion.jda.api.entities.Activity.ActivityType#PLAYING}
*/
@Nonnull
static Activity playing(@Nonnull String name)
{
Checks.notBlank(name, "Name");
name = name.trim();
Checks.notLonger(name, 128, "Name");
return EntityBuilder.createActivity(name, null, ActivityType.DEFAULT);
return EntityBuilder.createActivity(name, null, ActivityType.PLAYING);
}

/**
Expand Down Expand Up @@ -156,7 +156,7 @@ static Activity streaming(@Nonnull String name, @Nullable String url)
if (isValidStreamingUrl(url))
type = ActivityType.STREAMING;
else
type = ActivityType.DEFAULT;
type = ActivityType.PLAYING;
return EntityBuilder.createActivity(name, url, type);
}

Expand Down Expand Up @@ -278,7 +278,7 @@ static Activity of(@Nonnull ActivityType type, @Nonnull String name, @Nullable S
Checks.notNull(type, "Type");
switch (type)
{
case DEFAULT:
case PLAYING:
return playing(name);
case STREAMING:
return streaming(name, url);
Expand Down Expand Up @@ -307,17 +307,18 @@ static boolean isValidStreamingUrl(@Nullable String url)
}

/**
* The type game being played, differentiating between a game and stream types.
* The activity being executed, differentiating between, amongst others, playing, listening and streaming.
*/
enum ActivityType
{
/**
* The ActivityType used to represent a normal {@link Activity Activity} status.
* Used to indicate that the {@link Activity Activity} should display
* as {@code Playing...} in the official client.
*/
DEFAULT(0),
PLAYING(0),
/**
* Used to indicate that the {@link Activity Activity} is a stream
* <br>This type is displayed as "Streaming" in the discord client.
* Used to indicate that the {@link Activity Activity} is a stream and should be displayed
* as {@code Streaming...} in the official client.
*/
STREAMING(1),
/**
Expand Down Expand Up @@ -369,12 +370,12 @@ public int getKey()

/**
* Gets the ActivityType related to the provided key.
* <br>If an unknown key is provided, this returns {@link #DEFAULT}
* <br>If an unknown key is provided, this returns {@link #PLAYING}
*
* @param key
* The Discord key referencing a ActivityType.
*
* @return The ActivityType that has the key provided, or {@link #DEFAULT} for unknown key.
* @return The ActivityType that has the key provided, or {@link #PLAYING} for unknown key.
*/
@Nonnull
public static ActivityType fromKey(int key)
Expand All @@ -383,7 +384,7 @@ public static ActivityType fromKey(int key)
{
case 0:
default:
return DEFAULT;
return PLAYING;
case 1:
return STREAMING;
case 2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ActivityImpl implements Activity

protected ActivityImpl(String name)
{
this(name, null, ActivityType.DEFAULT);
this(name, null, ActivityType.PLAYING);
}

protected ActivityImpl(String name, String url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,12 @@ public static Activity createActivity(DataObject gameJson)
try
{
type = gameJson.isNull("type")
? Activity.ActivityType.DEFAULT
? Activity.ActivityType.PLAYING
: Activity.ActivityType.fromKey(Integer.parseInt(gameJson.get("type").toString()));
}
catch (NumberFormatException e)
{
type = Activity.ActivityType.DEFAULT;
type = Activity.ActivityType.PLAYING;
}

RichPresence.Timestamps timestamps = null;
Expand Down