From 49fed219902151967c89cf8e487cf4fc7ba30e9c Mon Sep 17 00:00:00 2001 From: "Benjamin A. Shelton" Date: Tue, 20 Oct 2026 15:17:16 -0600 Subject: [PATCH] Further app-ifying app. --- internal/app/app.go | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index e7d8cdc..b4db3bf 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -2,22 +2,23 @@ package app import ( "context" + "fmt" "io" - "github.com/jmoiron/sqlx" "github.com/joho/godotenv" "github.com/robfig/cron/v3" "github.com/urfave/cli/v3" "go.destrealm.net/logging/v3" "go.destrealm.net/vfs" + "code.destrealm.net/zancarius/justusbot/internal/models" "code.destrealm.net/zancarius/justusbot/internal/settings" ) type App struct { bot *bot ctx context.Context - db *sqlx.DB + db *models.Database fs vfs.VFS logger *logging.Log settings *settings.Settings @@ -25,12 +26,31 @@ type App struct { cron *cron.Cron } -func NewApp(root vfs.VFS, conf *settings.Settings) *App { - return &App{ +func NewApp(ctx context.Context, root vfs.VFS, conf *settings.Settings) (*App, error) { + app := &App{ + ctx: ctx, + db: models.OpenDatabase(ctx, conf), fs: root, logger: logging.Logger(), settings: conf, } + + if err := app.db.Open(); err != nil { + return nil, err + } + + return app, nil +} + +func (a *App) loadCron() error { + a.cron = cron.New() + a.cron.AddFunc(fmt.Sprintf("TZ=%s %s", + a.settings.System.TimeZone, + a.settings.DailyScripture.Schedule), a.scripture) + + a.cron.Start() + + return nil } func (a *App) loadEnv() error { @@ -51,13 +71,22 @@ func (a *App) loadEnv() error { } } + //if chats, err := a.db. + return nil } +func (a *App) scripture() { + +} + func (a *App) Start(ctx context.Context, cmd *cli.Command) error { if err := a.loadEnv(); err != nil { return err } + if err := a.loadCron(); err != nil { + return err + } bot := NewBot(ctx, a.settings) bot.Run()