From 1a2a0196e52ffdfca8b0640f86d121f5c9f10137 Mon Sep 17 00:00:00 2001 From: min Date: Wed, 25 Feb 2026 06:32:26 -0500 Subject: [PATCH] Initial incomplete --- .gitignore | 1 + go.mod | 14 +++++++++ go.sum | 10 ++++++ main.go | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 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..e8ea323 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.env diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..60e2e62 --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module git.min.rip/min/skybase + +go 1.25.5 + +require ( + github.com/diamondburned/arikawa/v3 v3.6.0 + github.com/gorilla/websocket v1.5.3 + github.com/joho/godotenv v1.5.1 +) + +require ( + github.com/gorilla/schema v1.4.1 // indirect + golang.org/x/time v0.10.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d843292 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/diamondburned/arikawa/v3 v3.6.0 h1:8sno6tO9F1TEkg1ChHfjuVX41a+uv3opcfWeNvbuhV4= +github.com/diamondburned/arikawa/v3 v3.6.0/go.mod h1:thocAM2X8lRDHuEZR5vWYaT4w+tb/vOKa1qm+r0gs5A= +github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E= +github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +golang.org/x/time v0.10.0 h1:3usCWA8tQn0L8+hFJQNgzpWbd89begxN66o1Ojdn5L4= +golang.org/x/time v0.10.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..c4e22cd --- /dev/null +++ b/main.go @@ -0,0 +1,90 @@ +package main + +import ( + "context" + "log" + "net/http" + "os" + "sync" + + "github.com/diamondburned/arikawa/v3/gateway" + "github.com/diamondburned/arikawa/v3/session" + "github.com/gorilla/websocket" + "github.com/joho/godotenv" +) + +var upgrader = websocket.Upgrader{} + +func handleIndex(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("hello from skybase")) +} + +func handleChat(w http.ResponseWriter, r *http.Request) { + c, err := upgrader.Upgrade(w, r, nil) + if err != nil { + return + } + defer c.Close() + + for { + mt, message, err := c.ReadMessage() + if err != nil { + break + } + + err = c.WriteMessage(mt, message) + if err != nil { + break + } + } +} + +func main() { + godotenv.Load() + + // load env + token := os.Getenv("BOT_TOKEN") + if token == "" { + log.Fatal("missing bot token") + } + httpListen := os.Getenv("HTTP_LISTEN") + if httpListen == "" { + log.Fatal("missing http listen address") + } + + // init session + s := session.New("Bot " + token) + s.AddHandler(func(c *gateway.ReadyEvent) { + u, err := s.Me() + if err != nil { + log.Fatal(err) + } + log.Println("started as", u.Username) + }) + s.AddHandler(func(c *gateway.MessageCreateEvent) { + if c.Author.Bot { + return + } + log.Println(c.Author.Username, "sent", c.Content) + }) + s.AddIntents(gateway.IntentGuildMessages) + + // init http + http.HandleFunc("/", handleIndex) + http.HandleFunc("/chat", handleChat) + + // begin + var wg sync.WaitGroup + wg.Go(func() { + if err := s.Connect(context.Background()); err != nil { + log.Fatal(err) + } + defer s.Close() + }) + wg.Go(func() { + http.ListenAndServe(httpListen, nil) + }) + + // wait + wg.Wait() +}