Skip to content

Commit

Permalink
Fix some Peer-Review messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyosource committed Oct 7, 2024
1 parent 9d48ce5 commit 1596e1a
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 24 deletions.
9 changes: 3 additions & 6 deletions src/main/java/net/dv8tion/jda/api/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -1754,10 +1754,10 @@ default List<RichCustomEmoji> getEmojisByName(@Nonnull String name, boolean igno
/**
* Creates a new {@link ApplicationEmoji} for this bot.
*
* <p>Note that the bot is limited to 2000 Application Emojis (normal and animated).
* <p>Note that the bot is limited to {@value ApplicationEmoji#APPLICATION_EMOJI_CAP} Application Emojis (normal and animated).
*
* @param name
* The name for the new emoji (2-30 characters)
* The name for the new emoji (2-{@value CustomEmoji#EMOJI_NAME_MAX_LENGTH} characters)
* @param icon
* The {@link Icon} for the new emoji
*/
Expand All @@ -1780,16 +1780,13 @@ default List<RichCustomEmoji> getEmojisByName(@Nonnull String name, boolean igno
* @param emojiId
* The emoji id
*
* @throws IllegalArgumentException
* If the provided id is not a valid snowflake
*
* @return {@link RestAction RestAction} - Type: {@link ApplicationEmoji}
*/
@Nonnull
@CheckReturnValue
default RestAction<ApplicationEmoji> retrieveApplicationEmojiById(long emojiId)
{
return retrieveApplicationEmojiById(String.valueOf(emojiId));
return retrieveApplicationEmojiById(Long.toUnsignedString(emojiId));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.entities.emoji;

import net.dv8tion.jda.api.JDA;
Expand All @@ -22,6 +38,8 @@
*/
public interface ApplicationEmoji extends CustomEmoji
{
int APPLICATION_EMOJI_CAP = 2000;

/**
* The {@link net.dv8tion.jda.api.JDA JDA} instance of this emoji
*
Expand All @@ -33,8 +51,6 @@ public interface ApplicationEmoji extends CustomEmoji
/**
* The user who created this emoji
*
* <p>This returns null, right after creating the emoji.
*
* @return The user who created this emoji
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
*/
public interface CustomEmoji extends Emoji, IMentionable
{
int EMOJI_NAME_MAX_LENGTH = 32

/** Template for {@link #getImageUrl()} */
String ICON_URL = "https://cdn.discordapp.com/emojis/%s.%s";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ enum Type
/**
* Custom Guild Emoji or Custom Application Emoji.
* <br>This represents emojis which were created by users and added to a guild.
* <br>This can also represent emojis which were created by users and added to a jda.
* <br>This can also represent emojis which were created and owned by a specific application.
*/
CUSTOM,
}
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/net/dv8tion/jda/api/entities/emoji/EmojiUnion.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* Represents possible {@link Emoji} types.
*
* <p>This delegates the emoji methods for some concrete emoji type,
* but can be converted to a concrete type using either {@link #asUnicode()} or {@link #asCustom()}.
* but can be converted to a concrete type using either {@link #asUnicode()},
* {@link #asCustom()}, {@link #asRich()} or {@link #asApplication()}.
*/
public interface EmojiUnion extends Emoji
{
Expand All @@ -47,4 +48,26 @@ public interface EmojiUnion extends Emoji
*/
@Nonnull
CustomEmoji asCustom();

/**
* Returns the underlying {@link RichCustomEmoji} if applicable.
*
* @throws IllegalStateException
* If this is not a {@link RichCustomEmoji}
*
* @return The {@link RichCustomEmoji}
*/
@Nonnull
RichCustomEmoji asRich();

/**
* Returns the underlying {@link ApplicationEmoji} if applicable.
*
* @throws IllegalStateException
* If this is not a {@link ApplicationEmoji}
*
* @return The {@link ApplicationEmoji}
*/
@Nonnull
ApplicationEmoji asApplication();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.managers;

import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
Expand Down Expand Up @@ -67,7 +83,7 @@ public interface ApplicationEmojiManager extends Manager<ApplicationEmojiManager
/**
* Sets the <b><u>name</u></b> of the selected {@link ApplicationEmoji}.
*
* <p>An emoji name <b>must</b> be between 2-32 characters long!
* <p>An emoji name <b>must</b> be between 2-{@value CustomEmoji#EMOJI_NAME_MAX_LENGTH} characters long!
* <br>Emoji names may only be populated with alphanumeric (with underscore and dash).
*
* <p><b>Example</b>: {@code tatDab} or {@code fmgSUP}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/dv8tion/jda/internal/JDAImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ public SnowflakeCacheView<RichCustomEmoji> getEmojiCache()
@Override
public RestAction<ApplicationEmoji> createApplicationEmoji(@Nonnull String name, @Nonnull Icon icon)
{
Checks.inRange(name, 2, 32, "Emoji name");
Checks.inRange(name, 2, CustomEmoji.EMOJI_NAME_MAX_LENGTH, "Emoji name");
Checks.notNull(icon, "Emoji icon");

DataObject body = DataObject.empty();
Expand Down Expand Up @@ -717,6 +717,7 @@ public RestAction<List<ApplicationEmoji>> retrieveApplicationEmojis()
@Override
public RestAction<ApplicationEmoji> retrieveApplicationEmojiById(@Nonnull String emojiId)
{
Checks.isSnowflake(emojiId);
Route.CompiledRoute route = Route.Applications.GET_APPLICATION_EMOJI.compile(getSelfUser().getApplicationId(), emojiId);
return new RestActionImpl<>(this, route,
(response, request) -> entityBuilder.createApplicationEmoji(this, response.getObject())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,8 @@ public RichCustomEmojiImpl createEmoji(GuildImpl guildObj, DataObject json)

public ApplicationEmojiImpl createApplicationEmoji(JDAImpl api, DataObject json)
{
final long emojiId = json.getLong("id");
// Nullable when creating emojis, at least
final User user = json.optObject("user").map(this::createUser).orElse(null);
final long emojiId = json.getUnsignedLong("id");
final User user = createUser(json.getObject("user"));
return new ApplicationEmojiImpl(emojiId, api, user)
.setAnimated(json.getBoolean("animated"))
.setName(json.getString("name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ public RoleAction createRole()
public AuditableRestAction<RichCustomEmoji> createEmoji(@Nonnull String name, @Nonnull Icon icon, @Nonnull Role... roles)
{
checkPermission(Permission.MANAGE_GUILD_EXPRESSIONS);
Checks.inRange(name, 2, 32, "Emoji name");
Checks.inRange(name, 2, CustomEmoji.EMOJI_NAME_MAX_LENGTH, "Emoji name");
Checks.notNull(icon, "Emoji icon");
Checks.notNull(roles, "Roles");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/*
* Copyright 2024 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.internal.entities.emoji;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.entities.emoji.UnicodeEmoji;
import net.dv8tion.jda.api.managers.ApplicationEmojiManager;
Expand Down Expand Up @@ -127,10 +144,10 @@ public boolean equals(Object obj)
{
if (obj == this)
return true;
if (!(obj instanceof CustomEmoji))
if (!(obj instanceof ApplicationEmojiImpl))
return false;

CustomEmoji other = (CustomEmoji) obj;
ApplicationEmojiImpl other = (ApplicationEmojiImpl) obj;
return this.id == other.getIdLong();
}

Expand All @@ -148,11 +165,6 @@ public String toString()
.toString();
}

public ApplicationEmojiImpl copy()
{
return new ApplicationEmojiImpl(id, api, owner).setAnimated(animated).setName(name);
}

@Nonnull
@Override
public UnicodeEmoji asUnicode()
Expand All @@ -166,4 +178,18 @@ public CustomEmoji asCustom()
{
return this;
}

@Nonnull
@Override
public RichCustomEmoji asRich()
{
throw new IllegalStateException("Cannot convert ApplicationEmoji to RichCustomEmoji!");
}

@Nonnull
@Override
public ApplicationEmoji asApplication()
{
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package net.dv8tion.jda.internal.entities.emoji;

import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.entities.emoji.UnicodeEmoji;
import net.dv8tion.jda.api.utils.data.DataObject;
Expand Down Expand Up @@ -125,4 +127,18 @@ public CustomEmoji asCustom()
{
return this;
}

@Nonnull
@Override
public RichCustomEmoji asRich()
{
throw new IllegalStateException("Cannot convert CustomEmoji to RichCustomEmoji!");
}

@Nonnull
@Override
public ApplicationEmoji asApplication()
{
throw new IllegalStateException("Cannot convert CustomEmoji to ApplicationEmoji!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
Expand Down Expand Up @@ -279,4 +280,18 @@ public CustomEmoji asCustom()
{
return this;
}

@Nonnull
@Override
public RichCustomEmoji asRich()
{
return this;
}

@Nonnull
@Override
public ApplicationEmoji asApplication()
{
throw new IllegalStateException("Cannot convert RichCustomEmoji to ApplicationEmoji!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package net.dv8tion.jda.internal.entities.emoji;

import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.entities.emoji.UnicodeEmoji;
import net.dv8tion.jda.api.utils.data.DataObject;
Expand Down Expand Up @@ -100,4 +102,18 @@ public CustomEmoji asCustom()
{
throw new IllegalStateException("Cannot convert UnicodeEmoji into CustomEmoji!");
}

@Nonnull
@Override
public RichCustomEmoji asRich()
{
throw new IllegalStateException("Cannot convert UnicodeEmoji into RichCustomEmoji!");
}

@Nonnull
@Override
public ApplicationEmoji asApplication()
{
throw new IllegalStateException("Cannot convert UnicodeEmoji to ApplicationEmoji!");
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.internal.managers;

import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
Expand Down Expand Up @@ -54,7 +70,7 @@ public ApplicationEmojiManagerImpl reset(long... fields)
@Override
public ApplicationEmojiManager setName(@NotNull String name)
{
Checks.inRange(name, 2, 32, "Emoji name");
Checks.inRange(name, 2, CustomEmoji.EMOJI_NAME_MAX_LENGTH, "Emoji name");
Checks.matches(name, Checks.ALPHANUMERIC_WITH_DASH, "Emoji name");
this.name = name;
set |= NAME;
Expand Down

0 comments on commit 1596e1a

Please sign in to comment.