#Custom Command for time till restart

45 messages · Page 1 of 1 (latest)

hazy oasis
#

Is it possible to have a script that allows for a custom command /rtime ?

This script would take the time value from /kubejs/loadtime.json then get the current time, then take away from load time to see how long till next restart what is ever 14400 seconds

Would maybe look somthing like this
/rtime > There is 1 hour and 22 minutes till next scheduled restart

I already have the current time of server load

{
    "time": "1696285059"
}
elder birchBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

hazy oasis
#

Custom Command for time till restart

limber ocean
#

Hello fellow ATM boy 🙂

const $Instant = Java.loadClass("java.time.Instant")

ServerEvents.commandRegistry((event) => {
  const { commands } = event
  event.register(
    commands.literal("rtime").executes((ctx) => {
      let maxUptime = 14400
      let loadTimeJson = JsonIO.read("kubejs/loadtime.json")
      let loadTime = $Instant.ofEpochSecond(parseInt(loadTimeJson.time))
      let timeNow = $Instant.now()
      let currentUptime = timeNow.minusSeconds(loadTime.epochSecond).epochSecond
      let secondsLeft = maxUptime - currentUptime
      let hoursLeft = Math.floor(secondsLeft / 3600)
      let minutesLeft = Math.floor((secondsLeft % 3600) / 60)
      if (secondsLeft < 0) {
        ctx.source.server.tell(
          Text.of(`Should have been restarted ${-hoursLeft} hour(s) and ${-minutesLeft} minute(s) ago!`)
        )
      } else
        ctx.source.server.tell(
          Text.of(`There is ${hoursLeft} hour(s) and ${minutesLeft} minute(s) till next scheduled restart`)
        )
      return 1
    })
  )
})

try this

limber ocean
hazy oasis
#

Thank you, I will try tonight

limber ocean
hazy oasis
#

Thank Uncandango works as intended

#

hazy oasis
#

Error loading KubeJS script: ReferenceError: "Java" is not defined. (server_scripts:rtime-1.18.js#1)

Should it be different on 1.18.2 @limber ocean?

const $Instant = java("java.time.Instant")

onEvent("command.registry", event => {
  const { commands } = event
  event.register(
    commands.literal("rtime").executes((ctx) => {
      let maxUptime = 14400
      let loadTimeJson = JsonIO.read("kubejs/loadtime.json")
      let loadTime = $Instant.ofEpochSecond(parseInt(loadTimeJson.time))
      let timeNow = $Instant.now()
      let currentUptime = timeNow.minusSeconds(loadTime.epochSecond).epochSecond
      let secondsLeft = maxUptime - currentUptime
      let hoursLeft = Math.floor(secondsLeft / 3600)
      let minutesLeft = Math.floor((secondsLeft % 3600) / 60)
      if (secondsLeft < 0) {
        ctx.source.server.tell(
          Text.of(`Should have been restarted ${-hoursLeft} hour(s) and ${-minutesLeft} minute(s) ago!`)
        )
      } else
        ctx.source.server.tell(
          Text.of(`There is ${hoursLeft} hour(s) and ${minutesLeft} minute(s) till next scheduled restart`)
        )
      return 1
    })
  )
})
limber ocean
#

yes

#

it is java("java.time.Instant")

#

don't know about the other stuff tho

hazy oasis
#

Right ok ty

hazy oasis
#

Not sure if it's possible

limber ocean
#

need to enable that

#

there is a config file

#

let me check where it is on 1.18

hazy oasis
#

printRemappedClasses=false

#

that?

limber ocean
#

no

#

something about filter

#

class

hazy oasis
#

disableClassFilter=false

#

that then

limber ocean
#

yes

#

turn to true

hazy oasis
#

ty, will see what it's like after a reboot in 4 hours ish

limber ocean
hazy oasis
#

Does not error

limber ocean
#

hover over?

hazy oasis
#

Hover over the error message

#

Guessing it's to do with the text.of area

#

if #20 is line then it's

ctx.source.server.tell(
          Text.of(`There is ${hoursLeft} hour(s) and ${minutesLeft} minute(s) till next scheduled restart`)
        )
limber ocean
#

despair

have to check if it is something diff on server, sometimes we need to use .server.asKJS()

let me see if any of this syntax errors

hazy oasis
#

possible I made a mistake

hazy oasis
#

Ty for checking if possible

#

If you comeup with anything I'll comeback and check tomorrow

limber ocean
#

ctx.source.server.asKJS().tell(

yeah you need to add .asKJS()

#

@hazy oasis