-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (75 loc) · 1.98 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
package main
import (
"flag"
"github.com/Ressetkk/Iku-chan/cmd/nhentai"
"github.com/Ressetkk/Iku-chan/pkg/activity"
"github.com/Ressetkk/Iku-chan/pkg/dux"
"github.com/bwmarrin/discordgo"
"github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
)
var (
logLevel = flag.String("logLevel", "info", "Set log level.")
)
func main() {
flag.Parse()
logrus.SetFormatter(&logrus.JSONFormatter{})
token := os.Getenv("IKU_BOT_TOKEN")
if token == "" {
logrus.Fatal("IKU_BOT_TOKEN cannot be empty. Exiting.")
}
session, err := discordgo.New("Bot " + token)
if err != nil {
logrus.WithError(err).Fatal("Could not initialize Discord session")
}
switch *logLevel {
case "error":
logrus.SetLevel(logrus.ErrorLevel)
session.LogLevel = discordgo.LogError
break
case "warn":
logrus.SetLevel(logrus.WarnLevel)
session.LogLevel = discordgo.LogWarning
break
case "info":
logrus.SetLevel(logrus.InfoLevel)
session.LogLevel = discordgo.LogWarning
break
case "debug":
logrus.SetLevel(logrus.DebugLevel)
session.LogLevel = discordgo.LogInformational
break
case "trace":
logrus.SetLevel(logrus.TraceLevel)
session.LogLevel = discordgo.LogDebug
break
default:
logrus.Fatal("wrong \"logLevel\" value: %s", *logLevel)
}
if err := session.Open(); err != nil {
logrus.WithError(err).Fatal("Could not open Discord Bot session")
}
logrus.Info("Discord session initialized. Initializing commands.")
ha := activity.NewHActivity(session)
r := &dux.Command{
Name: "iku",
Description: `The bot for most perverted and thirsty degenerates.
Come and use me, senpai~`,
}
r.AddCommands(nhentai.GetCmd(), nhentai.SearchCmd(), nhentai.RandomCmd(), ha.TodayCmd())
handler := dux.Handler{
AllowMentions: true,
Root: r,
}
session.AddHandler(handler.Set())
go ha.Run()
defer func() {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Kill, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
s := <-sig
logrus.Infof("Requested %v. Exiting.", s)
_ = session.Close()
}()
}