Skip to content

Commit

Permalink
feat: add timestamp to the embed
Browse files Browse the repository at this point in the history
* this allows users of the mobile app to see when the embed was last updated
  • Loading branch information
DarkAtra committed Apr 9, 2024
1 parent 7eef6a3 commit c9a79c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package de.darkatra.vrising.discord.serverstatus
import de.darkatra.vrising.discord.serverstatus.model.ServerInfo
import dev.kord.common.Color
import dev.kord.rest.builder.message.EmbedBuilder
import kotlinx.datetime.toKotlinInstant
import java.lang.String.CASE_INSENSITIVE_ORDER
import java.time.Instant

object ServerStatusEmbed {

Expand Down Expand Up @@ -79,6 +81,8 @@ object ServerStatusEmbed {
}
}
}

timestamp = Instant.now().toKotlinInstant()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package de.darkatra.vrising.discord.serverstatus
import de.darkatra.vrising.discord.serverstatus.model.ServerInfoTestUtils
import dev.kord.common.Color
import dev.kord.rest.builder.message.EmbedBuilder
import kotlinx.datetime.toJavaInstant
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import java.time.Instant

class ServerStatusEmbedTest {

Expand All @@ -14,6 +16,8 @@ class ServerStatusEmbedTest {
val serverInfo = ServerInfoTestUtils.getServerInfo()
val embedBuilder = EmbedBuilder()

val timestampBeforeEmbed = Instant.now()

ServerStatusEmbed.buildEmbed(
serverInfo = serverInfo,
apiEnabled = false,
Expand All @@ -22,13 +26,18 @@ class ServerStatusEmbedTest {
embedBuilder = embedBuilder
)

val timestampAfterEmbed = Instant.now()

assertThat(embedBuilder.title).isEqualTo(ServerInfoTestUtils.NAME)
assertThat(embedBuilder.color).isEqualTo(Color(red = 0, green = 142, blue = 68))
assertThat(embedBuilder.description).isEqualTo(ServerInfoTestUtils.DESCRIPTION)
assertThat(fieldByName(embedBuilder, "Ip and Port").value).isEqualTo("${ServerInfoTestUtils.IP}:${ServerInfoTestUtils.GAME_PORT}")
assertThat(fieldByName(embedBuilder, "Online count").value).isEqualTo("${ServerInfoTestUtils.NUMBER_OF_PLAYERS}/${ServerInfoTestUtils.MAX_PLAYERS}")
assertThat(fieldByName(embedBuilder, "Days running").value).isEqualTo(ServerInfoTestUtils.DAYS_RUNNING.toString())
assertThat(fieldByName(embedBuilder, "Online players").value).isEqualTo("**Atra**")
assertThat(embedBuilder.timestamp).isNotNull
assertThat(embedBuilder.timestamp!!.toJavaInstant()).isAfterOrEqualTo(timestampBeforeEmbed)
assertThat(embedBuilder.timestamp!!.toJavaInstant()).isBeforeOrEqualTo(timestampAfterEmbed)
}

private fun fieldByName(embedBuilder: EmbedBuilder, fieldName: String): EmbedBuilder.Field {
Expand Down

0 comments on commit c9a79c1

Please sign in to comment.