justusbot/cmd/bot/main.go

213 lines
5.6 KiB
Go
Raw Normal View History

package main
import (
"context"
2026-09-10 15:44:40 -06:00
"os"
2026-10-08 15:38:25 -06:00
_ "sync"
2026-10-08 15:38:25 -06:00
"github.com/urfave/cli/v3"
"go.destrealm.net/errors"
"go.destrealm.net/logging/v3"
"go.destrealm.net/vfs"
2026-10-08 15:38:25 -06:00
"code.destrealm.net/zancarius/justusbot/internal/commands"
)
// Send any text message to the bot after the bot has been started
func main() {
2026-10-08 15:38:25 -06:00
var rootfs vfs.VFS
ctx := context.Background()
logger := logging.Logger()
if root, err := os.Getwd(); err != nil {
logger.Error("could not discern working directory:", err)
os.Exit(1)
} else {
rootfs = vfs.MustVFS(vfs.NewVFS(root))
}
cmdHost, err := commands.NewCommandHost(ctx, rootfs)
2026-10-08 15:38:25 -06:00
if err != nil {
logger.Error("unable to configure host:", errors.Unfurl(err))
os.Exit(1)
}
cmd := cli.Command{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Configuration location. Defaults to working directory.",
Value: "settings.toml",
},
},
Commands: []*cli.Command{
{
Name: "chats",
Description: "Chats management",
Commands: []*cli.Command{
{
Name: "add",
Description: "Adds a chat to the bot. This is analogous to running /start within a chat.",
Action: cmdHost.Chats().AddChat,
Flags: []cli.Flag{
2026-10-20 15:33:29 -06:00
&cli.Int64Flag{
Name: "id",
Aliases: []string{"i"},
Usage: "Specifies the chat id.",
},
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "Specifies the chat name.",
},
},
},
2026-10-20 20:17:07 -06:00
{
Name: "list",
Description: "List the chats currently configured for this bot.",
Action: cmdHost.Chats().ListChats,
},
},
},
2026-10-08 15:38:25 -06:00
{
Name: "init",
Description: "Initialize the bot, its database, and prepare for first run.",
Action: cmdHost.Initalizer().DoInstall,
},
{
Name: "metadata",
Description: "Bible metadata-related management.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "translation",
Aliases: []string{"t"},
Value: "bsb",
Usage: "Specifies the Bible translation to use for metadata extraction and inspection.",
},
},
Commands: []*cli.Command{
{
Name: "dump",
Description: "Dump Bible metadata",
Commands: []*cli.Command{
{
Name: "structure",
Description: "Dumps an entire translation's book, chapter, and verse structure.",
Action: cmdHost.Meta().DumpStructure,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "format",
Aliases: []string{"f"},
Value: "json",
Usage: `Output format. One of "json" or "toml".`,
},
},
},
},
},
},
},
{
Name: "migrate",
Description: "Migration-related commands and options.",
Commands: []*cli.Command{
{
Name: "up",
Description: `Perform upgrade.`,
},
{
Name: "down",
Description: `Perform downgrade.`,
},
},
},
{
Name: "start",
Description: "Start the bot.",
Action: cmdHost.App().Start,
2026-10-08 15:38:25 -06:00
},
{
Name: "verse",
Description: "Bible verse helpers and tools.",
2026-10-08 21:22:11 -06:00
Commands: []*cli.Command{
{
Name: "add",
Description: "Add a verse to the random rotation.",
Action: cmdHost.Verse().AddVerse,
2026-10-14 15:36:24 -06:00
//Future implementation.
2026-10-08 21:22:11 -06:00
Flags: []cli.Flag{
&cli.StringFlag{
Name: "translation",
Usage: "Specifies which translation this verse should be included from.",
Aliases: []string{"t"},
2026-10-14 15:36:24 -06:00
Value: "bsb",
2026-10-08 21:22:11 -06:00
},
&cli.StringFlag{
Name: "date",
Usage: "Specifies a date for the provided verse to be displayed. Overrides random rotation. Use with caution as this will override random verses for all connected chats.",
Aliases: []string{"d"},
},
2026-10-14 15:36:24 -06:00
},
2026-10-08 21:22:11 -06:00
},
2026-10-14 14:08:49 -06:00
{
Name: "list",
Description: "List verses configured for this bot.",
Action: cmdHost.Verse().ListVerses,
Flags: []cli.Flag{
&cli.IntFlag{
Name: "chatid",
Usage: "Include verses configured for the specified chat ID",
Aliases: []string{"i"},
},
&cli.BoolFlag{
Name: "random",
2026-10-14 14:11:58 -06:00
Usage: "Include verse random rotation status (if available); requires --chatid",
2026-10-14 14:08:49 -06:00
Aliases: []string{"r"},
},
},
},
2026-10-14 23:56:06 -06:00
{
Name: "random",
Description: "select a random verse from the bot's database",
Action: cmdHost.Verse().RandomVerse,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "simulate",
Usage: "Simulates a random verse selection from the bot and populates the internal verse rotation status. Requires --chatid.",
},
&cli.Int64Flag{
Name: "chatid",
Usage: "Specifies the chat ID to generate a random verse from. If --simulate is specified, this will update the verse rotation statues.",
},
},
},
{
Name: "rotation",
Description: "Random verse rotation management",
Commands: []*cli.Command{
{
Name: "delete",
Description: "Delete rotations; this will reset the specified chat's exhausted verses list",
Action: cmdHost.Verse().DeleteRotation,
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "chatid",
Aliases: []string{"i"},
Usage: "Specifies the chat from which rotation records will be removed.",
},
},
},
},
},
2026-10-08 21:22:11 -06:00
},
2026-10-08 15:38:25 -06:00
},
},
}
err = cmd.Run(ctx, os.Args)
if err != nil {
panic(err)
}
2026-09-10 15:44:40 -06:00
}