-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuilder.go
More file actions
86 lines (69 loc) · 1.57 KB
/
Copy pathbuilder.go
File metadata and controls
86 lines (69 loc) · 1.57 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
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
package main
import (
"chillbot/internal/admin"
automoderator "chillbot/internal/automod"
"chillbot/internal/bot"
"chillbot/internal/config"
"chillbot/internal/events"
"chillbot/internal/general"
"chillbot/internal/greetings"
"chillbot/internal/logging"
"chillbot/internal/reactions"
youtube "chillbot/internal/youtube_feed"
"os"
"github.com/bwmarrin/discordgo"
)
var modules = []bot.Module{
&reactions.ReactorModule{},
&greetings.GreetingsModule{},
&youtube.YoutubeFeedModule{},
&general.GeneralModule{},
&admin.AdminModule{},
&automoderator.AutoModule{},
&events.EventsModule{},
}
type Builder struct {
Bot *bot.Bot
logger *logging.Logger
config *config.Config
container *Container
}
func NewBuilder(l *logging.Logger, c *config.Config) *Builder {
return &Builder{
logger: l,
config: c,
container: &Container{},
}
}
func (b *Builder) Build() error {
err := b.BuildDiscordClient()
if err != nil {
return err
}
b.BuildBot()
b.Bot.Init()
b.BuildModules()
return nil
}
func (b *Builder) BuildDiscordClient() error {
token := os.Getenv("DISCORD_CLIENT_SECRET")
discord, err := discordgo.New("Bot " + token)
b.container.Discord = discord
return err
}
func (b *Builder) BuildBot() {
b.Bot = bot.NewBot(b.container.Discord, b.logger, b.config)
}
func (b *Builder) BuildModules() {
deps := &bot.CommonDeps{
Bot: b.Bot,
Logger: b.logger,
Config: b.config,
}
for _, m := range modules {
err := m.Load(deps)
if err != nil {
b.logger.LogFatal("Error loading module %s, error %s", m.GetName(), err.Error())
}
}
}