-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (62 loc) · 1.92 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
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"workoutbot/internal/db"
"workoutbot/internal/services"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
)
func main() {
// Project init
// Load .env file if it exists
if err := godotenv.Load(); err != nil {
log.Println("No .env file found")
}
// Get the Discord token
// Initialize the session and log fatal if error
errDiscord := services.InitializeDiscordGo()
// Initiailze AI - Currently Gemini 1.5
services.InitializeAiPartner()
if errDiscord != nil {
log.Printf("Error initializing DiscordGo: %v", errDiscord)
}
// Initialize MongoDB
db.MongoDBInit()
defer func() {
if err := db.MongoClient.Disconnect(context.TODO()); err != nil {
log.Fatalf("Failed to disconnect MongoDB client: %v", err)
}
log.Println("Disconnected from MongoDB")
}()
// Add Discord handlers
services.DiscordAddReactionHandler()
services.DiscordRemoveReactionHandler()
services.DiscordMessageCreateHandler()
services.DiscordHelpMessageHandler()
// Set the intent
services.DiscordSession.Identify.Intents = discordgo.IntentsAllWithoutPrivileged
// Open the Session
errDiscord = services.DiscordSession.Open()
if errDiscord != nil {
log.Fatal((errDiscord))
}
defer services.DiscordSession.Close()
defer services.AiClient.Close()
defer func() {
services.DiscordSession.ChannelMessageSend("898225507064250420", "The Bot is Offline from Main.go Ending")
}()
// This needs to happen after the session.Open() in order for commands to be registered.
services.RegisterCommands()
services.DiscordSlashCommandHandler()
services.DiscordSession.ChannelMessageSend("898225507064250420", "The bot is online!")
fmt.Println("The bot is online!")
// Create a channel to listen to system notifications in order to close up. Use CTRL + C to close
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}