Skip to content

Commit

Permalink
Add ApplicationEmojiManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Jul 21, 2024
1 parent 6022d43 commit 641114e
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.managers.ApplicationEmojiManager;
import net.dv8tion.jda.api.requests.RestAction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand All @@ -26,4 +28,8 @@ public interface ApplicationEmoji extends CustomEmoji
User getOwner();

RestAction<Void> delete();

@Nonnull
@CheckReturnValue
ApplicationEmojiManager getManager();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.dv8tion.jda.api.managers;

import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

public interface ApplicationEmojiManager extends Manager<ApplicationEmojiManager>
{
long NAME = 1;

@Nonnull
@Override
ApplicationEmojiManager reset(long fields);

@Nonnull
@Override
ApplicationEmojiManager reset(long... fields);

@Nonnull
ApplicationEmoji getEmoji();

@Nonnull
@CheckReturnValue
ApplicationEmojiManager setName(@Nonnull String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.entities.emoji.UnicodeEmoji;
import net.dv8tion.jda.api.managers.ApplicationEmojiManager;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.Route;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.managers.ApplicationEmojiManagerImpl;
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.utils.EntityString;

Expand Down Expand Up @@ -81,6 +83,13 @@ public User getOwner()
{
return owner;
}

@Nonnull
@Override
public ApplicationEmojiManager getManager()
{
return new ApplicationEmojiManagerImpl(this);
}

@Override
public boolean isAnimated()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package net.dv8tion.jda.internal.managers;

import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
import net.dv8tion.jda.api.managers.ApplicationEmojiManager;
import net.dv8tion.jda.api.requests.Route;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.utils.Checks;
import okhttp3.RequestBody;
import org.jetbrains.annotations.NotNull;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

public class ApplicationEmojiManagerImpl extends ManagerBase<ApplicationEmojiManager> implements ApplicationEmojiManager
{
protected final ApplicationEmoji emoji;

protected String name;

public ApplicationEmojiManagerImpl(ApplicationEmoji emoji)
{
super(emoji.getJDA(), Route.Applications.MODIFY_APPLICATION_EMOJI.compile(emoji.getJDA().getSelfUser().getApplicationId(), emoji.getId()));
this.emoji = emoji;
}

@NotNull
@Override
public ApplicationEmoji getEmoji()
{
return emoji;
}

@Nonnull
@Override
@CheckReturnValue
public ApplicationEmojiManagerImpl reset(long fields)
{
super.reset(fields);
if ((fields & NAME) == NAME)
this.name = null;
return this;
}

@Nonnull
@Override
@CheckReturnValue
public ApplicationEmojiManagerImpl reset(long... fields)
{
super.reset(fields);
return this;
}

@NotNull
@Override
public ApplicationEmojiManager setName(@NotNull String name)
{
Checks.notBlank(name, "Name");
name = name.trim();
Checks.inRange(name, 2, 32, "Name");
this.name = name;
set |= NAME;
return this;
}

@Override
protected RequestBody finalizeData()
{
DataObject object = DataObject.empty();
if (shouldUpdate(NAME))
object.put("name", name);
reset();
return getRequestBody(object);
}
}

0 comments on commit 641114e

Please sign in to comment.