urfave/cli.
This commit is contained in:
parent
6474c45abb
commit
8140201588
1 changed files with 105 additions and 6 deletions
111
cmd/bot/main.go
111
cmd/bot/main.go
|
|
@ -2,31 +2,130 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"slices"
|
||||
"sync"
|
||||
_ "sync"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/mymmrac/telego"
|
||||
th "github.com/mymmrac/telego/telegohandler"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/urfave/cli/v3"
|
||||
"go.destrealm.net/errors"
|
||||
"go.destrealm.net/logging/v3"
|
||||
"go.destrealm.net/vfs"
|
||||
|
||||
"fmt"
|
||||
|
||||
"code.destrealm.net/zancarius/justusbot/internal/commands"
|
||||
"code.destrealm.net/zancarius/justusbot/internal/settings"
|
||||
)
|
||||
|
||||
// Send any text message to the bot after the bot has been started
|
||||
|
||||
func main() {
|
||||
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))
|
||||
}
|
||||
|
||||
if err := godotenv.Load(); err != nil {
|
||||
panic(fmt.Sprintf("dotenv: %s", err))
|
||||
}
|
||||
|
||||
b, c, err := NewBot()
|
||||
cmdHost, err := commands.NewCommandHost(rootfs)
|
||||
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: "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: "run",
|
||||
Description: "Run the bot.",
|
||||
},
|
||||
{
|
||||
Name: "verse",
|
||||
Description: "Bible verse helpers and tools.",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = cmd.Run(ctx, os.Args)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
/*b, c, err := NewBot()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -39,7 +138,7 @@ func main() {
|
|||
err := b.Start()
|
||||
fmt.Println(err)
|
||||
}()
|
||||
wg.Wait()
|
||||
wg.Wait()*/
|
||||
|
||||
/*fmt.Println(bible.FindAlias("mat"))
|
||||
s, err := settings.LoadSettings("settings.toml")
|
||||
|
|
@ -58,7 +157,7 @@ type Bot struct {
|
|||
func NewBot() (bot *Bot, errch chan error, err error) {
|
||||
bot = &Bot{}
|
||||
|
||||
conf, err := settings.LoadSettings("settings.toml")
|
||||
conf, err := settings.LoadSettings("settings.toml", vfs.MustVFS(vfs.NewVFS(".")))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue