2026-09-09 16:19:41 -06:00
package main
import (
"context"
2026-09-10 15:44:40 -06:00
"os"
2026-10-08 15:38:25 -06:00
_ "sync"
2026-09-09 16:19:41 -06:00
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-09-09 16:19:41 -06:00
2026-10-08 15:38:25 -06:00
"code.destrealm.net/zancarius/justusbot/internal/commands"
2026-09-09 16:19:41 -06:00
)
2026-11-03 20:49:26 -07:00
var Version string
2026-09-09 16:19:41 -06:00
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 ) )
}
2026-10-20 15:17:00 -06:00
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 )
}
2026-11-03 20:49:26 -07:00
if Version == "" {
Version = "devbuild"
}
2026-10-08 15:38:25 -06:00
cmd := cli . Command {
2026-11-03 20:49:26 -07:00
Version : Version ,
2026-10-08 15:38:25 -06:00
Flags : [ ] cli . Flag {
& cli . StringFlag {
Name : "config" ,
Aliases : [ ] string { "c" } ,
Usage : "Configuration location. Defaults to working directory." ,
Value : "settings.toml" ,
} ,
} ,
Commands : [ ] * cli . Command {
2026-10-30 14:28:38 -06:00
{
Name : "announcements" ,
Description : "Announcement management" ,
Commands : [ ] * cli . Command {
{
Name : "add" ,
Description : "Adds an announcement to the queue." ,
Action : cmdHost . Announcements ( ) . AddAnnouncement ,
Flags : [ ] cli . Flag {
& cli . Int64Flag {
Name : "chatid" ,
Aliases : [ ] string { "c" } ,
Usage : "Specifies the chat ID. Required." ,
} ,
& cli . BoolFlag {
Name : "reminders" ,
Aliases : [ ] string { "r" } ,
Usage : "Enables reminders for this announcement. Reminders will be triggered one week prior and one day prior by default." ,
} ,
& cli . StringFlag {
Name : "title" ,
Aliases : [ ] string { "t" } ,
Usage : "Announcement title (optional)." ,
} ,
& cli . StringFlag {
Name : "content" ,
Aliases : [ ] string { "a" } ,
Usage : "Announcement content (required)." ,
} ,
} ,
} ,
{
Name : "weekly" ,
Description : "Lists this week's announcements." ,
Action : cmdHost . Announcements ( ) . ListThisWeeksAnnouncements ,
} ,
{
Name : "today" ,
Description : "Lists the announcements for today." ,
Action : cmdHost . Announcements ( ) . ListTodaysAnnouncements ,
Flags : [ ] cli . Flag {
& cli . Int64Flag {
Name : "chatid" ,
Aliases : [ ] string { "c" } ,
Usage : "Specifies the chat ID. Required." ,
} ,
} ,
} ,
} ,
} ,
2026-10-23 21:29:01 -06:00
{
Name : "birthdays" ,
Description : "Birthday management" ,
Commands : [ ] * cli . Command {
2026-10-24 14:10:24 -06:00
{
Name : "add" ,
Description : "Adds a birthday to the roster. Chat ID and name required." ,
Action : cmdHost . Birthdays ( ) . AddBirthday ,
Flags : [ ] cli . Flag {
& cli . Int64Flag {
Name : "chatid" ,
Aliases : [ ] string { "c" } ,
Usage : "Specifies the chat ID. Required." ,
} ,
& cli . StringFlag {
Name : "name" ,
Aliases : [ ] string { "n" } ,
Usage : "User's name. The user does not have to be present in the specified chat." ,
} ,
& cli . Int64Flag {
Name : "userid" ,
Aliases : [ ] string { "u" } ,
Usage : "User ID. The user must be present in the specified chat if this flag is provided." ,
} ,
& cli . IntFlag {
Name : "birthday-id" ,
Aliases : [ ] string { "b" } ,
Usage : "Birthday ID. Use this flag to update a given birthday. This can be used to change the birthday's date or to attach a user ID with a previously entered birthday." ,
} ,
} ,
} ,
{
Name : "list" ,
Description : "Lists all birthdays in the current roster for the specified chat ID." ,
Action : cmdHost . Birthdays ( ) . ListBirthdays ,
Flags : [ ] cli . Flag {
& cli . Int64Flag {
Name : "chatid" ,
Aliases : [ ] string { "c" } ,
Usage : "Specifies the chat ID. Required." ,
} ,
2026-10-26 15:28:00 -06:00
& cli . BoolFlag {
Name : "annunciate" ,
Aliases : [ ] string { "a" } ,
Usage : "Displays announcement status." ,
} ,
2026-10-24 14:10:24 -06:00
} ,
} ,
2026-10-23 21:29:01 -06:00
{
Name : "weekly" ,
Description : "Lists the weekly birthdays for this week." ,
Action : cmdHost . Birthdays ( ) . ListWeeklyBirthdays ,
Flags : [ ] cli . Flag {
& cli . Int64Flag {
Name : "chatid" ,
Aliases : [ ] string { "c" } ,
Usage : "Specifies the chat ID. Required." ,
} ,
} ,
} ,
{
Name : "today" ,
Description : "Lists birthdays for today." ,
Action : cmdHost . Birthdays ( ) . ListTodaysBirthdays ,
Flags : [ ] cli . Flag {
& cli . Int64Flag {
Name : "chatid" ,
Aliases : [ ] string { "c" } ,
Usage : "Specifies the chat ID. Required." ,
} ,
} ,
} ,
} ,
} ,
2026-10-14 14:26:18 -06:00
{
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 {
2026-10-14 14:26:18 -06:00
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-14 14:26:18 -06:00
} ,
} ,
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. ` ,
2026-10-22 21:23:35 -06:00
Action : cmdHost . Initalizer ( ) . DoUp ,
2026-10-08 15:38:25 -06:00
} ,
{
Name : "down" ,
Description : ` Perform downgrade. ` ,
} ,
2026-10-26 15:28:00 -06:00
{
Name : "list" ,
Description : "List available migrations" ,
Action : cmdHost . Initalizer ( ) . ListMigrations ,
} ,
2026-10-08 15:38:25 -06:00
} ,
} ,
{
2026-10-16 00:14:43 -06:00
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." ,
} ,
} ,
} ,
2026-10-15 15:11:40 -06:00
{
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
}