From b03889101d81b1b6c79f627a22dca7569cb14ad6 Mon Sep 17 00:00:00 2001 From: Castor Regex Date: Sun, 24 Aug 2025 13:07:43 -0500 Subject: [PATCH] feat(chat): add --new-chat and --count-auto flags --- argv.go | 2 ++ doCountAuto.go | 16 ++++++++++++++++ doNewChat.go | 28 ++++++++++++++++++++++++++++ main.go | 10 ++++++++++ 4 files changed, 56 insertions(+) create mode 100644 doCountAuto.go create mode 100644 doNewChat.go diff --git a/argv.go b/argv.go index 21c6210..775b0b5 100644 --- a/argv.go +++ b/argv.go @@ -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"` diff --git a/doCountAuto.go b/doCountAuto.go new file mode 100644 index 0000000..2aa958e --- /dev/null +++ b/doCountAuto.go @@ -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) +} diff --git a/doNewChat.go b/doNewChat.go new file mode 100644 index 0000000..bd71f45 --- /dev/null +++ b/doNewChat.go @@ -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) +} diff --git a/main.go b/main.go index c0dbf79..57c91e2 100644 --- a/main.go +++ b/main.go @@ -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("")