-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
96 lines (77 loc) · 2.36 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
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
93
94
95
96
package main
import (
"fmt"
"log"
"github.com/caarlos0/env"
"github.com/joho/godotenv"
"github.com/stripe/stripe-go/v72"
"gitlab.com/logan9312/discord-auction-bot/commands"
"gitlab.com/logan9312/discord-auction-bot/connect"
"gitlab.com/logan9312/discord-auction-bot/database"
"gitlab.com/logan9312/discord-auction-bot/routers"
)
// Environment struct
type Environment struct {
Environment string `env:"ENVIRONMENT,required"`
DiscordToken string `env:"DISCORD_TOKEN,required"`
Migrate bool `env:"MIGRATE"`
Host string `env:"DB_HOST"`
Password string `env:"DB_PASSWORD"`
StripeToken string `env:"STRIPE_TOKEN"`
NewHost string `env:"NEW_HOST"`
NewPassword string `env:"NEW_PASSWORD"`
}
func main() {
environment := Environment{}
err := godotenv.Load(".env")
if err != nil {
fmt.Println("Error loading .env file:", err)
}
if err := env.Parse(&environment); err != nil {
fmt.Println(err)
log.Fatal("FAILED TO LOAD ENVIRONMENT VARIABLES")
}
stripe.Key = environment.StripeToken
//Connects database
database.DatabaseConnect(environment.Password, environment.Host, environment.Environment)
//Connects main bot
mainSession, err := connect.BotConnect(environment.DiscordToken, environment.Environment)
if err != nil {
fmt.Println(err)
}
database.NewDBConnect(environment.NewPassword, environment.NewHost)
database.CopyTablesToNewDB()
devData := database.DevSetup{
BotID: mainSession.State.User.ID,
}
result := database.DB.First(&devData)
if result.Error != nil {
fmt.Println(result.Error)
}
err = mainSession.UpdateGameStatus(0, "Bot Version "+devData.Version)
if err != nil {
fmt.Println("Error setting status", err)
}
WhiteLabels := []map[string]any{}
result = database.DB.Model([]database.WhiteLabels{}).Find(&WhiteLabels)
if result.Error != nil {
fmt.Println("Error fetching whitelabels:", result.Error)
}
connect.Timers(mainSession)
for _, v := range WhiteLabels {
s, err := connect.BotConnect(v["bot_token"].(string), environment.Environment)
if err != nil {
fmt.Println("Error connecting bot: %w", err)
}
if s.State.User.ID == "995022149226082324" {
err = s.UpdateGameStatus(0, "Bot Version "+devData.Version)
if err != nil {
fmt.Println("Error setting status", err)
}
}
connect.Timers(s)
}
go commands.SetRoles(mainSession)
fmt.Println("Bot is running!")
routers.HealthCheck()
}