-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (76 loc) · 1.63 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
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package main
import (
"context"
"effie3/bot"
"effie3/cmd"
"effie3/logger"
"effie3/messenger"
"effie3/riot"
"effie3/tracker"
"effie3/values"
"os"
"os/signal"
"strings"
"sync"
"syscall"
)
var sc = make(chan os.Signal, 1)
var botChannel = make(chan bot.Api)
var log = logger.Get("app").Sugar()
func main() {
defer logger.Sync()
var wg sync.WaitGroup
wg.Add(2)
go func() {
api, err := cmd.Execute()
if err != nil {
log.Error(err)
sc <- os.Kill
}
botChannel <- api
wg.Done()
}()
go func() {
if os.Getenv("DISCORD_CHANNEL") == "" {
log.Error("DISCORD_CHANNEL is empty")
sc <- os.Kill
return
}
messenger.Start(<-botChannel, os.Getenv("DISCORD_CHANNEL"))
wg.Done()
}()
// tracker context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
wg.Wait()
err := tracker.Start(ctx, values.Targets.List)
if err != nil {
log.Error(err)
sc <- os.Kill
}
}()
for _, s := range strings.Split(os.Getenv("SUMMONER_LIST"), ";") {
if s == "" {
log.Fatal("empty name not allowed")
}
log.Debugw("adding summoner from env list", "name", s)
info, err := riot.GetSummonerByName(s)
if err != nil {
log.Errorw("error while adding predefined summoner", "err", err, "summonerName", s)
continue
}
err = values.Targets.Add(info.ID)
if err != nil {
log.Warn(err)
}
}
// Wait here until CTRL-C or other term signal is received.
//fmt.Println("Bot is now running. Press CTRL-C to exit.")
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
log.Warnw("shutting down...")
}