Files
simplexcalc/cmd/simplexcalc/run.go
T
clawbot 16649e0f2f
check / check (push) Successful in 54s
A SimpleX Chat bot that answers arithmetic (closes #1)
Remove the template's HTTP service, database and fx wiring. Add exact
arithmetic on go/parser and go/constant, a client that runs simplex-chat
as a child process and drives its WebSocket API, and the bot, which keeps
an auto-accepting address and replies to each message. The image adds the
checksum-pinned simplex-chat v7.0.2 on Ubuntu 22.04.

Model: opus-5-5
2026-09-26 22:01:51 +00:00

59 lines
1.1 KiB
Go

package main
import (
"context"
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
"github.com/spf13/cobra"
"sneak.berlin/go/simplexcalc/internal/bot"
"sneak.berlin/go/simplexcalc/internal/config"
"sneak.berlin/go/simplexcalc/internal/logger"
)
func runCmd() *cobra.Command {
return &cobra.Command{
Use: "run",
Short: "run the bot",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return run(cmd.Context())
},
}
}
// run reads the configuration and runs the bot until SIGINT or SIGTERM,
// or until it fails. A failure is the process's exit status, so a
// supervisor restarts it.
func run(ctx context.Context) error {
cfg, err := config.New()
if err != nil {
return fmt.Errorf("reading configuration: %w", err)
}
log := logger.New(os.Stdout, cfg.Debug)
log.Info("starting",
"appname", appname,
"version", version,
"arch", runtime.GOARCH,
"data_dir", cfg.DataDir,
)
ctx, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer stop()
err = bot.Run(ctx, log, cfg.DataDir)
if err != nil {
log.Error("stopped", "error", err)
return err
}
log.Info("stopped")
return nil
}