This repository was archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
51 lines (39 loc) · 1.29 KB
/
app.go
File metadata and controls
51 lines (39 loc) · 1.29 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
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
"github.com/codify-community/internals/codify-updater/handlers"
"github.com/codify-community/internals/codify-updater/log"
"github.com/codify-community/internals/codify-updater/utils"
"github.com/joho/godotenv"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func main() {
godotenv.Load()
conf, err := utils.LoadConfig()
utils.Try(err)
log.Wait("connecting to database ...")
mongo, err := mongo.Connect(context.Background(), options.Client().ApplyURI(conf.MongoConnectionURI))
utils.Try(err)
discord, err := discordgo.New("Bot " + conf.DiscordToken)
utils.Try(err)
discord.AddHandlerOnce(func(s *discordgo.Session, r *discordgo.Ready) {
go handlers.OnReady(mongo, &conf, s, r)
})
discord.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Message != nil && m.Author != nil && m.Member != nil {
handlers.OnMessage(mongo, &conf, s, m)
}
})
utils.Try(err)
defer discord.Close()
discord.Identify.Intents = discordgo.IntentsGuilds | discordgo.IntentsGuildMessages | discordgo.IntentsGuildVoiceStates
utils.Try(discord.Open())
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}