feat(chat): add --new-chat and --count-auto flags
This commit is contained in:
parent
1a6b367144
commit
b03889101d
2
argv.go
2
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"`
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue