-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (50 loc) · 1.21 KB
/
main.go
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
package main
import (
"context"
"log"
"os"
"os/signal"
"github.com/barkloaf/HolidayBot/db"
"github.com/barkloaf/HolidayBot/events"
"github.com/barkloaf/HolidayBot/misc"
"github.com/bwmarrin/discordgo"
"github.com/jackc/pgx/v4/pgxpool"
)
func main() {
connection, err := pgxpool.Connect(context.Background(), misc.Config.DBUrl)
if err != nil {
log.Fatalf("Database erorr: %v", err)
}
db.Init(connection)
client, err := discordgo.New("Bot " + misc.Config.Token)
if err != nil {
log.Fatalf("Client creation Error: %v", err)
}
for _, handler := range []interface{}{
events.ChannelDelete,
events.GuildCreate,
events.GuildDelete,
events.InteractionCreate,
events.MessageCreate,
events.Ready,
} {
client.AddHandler(handler)
}
err = client.Open()
if err != nil {
log.Fatalf("Cannot open the session: %v", err)
}
defer client.Close()
defer connection.Close()
for _, cmd := range commandInfo {
_, err := client.ApplicationCommandCreate(client.State.User.ID, "", cmd)
if err != nil {
log.Panicf("Cannot create '%v' command: %v", cmd.Name, err)
}
}
dailyPosting(client)
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
<-stop
log.Println("Shutting down...")
}