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

Fix default avatar URL not working #691

Merged
merged 7 commits into from
Sep 15, 2022
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
2 changes: 1 addition & 1 deletion core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -6401,7 +6401,7 @@ public final class dev/kord/core/entity/GuildWidget : dev/kord/core/KordObject,
}

public abstract class dev/kord/core/entity/Icon : dev/kord/core/KordObject {
public synthetic fun <init> (ZLdev/kord/rest/route/CdnUrl;Ldev/kord/core/Kord;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/kord/rest/Image$Format;ZLdev/kord/rest/route/CdnUrl;Ldev/kord/core/Kord;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getAnimated ()Z
Copy link
Member

@lukellmann lukellmann Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you bring animated back for binary compatibility? Not sure if it should be deprecated though.

public final fun getCdnUrl ()Ldev/kord/rest/route/CdnUrl;
public final fun getFormat ()Ldev/kord/rest/Image$Format;
Expand Down
27 changes: 12 additions & 15 deletions core/src/main/kotlin/entity/Icon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import dev.kord.rest.Image
import dev.kord.rest.route.CdnUrl
import dev.kord.rest.route.DiscordCdn

public sealed class Icon(public val animated: Boolean, public val cdnUrl: CdnUrl, override val kord: Kord) :
KordObject {

public val format: Image.Format
get() = when {
animated -> Image.Format.GIF
else -> Image.Format.WEBP
}

public sealed class Icon(
public val format: Image.Format,
public val animated: Boolean,
public val cdnUrl: CdnUrl,
override val kord: Kord
) : KordObject {
public val url: String
get() = cdnUrl.toUrl {
this.format = [email protected]
Expand All @@ -40,22 +37,22 @@ public sealed class Icon(public val animated: Boolean, public val cdnUrl: CdnUrl
})

override fun toString(): String {
return "Icon(type=${javaClass.name},animated=$animated,cdnUrl=$cdnUrl,kord=$kord)"
return "Icon(type=${javaClass.name},format=$format,animated=$animated,cdnUrl=$cdnUrl,kord=$kord)"
}

public class EmojiIcon(animated: Boolean, emojiId: Snowflake, kord: Kord) :
Icon(animated, DiscordCdn.emoji(emojiId), kord)
Icon(if (animated) Image.Format.GIF else Image.Format.WEBP, animated, DiscordCdn.emoji(emojiId), kord)

public class DefaultUserAvatar(discriminator: Int, kord: Kord) :
Icon(false, DiscordCdn.defaultAvatar(discriminator), kord)
Icon(Image.Format.PNG /* Discord Default Avatars only support PNG */, false, DiscordCdn.defaultAvatar(discriminator), kord)

public class UserAvatar(userId: Snowflake, avatarHash: String, kord: Kord) :
Icon(avatarHash.startsWith("a_"), DiscordCdn.userAvatar(userId, avatarHash), kord)
Icon(if (avatarHash.startsWith("a_")) Image.Format.GIF else Image.Format.WEBP, avatarHash.startsWith("a_"), DiscordCdn.userAvatar(userId, avatarHash), kord)

public class MemberAvatar(guildId: Snowflake, userId: Snowflake, avatarHash: String, kord: Kord) :
Icon(avatarHash.startsWith("a_"), DiscordCdn.memberAvatar(guildId, userId, avatarHash), kord)
Icon(if (avatarHash.startsWith("a_")) Image.Format.GIF else Image.Format.WEBP, avatarHash.startsWith("a_"), DiscordCdn.memberAvatar(guildId, userId, avatarHash), kord)

public class RoleIcon(roleId: Snowflake, iconHash: String, kord: Kord) :
Icon(iconHash.startsWith("a_"), DiscordCdn.roleIcon(roleId, iconHash), kord)
Icon(if (iconHash.startsWith("a_")) Image.Format.GIF else Image.Format.WEBP, iconHash.startsWith("a_"), DiscordCdn.roleIcon(roleId, iconHash), kord)

}