Compentize Workload (#4)

This commit is contained in:
2023-03-30 23:51:05 -04:00
committed by GitHub
parent 228c293b70
commit 3d15d09dd7
21 changed files with 528 additions and 319 deletions

35
main.go
View File

@@ -1,13 +1,17 @@
package main
import (
"errors"
"flag"
"fmt"
"log"
"os"
"path"
"github.com/ilyakaznacheev/cleanenv"
"github.com/yeslayla/birdbot/app"
"github.com/yeslayla/birdbot/core"
"github.com/yeslayla/birdbot/events"
)
func main() {
@@ -27,12 +31,41 @@ func main() {
return
}
log.Printf("Using config: %s", config_file)
cfg := &core.Config{}
_, err := os.Stat(config_file)
if errors.Is(err, os.ErrNotExist) {
log.Printf("Config file not found: '%s'", config_file)
err := cleanenv.ReadEnv(cfg)
if err != nil {
log.Fatal(err)
}
} else {
err := cleanenv.ReadConfig(config_file, cfg)
if err != nil {
log.Fatal(err)
}
}
bot := app.NewBot()
if err := bot.Initialize(config_file); err != nil {
if err := bot.Initialize(cfg); err != nil {
log.Fatal("Failed to initialize: ", err)
}
loader := app.NewComponentLoader(bot)
if cfg.Features.AnnounceEvents {
loader.LoadComponent(events.NewAnnounceEventsComponent(bot.Mastodon, cfg.Discord.NotificationChannel))
}
if cfg.Features.ManageEventChannels {
loader.LoadComponent(events.NewManageEventChannelsComponent(cfg.Discord.EventCategory, bot.Session))
}
if cfg.Features.ReccurringEvents {
loader.LoadComponent(events.NewRecurringEventsComponent())
}
if err := bot.Run(); err != nil {
log.Fatal(err)
}