Related to #17 Renames the `/ping` command to `/info` and adds the following information to the Discord response * Uptime of the server * Total number of claims currently held * Total number of unique players holding claimsabsences
parent
fb25f21472
commit
c454b92d41
@ -0,0 +1,26 @@
|
||||
package themis
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Uptime returns the time elapsed since the start of the current process ID.
|
||||
func Uptime() (time.Duration, error) {
|
||||
raw, err := os.ReadFile("/proc/uptime")
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to read uptime from OS: %w", err)
|
||||
}
|
||||
|
||||
i := bytes.IndexRune(raw, ' ')
|
||||
|
||||
up, err := strconv.ParseFloat(string(raw[:i]), 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to parse uptime from OS: %w", err)
|
||||
}
|
||||
|
||||
return time.Duration(int(up*1000) * int(time.Millisecond)), nil
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package themis
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUptime(t *testing.T) {
|
||||
uptime, err := Uptime()
|
||||
assert.NoError(t, err)
|
||||
assert.Greater(t, uptime, 100*time.Millisecond)
|
||||
}
|
Loading…
Reference in new issue