Skip to content

Commit

Permalink
Update Constants and Profile rendering to get the profile assets locally
Browse files Browse the repository at this point in the history
  • Loading branch information
WinG4merBR committed Jan 22, 2025
1 parent b50e7e4 commit 09b96e3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
42 changes: 26 additions & 16 deletions common/src/main/kotlin/net/cakeyfox/common/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package net.cakeyfox.common

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.hocon.Hocon
import java.io.InputStream

object Constants {
const val UNBAN_FORM_URL = "https://forms.gle/bKfRKxoyFGZzRB7x8"
const val FOXY_WEBSITE = "https://foxybot.win"
// const val CROWDIN = "https://foxybot.win/translate"
const val TERMS = "https://foxybot.win/br/support/terms"
const val SUPPORT_SERVER = "https://foxybot.win/br/support"
const val INVITE_LINK = "https://discord.com/oauth2/authorize?client_id=1006520438865801296&scope=bot+applications.commands&permissions=269872255"
Expand All @@ -19,32 +19,42 @@ object Constants {
const val SUPPORT_SERVER_ID = "768267522670723094"


fun getDefaultActivity(environment: String): String {
return when(environment) {
"development" -> "https://youtu.be/0OIqlp2U9EQ"
"production" -> "foxybot.win · /help"
else -> "foxybot.win · /help"
fun getDefaultActivity(environment: String, clusterName: String?): String {
if (clusterName != null) {
return when(environment) {
"development" -> "https://youtu.be/0OIqlp2U9EQ | Cluster: $clusterName"
"production" -> "foxybot.win · /help | Cluster: $clusterName"
else -> "foxybot.win · /help | Cluster: $clusterName"
}
} else {
return when(environment) {
"development" -> "https://youtu.be/0OIqlp2U9EQ"
"production" -> "foxybot.win · /help"
else -> "foxybot.win · /help"
}
}
}

/* ---- [Profile Assets] ---- */
fun getProfileBackground(backgroundId: String): String {
return "https://cakey.foxybot.win/assets/backgrounds/$backgroundId"

fun getProfileBackground(backgroundId: String): InputStream {
return javaClass.getResourceAsStream("/profile/backgrounds/$backgroundId")!!
}

fun getProfileLayout(layoutId: String): String {
return "https://cakey.foxybot.win/assets/layouts/$layoutId"
fun getProfileLayout(layoutId: String): InputStream {
return javaClass.getResourceAsStream("/profile/layouts/$layoutId")!!
}

fun getProfileDecoration(maskId: String): String {
return "https://cakey.foxybot.win/assets/masks/$maskId.png"
fun getProfileDecoration(maskId: String): InputStream {
return javaClass.getResourceAsStream("/profile/decorations/$maskId.png")!!
}

fun getMarriedOverlay(layoutId: String): String {
return "https://cakey.foxybot.win/assets/layouts/${layoutId}-married.png"
fun getMarriedOverlay(layoutId: String): InputStream {
return javaClass.getResourceAsStream("/profile/layouts/${layoutId}-married.png")!!
}

fun getProfileBadge(badgeId: String): String {
return "https://cakey.foxybot.win/assets/badges/$badgeId"
fun getProfileBadge(badgeId: String): InputStream {
return javaClass.getResourceAsStream("/profile/badges/$badgeId")!!
}

}
10 changes: 9 additions & 1 deletion foxy/src/main/kotlin/net/cakeyfox/foxy/FoxyInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class FoxyInstance(
private lateinit var topggStatsSender: TopggStatsSender
private lateinit var environment: String
private val activeJobs = ThreadUtils.activeJobs
private val currentClusterName = if (config.discord.clusters.size < 2) null else currentCluster.name
private val coroutineExecutor = ThreadUtils.createThreadPool("CoroutineExecutor [%d]")
val threadPoolManager = ThreadPoolManager()
val coroutineDispatcher = coroutineExecutor.asCoroutineDispatcher()
Expand Down Expand Up @@ -88,7 +89,14 @@ class FoxyInstance(
)
.setAutoReconnect(true)
.setStatus(OnlineStatus.ONLINE)
.setActivity(Activity.customStatus(Constants.getDefaultActivity(config.environment)))
.setActivity(
Activity.customStatus(
Constants.getDefaultActivity(
config.environment,
currentClusterName
)
)
)
.setShardsTotal(config.discord.totalShards)
.setShards(currentCluster.minShard, currentCluster.maxShard)
.setMemberCachePolicy(MemberCachePolicy.ALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ data class FoxyConfig(
@Serializable
data class OtherSettings(
val foxyApi: FoxyAPISettings,
val internalApi: InternalApi,
val artistry: ArtistrySettings,
val activityUpdater: ActivityUpdaterSettings,
val statsSenderPort: Int,
val topggToken: String,
) {
@Serializable
data class InternalApi(
val key: String
)

@Serializable
data class FoxyAPISettings(
val key: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package net.cakeyfox.foxy.utils.profile

import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import net.cakeyfox.foxy.utils.image.ImageUtils
import net.cakeyfox.serializable.database.data.Background
import net.cakeyfox.serializable.database.data.Badge
import net.cakeyfox.serializable.database.data.Decoration
import net.cakeyfox.serializable.database.data.Layout
import java.awt.image.BufferedImage
import java.io.InputStream
import javax.imageio.ImageIO

object ProfileCacheManager {
val backgroundCache: Cache<String, Background> = Caffeine.newBuilder().build()
Expand All @@ -18,11 +19,5 @@ object ProfileCacheManager {
.maximumSize(100)
.build()

suspend fun loadImageFromCache(url: String): BufferedImage {
return imageCache.getIfPresent(url) ?: run {
val image = ImageUtils.loadProfileAssetFromURL(url)
imageCache.put(url, image)
image
}
}
fun loadImageFromFile(stream: InputStream): BufferedImage = ImageIO.read(stream)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class ProfileRender(
}

val layoutDeferred = async {
ProfileCacheManager.loadImageFromCache(Constants.getProfileLayout(layoutInfo.filename))
ProfileCacheManager.loadImageFromFile(Constants.getProfileLayout(layoutInfo.filename))
}

val backgroundDeferred = async {
ProfileCacheManager.loadImageFromCache(Constants.getProfileBackground(backgroundInfo.filename))
ProfileCacheManager.loadImageFromFile(Constants.getProfileBackground(backgroundInfo.filename))
}

val layout = layoutDeferred.await()
Expand Down Expand Up @@ -140,7 +140,7 @@ class ProfileRender(

val decorationDeferred = async {
data.userProfile.decoration?.let {
ImageUtils.loadProfileAssetFromURL(Constants.getProfileDecoration(it))
ProfileCacheManager.loadImageFromFile(Constants.getProfileDecoration(it))
}
}

Expand Down Expand Up @@ -187,7 +187,7 @@ class ProfileRender(
}

val decorationImage =
ImageUtils.loadProfileAssetFromURL(
ProfileCacheManager.loadImageFromFile(
Constants.getProfileDecoration(
decorationInfo.filename.replace(
".png",
Expand Down Expand Up @@ -238,7 +238,7 @@ class ProfileRender(
var y = layoutInfo.profileSettings.positions.badgesPosition.y

for (badge in userBadges) {
val badgeImage = ImageUtils.loadProfileAssetFromURL(Constants.getProfileBadge(badge.asset))
val badgeImage = ProfileCacheManager.loadImageFromFile(Constants.getProfileBadge(badge.asset))
graphics.drawImage(badgeImage, x.toInt(), y.toInt(), 50, 50, null)

x += 60
Expand All @@ -251,7 +251,7 @@ class ProfileRender(

private suspend fun drawMarryInfo(userData: FoxyUser, layout: Layout) {
val marriedDateFormatted = context.utils.convertToHumanReadableDate(userData.marryStatus.marriedDate!!)
val marriedOverlay = ImageUtils.loadProfileAssetFromURL(Constants.getMarriedOverlay(layout.id))
val marriedOverlay = ProfileCacheManager.loadImageFromFile(Constants.getMarriedOverlay(layout.id))
val color = if (layout.darkText) Color.BLACK else Color.WHITE
val partnerUser = context.jda.retrieveUserById(userData.marryStatus.marriedWith!!).await()

Expand Down

0 comments on commit 09b96e3

Please sign in to comment.