App-related cruft WIP.
This commit is contained in:
parent
823c114db0
commit
a3671d03da
1 changed files with 41 additions and 32 deletions
|
|
@ -2,59 +2,68 @@ package app
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/mymmrac/telego"
|
||||
th "github.com/mymmrac/telego/telegohandler"
|
||||
"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/settings"
|
||||
)
|
||||
|
||||
type app struct {
|
||||
//ds *datastore
|
||||
type App struct {
|
||||
bot *bot
|
||||
ctx context.Context
|
||||
db *sqlx.DB
|
||||
fs vfs.VFS
|
||||
logger *logging.Log
|
||||
settings *settings.Settings
|
||||
|
||||
cron *cron.Cron
|
||||
}
|
||||
|
||||
func NewApp(conf string) (*app, error) {
|
||||
/*a := &app{}
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func NewApp(root vfs.VFS, conf *settings.Settings) *App {
|
||||
return &App{
|
||||
fs: root,
|
||||
logger: logging.Logger(),
|
||||
settings: conf,
|
||||
}
|
||||
if root, err := vfs.NewVFS(cwd); err == nil {
|
||||
a.ds, err = newDataStore(root)
|
||||
if s, err := settings.LoadSettings(conf, root); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
a.settings = s
|
||||
}
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return a, nil*/
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *app) Start() error {
|
||||
func (a *App) loadEnv() error {
|
||||
// Load .env from VFS.
|
||||
fp, err := a.fs.Open(".env")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf, err := io.ReadAll(fp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
env, err := godotenv.UnmarshalBytes(buf)
|
||||
for k, v := range env {
|
||||
switch k {
|
||||
case "TOKEN":
|
||||
a.settings.Service.BotToken = v
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) Start(ctx context.Context, cmd *cli.Command) error {
|
||||
if err := a.loadEnv(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bot := NewBot(ctx, a.settings)
|
||||
bot.Run()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type chats struct {
|
||||
}
|
||||
|
||||
type bot struct {
|
||||
settings *settings.Settings
|
||||
tgbot *telego.Bot
|
||||
handler *th.BotHandler
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
|
||||
chats *chats
|
||||
}
|
||||
|
||||
func newBot() (*bot, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue