feat(chat): add --get-next-auto-topic flag

This commit is contained in:
Castor Regex 2025-08-24 13:23:12 -05:00 committed by Jeff Carr
parent 82eba977cd
commit a9b7fca08d
3 changed files with 37 additions and 15 deletions

12
argv.go
View File

@ -17,12 +17,12 @@ type args struct {
Input string `arg:"--input" help:"should get a string from regex-cli"` Input string `arg:"--input" help:"should get a string from regex-cli"`
ImportFile string `arg:"--import" help:"import a file from regex-cli"` ImportFile string `arg:"--import" help:"import a file from regex-cli"`
Stats []string `arg:"--stats" help:"add stats to a chat"` Stats []string `arg:"--stats" help:"add stats to a chat"`
NewChat []string `arg:"--new-chat" help:"create a new chat"` NewChat []string `arg:"--new-chat" help:"create a new chat"`
CountAuto bool `arg:"--count-auto" help:"count the number of auto chats"` GetNextAutoTopic bool `arg:"--get-next-auto-topic" help:"get the next auto topic name"`
Force bool `arg:"--force" help:"try to strong arm things"` Force bool `arg:"--force" help:"try to strong arm things"`
Verbose bool `arg:"--verbose" help:"show more output"` Verbose bool `arg:"--verbose" help:"show more output"`
Bash bool `arg:"--bash" help:"generate bash completion"` Bash bool `arg:"--bash" help:"generate bash completion"`
BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"` BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"`
} }
type EmptyCmd struct { type EmptyCmd struct {

24
doGetNextAutoTopic.go Normal file
View File

@ -0,0 +1,24 @@
package main
import (
"fmt"
"strconv"
"strings"
)
func doGetNextAutoTopic() {
if err := me.chats.ConfigLoad(); err != nil {
badExit(err)
}
max := 0
for _, chat := range me.chats.GetChats() {
if strings.HasPrefix(chat.GetChatName(), "Auto ") {
numStr := strings.TrimPrefix(chat.GetChatName(), "Auto ")
num, err := strconv.Atoi(numStr)
if err == nil && num > max {
max = num
}
}
}
fmt.Printf("Auto %d", max+1)
}

16
main.go
View File

@ -46,17 +46,15 @@ func main() {
} }
me.chats = chatpb.NewChats() me.chats = chatpb.NewChats()
if !argv.CountAuto { if err := me.chats.ConfigLoad(); err != nil {
if err := me.chats.ConfigLoad(); err != nil { badExit(err)
badExit(err) }
} if verifyUuids(me.chats) {
if verifyUuids(me.chats) { me.chats.ConfigSave()
me.chats.ConfigSave()
}
} }
if argv.CountAuto { if argv.GetNextAutoTopic {
doCountAuto() doGetNextAutoTopic()
okExit("") okExit("")
} }