-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
92 lines (81 loc) · 2.52 KB
/
main.go
File metadata and controls
92 lines (81 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"context"
"errors"
"funnygomusic/databaser"
"funnygomusic/routes"
"github.com/gin-gonic/gin"
"log"
"net/http"
"os"
"os/signal"
"strconv"
"funnygomusic/bot"
_ "funnygomusic/databaser"
"funnygomusic/events"
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/state"
)
func main() {
id := gateway.DefaultIdentifier(os.Getenv("BOT_TOKEN"))
id.Properties.OS = "iOS"
id.Properties.Browser = "Discord iOS"
currentState := state.NewWithIdentifier(id)
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
b := bot.NewBotter(currentState, &ctx)
var alusers []databaser.AllowedUser
b.Db.Find(&alusers)
b.AllowList = append(b.AllowList, os.Getenv("BOT_OWNER"))
for _, u := range alusers {
b.AllowList = append(b.AllowList, strconv.Itoa(int(u.ID)))
}
PlCtx := context.WithoutCancel(ctx)
go b.Queue.Start(PlCtx)
currentState.AddHandler(func(c *gateway.ReadyEvent) { events.OnReady(c, b) })
currentState.AddHandler(func(c *gateway.MessageCreateEvent) { events.OnMessage(c, b) })
currentState.AddHandler(func(c *gateway.VoiceStateUpdateEvent) { events.OnVoiceStateUpdate(c, b) })
currentState.AddHandler(func(c *gateway.RelationshipAddEvent) { events.OnRelationshipAdd(c, b) })
// start connection
if err := currentState.Open(ctx); err != nil {
log.Fatalln("failed to open:", err)
}
defer currentState.Close()
cfg := databaser.MakeConfigPath()
gin.SetMode(gin.ReleaseMode)
ginr := gin.Default()
ginr.Use(func(c *gin.Context) {
c.Set("bot", b)
})
ginr.GET("/connected", routes.Connected)
ginr.GET("/vcInfo", routes.VcInfo)
qgroup := ginr.Group("/queue")
{
qgroup.GET("/skip", routes.SkipSong)
qgroup.GET("/pause", routes.PauseSong)
qgroup.GET("/resume", routes.ResumeSong)
qgroup.GET("/stop", routes.StopSong)
qgroup.GET("/clear", routes.ClearQueue)
qgroup.POST("/add", routes.PushToQueue)
qgroup.GET("/current", routes.CurrentSong)
qgroup.GET("/", routes.GetQueue)
}
//ginr.GET("/queue", routes.GetQueue)
//ginr.GET("/queue/current", routes.CurrentSong)
//ginr.POST("/queue/add", routes.PushToQueue)
ginr.Static("/artwork", cfg+"/artwork")
srv := &http.Server{
Addr: "0.0.0.0:34713",
Handler: ginr,
}
go func() {
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalln("failed to listen:", err)
}
}()
defer srv.Close()
log.Println("Blocking, press ctrl+c to continue...")
<-ctx.Done()
log.Println("Shutting down... going to save queue")
//b.Queue.SaveQueue()
}