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

Fixing arithmetic exception when server memory is set to unlimited #6

Merged
merged 2 commits into from
Nov 17, 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
4 changes: 2 additions & 2 deletions src/main/kotlin/tech/goksi/pterobot/commands/Servers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Servers(jda: JDA) : SimpleCommand() {
}
event.deferReply(ConfigManager.config.getBoolean("BotInfo.Ephemeral")).queue()
val pteroMember = PteroMember(event.user)

event.message.delete().queue()
if (!pteroMember.isLinked()) {
event.hook.sendMessageEmbeds(
EmbedManager
Expand Down Expand Up @@ -254,7 +254,7 @@ class Servers(jda: JDA) : SimpleCommand() {
emoji = Emoji.fromUnicode(getButtonSetting("CloseEmoji"))
) {
it.deferEdit().queue()
val original = it.hook.retrieveOriginal().await()
it.hook.retrieveOriginal().queue { msg -> msg.delete().queue() }
}
event.hook.sendMessageEmbeds(response).addActionRow(
changeStateButton,
Expand Down
8 changes: 7 additions & 1 deletion src/main/kotlin/tech/goksi/pterobot/entities/ServerInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package tech.goksi.pterobot.entities

import com.mattmalec.pterodactyl4j.client.entities.ClientServer
import tech.goksi.pterobot.NodeStatus
import tech.goksi.pterobot.util.Common

data class ServerInfo(private val server: ClientServer) {
val identifier: String = server.identifier
val name: String = server.name
Expand All @@ -13,7 +15,11 @@ data class ServerInfo(private val server: ClientServer) {
val diskUsed = (utilization.disk.toFloat()) / 1024 / 1024 / 1024 //gb
val ramUsed = utilization.memory / 1024 / 1024 //mb
val diskMax = (server.limits.diskLong.toFloat()) / 1024
val ramMax = server.limits.memoryLong
val ramMax: Long
get() {
return if (server.limits.memoryLong != 0L) server.limits.memoryLong
else Common.getDefaultApplication().retrieveNodesByName(server.node, false).execute()[0].memoryLong
}
val emoji = when (status) {
"RUNNING" -> NodeStatus.ONLINE.emoji
"STARTING" -> NodeStatus.ONLINE.emoji
Expand Down