-
-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/net/dv8tion/jda/api/managers/ApplicationEmojiManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/net/dv8tion/jda/internal/managers/ApplicationEmojiManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |