// Command core is the bot gateway: it talks to Telegram, owns the queue and // the database, serves the HTTP API and, by default, runs an embedded // download worker. // // core run the bot // core worker add register a remote worker and print its token // core worker revoke revoke a worker's token // core worker list list workers package main import ( "context" "flag" "fmt" "os" "os/signal" "syscall" "github.com/noderunners/dlbot/internal/app" "github.com/noderunners/dlbot/internal/config" ) func main() { configPath := flag.String("config", "", "path to a TOML config file (optional, env vars override it)") flag.Parse() cfg, err := config.Load(*configPath) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) } log := app.NewLogger(cfg.Log, app.Secrets(cfg)...) ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop() // "core worker ..." manages worker tokens and exits. if args := flag.Args(); len(args) > 0 { if args[0] != "worker" { fmt.Fprintf(os.Stderr, "unknown command %q\n", args[0]) os.Exit(2) } if err := app.WorkerAdmin(ctx, cfg, args[1:], os.Stdout); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } return } a, err := app.New(ctx, app.Options{Config: cfg, Log: log}) if err != nil { log.Error("startup failed", "err", err) os.Exit(1) } if err := a.Run(ctx); err != nil { log.Error("core exited with error", "err", err) os.Exit(1) } }