summaryrefslogtreecommitdiff
path: root/doInput.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-08-22 10:43:52 -0500
committerJeff Carr <[email protected]>2025-08-22 10:43:52 -0500
commitcf812da1d3cfa94fa7d701a0dc01c6bd2ff3f70b (patch)
tree40cdd80e6f1b4391d65255e106faa0aa7236a1c3 /doInput.go
parent5db2567e60bc5bc72b7a12dc0765c773a24fa77a (diff)
add doInput()
Diffstat (limited to 'doInput.go')
-rw-r--r--doInput.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/doInput.go b/doInput.go
new file mode 100644
index 0000000..3278d36
--- /dev/null
+++ b/doInput.go
@@ -0,0 +1,56 @@
+package main
+
+import (
+ "os"
+ "time"
+
+ "go.wit.com/lib/protobuf/chatpb"
+ "go.wit.com/log"
+ "google.golang.org/protobuf/types/known/timestamppb"
+)
+
+func doInput(s string) {
+ filename := "/tmp/gemini-input.log"
+ f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+ defer f.Close()
+ if _, err := f.WriteString(s + "\n"); err != nil {
+ log.Println(err)
+ }
+
+ log.Info("INPUT LOGGED TO", filename)
+
+ // Load the existing chats.
+ all := chatpb.NewChats()
+ if err := all.ConfigLoad(); err != nil {
+ log.Warn("Error loading config, can't add to auto chat:", err)
+ return
+ }
+
+ // Find the "auto" chat.
+ var autoChat *chatpb.Chat
+ for _, chat := range all.GetChats() {
+ if chat.GetChatName() == "auto" {
+ autoChat = chat
+ break
+ }
+ }
+
+ // If the "auto" chat is found, add the new entry.
+ if autoChat != nil {
+ newEntry := &chatpb.ChatEntry{
+ From: chatpb.Who_USER,
+ Content: s,
+ Ctime: timestamppb.New(time.Now()),
+ }
+ autoChat.Entries = append(autoChat.Entries, newEntry)
+ if err := all.ConfigSave(); err != nil {
+ log.Warn("Error saving config after adding to auto chat:", err)
+ } else {
+ log.Info("Added new entry to 'auto' chat.")
+ }
+ }
+}