From 8d96b37ce300dff2ab3a362fb1fa4fe05af802ea Mon Sep 17 00:00:00 2001 From: lily Date: Fri, 17 Jul 2026 01:13:24 -0400 Subject: [PATCH] first commit --- .gitignore | 32 +++++++++++++++++++++++++++++++ go.mod | 5 +++++ go.sum | 2 ++ main.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aaadf73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Code coverage profiles and other test artifacts +*.out +coverage.* +*.coverprofile +profile.cov + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env + +# Editor/IDE +# .idea/ +# .vscode/ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1b02d59 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module hypixel-bans-api + +go 1.24.4 + +require github.com/joho/godotenv v1.5.1 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d61b19e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= diff --git a/main.go b/main.go new file mode 100644 index 0000000..4f07749 --- /dev/null +++ b/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" + "os" + "time" + + "github.com/joho/godotenv" +) + +type PunishmentStats struct { + Success bool `json:"success"` + WatchdogLastMinute int `json:"watchdog_lastMinute"` + WatchdogRollingDaily int `json:"watchdog_rollingDaily"` + WatchdogTotal int64 `json:"watchdog_total"` + StaffRollingDaily int `json:"staff_rollingDaily"` + StaffTotal int64 `json:"staff_total"` +} + +func fetchStats(apiKey string) (*PunishmentStats, error) { + req, err := http.NewRequest("GET", "https://api.hypixel.net/v2/punishmentstats", nil) + if err != nil { + return nil, err + } + req.Header.Set("API-Key", apiKey) + + client := &http.Client{Timeout: 10 * time.Second} + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("bad status: %s", resp.Status) + } + + var stats PunishmentStats + if err := json.NewDecoder(resp.Body).Decode(&stats); err != nil { + return nil, err + } + return &stats, nil +} + +func main() { + _ = godotenv.Load() + key := os.Getenv("HYPIXEL_API_KEY") + stats, err := fetchStats(key) + if err != nil { + fmt.Println("error:", err) + os.Exit(1) + } + fmt.Printf("%+v\n", stats) +}