feat(chat): add --new-chat and --count-auto flags

This commit is contained in:
Castor Regex 2025-08-24 13:07:43 -05:00 committed by Jeff Carr
parent 1a6b367144
commit b03889101d
4 changed files with 56 additions and 0 deletions

View File

@ -17,6 +17,8 @@ type args struct {
Input string `arg:"--input" help:"should get a string from regex-cli"`
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"`
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"`

16
doCountAuto.go Normal file
View File

@ -0,0 +1,16 @@
package main
import (
"fmt"
"strings"
)
func doCountAuto() {
count := 0
for _, chat := range me.chats.GetChats() {
if strings.HasPrefix(chat.GetChatName(), "Auto ") {
count++
}
}
fmt.Println(count)
}

28
doNewChat.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"fmt"
"go.wit.com/lib/protobuf/chatpb"
"go.wit.com/log"
"google.golang.org/protobuf/types/known/timestamppb"
)
func doNewChat() {
if len(argv.NewChat) != 2 {
log.Error(fmt.Errorf("expected 2 arguments for --new-chat"))
return
}
uuid := argv.NewChat[0]
topic := argv.NewChat[1]
chat := &chatpb.Chat{
Uuid: uuid,
ChatName: topic,
Ctime: timestamppb.Now(),
}
me.chats.Chats = append(me.chats.Chats, chat)
me.chats.ConfigSave()
log.Info("created new chat for", uuid)
}

10
main.go
View File

@ -53,6 +53,16 @@ func main() {
me.chats.ConfigSave()
}
if argv.CountAuto {
doCountAuto()
okExit("")
}
if argv.NewChat != nil {
doNewChat()
okExit("")
}
if argv.Stats != nil {
doStats()
okExit("")