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

View File

@ -18,7 +18,7 @@ type args struct {
ImportFile string `arg:"--import" help:"import a file from regex-cli"`
Stats []string `arg:"--stats" help:"add stats to a 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"`
Verbose bool `arg:"--verbose" help:"show more output"`
Bash bool `arg:"--bash" help:"generate bash completion"`

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)
}

View File

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