Merge pull request #88 from dalbodeule/develop

apiDiscordRoutes fix. (7x)
This commit is contained in:
JinU Choi 2024-08-15 10:25:37 +09:00 committed by GitHub
commit 380e36188f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,19 +22,20 @@ object DiscordGuildCache {
suspend fun getCachedGuilds(guildId: String): Guild? { suspend fun getCachedGuilds(guildId: String): Guild? {
val now = Instant.now() val now = Instant.now()
val guild = cache[guildId] var guild = cache[guildId]
if(guild == null || guild.timestamp.plusSeconds(EXP_SECONDS).isBefore(now) || !guild.isBotAvailable) { if(guild == null || guild.timestamp.plusSeconds(EXP_SECONDS).isBefore(now) || !guild.isBotAvailable) {
mutex.withLock { mutex.withLock {
if(guild == null || guild.timestamp.plusSeconds(EXP_SECONDS).isBefore(now) || !guild.isBotAvailable) { if(guild == null || guild!!.timestamp.plusSeconds(EXP_SECONDS).isBefore(now) || !guild!!.isBotAvailable) {
fetchAllGuilds() fetchAllGuilds()
guild = cache[guildId]
} }
try { try {
if (guild?.guild?.roles?.isEmpty() == true) { if (guild!!.guild.roles.isEmpty()) {
guild.guild.roles = fetchGuildRoles(guildId) guild!!.guild.roles = fetchGuildRoles(guildId)
} }
if (guild?.guild?.channel?.isEmpty() == true) { if (guild!!.guild.channel.isEmpty()) {
guild.guild.channel = fetchGuildChannels(guildId) guild!!.guild.channel = fetchGuildChannels(guildId)
} }
} catch(e: Exception) { } catch(e: Exception) {
logger.info("guild fetch is failed.") logger.info("guild fetch is failed.")