Initial incomplete

This commit is contained in:
minish 2026-02-25 06:32:26 -05:00
commit 1a2a0196e5
Signed by: min
SSH Key Fingerprint: SHA256:mf+pUTmK92Y57BuCjlkBdd82LqztTfDCQIUp0fCKABc
4 changed files with 115 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.env

14
go.mod Normal file
View File

@ -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
)

10
go.sum Normal file
View File

@ -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=

90
main.go Normal file
View File

@ -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()
}