generated from csivitu/Template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
71 lines (56 loc) · 1.3 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
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/csivitu/bl0b/db"
"github.com/csivitu/bl0b/notifs"
"github.com/csivitu/bl0b/routines"
_ "github.com/go-sql-driver/mysql"
"github.com/bwmarrin/discordgo"
)
// Session is declared in a global namespace
var Session, _ = discordgo.New()
func init() {
Session.Token = os.Getenv("DG_TOKEN")
if Session.Token == "" {
flag.StringVar(&Session.Token, "t", "", "Discord Authentication Token")
}
}
func main() {
fmt.Println(`
___. .__ _______ ___.
\_ |__ | | \ _ \\_ |__
| __ \| | / /_\ \| __ \
| \_\ \ |_\ \_/ \ \_\ \
|___ /____/\_____ /___ /
\/ \/ \/
`)
flag.Parse()
if Session.Token == "" {
log.Println("Discord Authentication Token not provided.")
return
}
err := Session.Open()
if err != nil {
log.Printf("Error opening connection to Discord, %s\n", err)
os.Exit(1)
}
err = db.Init()
if err != nil {
log.Println(err)
log.Fatalln("Could not initialize DB!")
}
n := notifs.NewNotifHandler(Session)
routines.Populate(time.Hour)
routines.Analyze(time.Minute, n)
log.Println("bl0b is running, press Ctrl-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
Session.Close()
}