forked from ReeceDonovan/uni-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (41 loc) · 1.12 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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/ReeceDonovan/uni-bot/commands"
"github.com/ReeceDonovan/uni-bot/config"
"github.com/bwmarrin/discordgo"
"github.com/go-co-op/gocron"
"github.com/spf13/viper"
)
func main() {
config.InitConfig()
// Discord connection
token := viper.GetString("discord.token")
session, err := discordgo.New("Bot " + token)
session.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsAll)
if err != nil {
log.Println("Failed to initialise bot")
}
err = session.Open()
if err != nil {
log.Println("Failed to connect bot")
os.Exit(1)
}
commands.RegisterCommands(session)
// Scheduling
scheduler := gocron.NewScheduler(time.UTC)
scheduler.StartAsync()
schedulerTrigger := viper.GetString("scheduler.trigger")
log.Println("Scheduling Due Assignments Check for " + schedulerTrigger)
scheduler.Every(1).Day().At(schedulerTrigger).Do(commands.DueAssignments, session)
log.Println("Bot is Running")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
log.Println("Exiting")
session.Close()
}