mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat(command): extend slash command system with new commands and UX improvements
Add 9 new command groups (/model, /memory, /search, /browser, /usage, /email, /heartbeat, /skill, /fs) and improve existing commands by hiding internal UUIDs, resolving IDs to human-readable names in /settings, and switching /schedule to name-based references.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (h *Handler) buildFSGroup() *CommandGroup {
|
||||
g := newCommandGroup("fs", "Browse container filesystem")
|
||||
g.Register(SubCommand{
|
||||
Name: "list",
|
||||
Usage: "list [path] - List files in the container",
|
||||
Handler: func(cc CommandContext) (string, error) {
|
||||
if h.containerFS == nil {
|
||||
return "Container filesystem is not available.", nil
|
||||
}
|
||||
dir := "/"
|
||||
if len(cc.Args) > 0 {
|
||||
dir = cc.Args[0]
|
||||
}
|
||||
entries, err := h.containerFS.ListDir(cc.Ctx, cc.BotID, dir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(entries) == 0 {
|
||||
return fmt.Sprintf("Directory %q is empty.", dir), nil
|
||||
}
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "%s:\n", dir)
|
||||
for _, e := range entries {
|
||||
if e.IsDir {
|
||||
fmt.Fprintf(&b, " %s/\n", e.Name)
|
||||
} else {
|
||||
fmt.Fprintf(&b, " %s (%d bytes)\n", e.Name, e.Size)
|
||||
}
|
||||
}
|
||||
return b.String(), nil
|
||||
},
|
||||
})
|
||||
g.Register(SubCommand{
|
||||
Name: "read",
|
||||
Usage: "read <path> - Read a file from the container",
|
||||
Handler: func(cc CommandContext) (string, error) {
|
||||
if h.containerFS == nil {
|
||||
return "Container filesystem is not available.", nil
|
||||
}
|
||||
if len(cc.Args) < 1 {
|
||||
return "Usage: /fs read <path>", nil
|
||||
}
|
||||
content, err := h.containerFS.ReadFile(cc.Ctx, cc.BotID, cc.Args[0])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
const maxLen = 2000
|
||||
if len(content) > maxLen {
|
||||
content = content[:maxLen] + "\n... (truncated)"
|
||||
}
|
||||
return fmt.Sprintf("```\n%s\n```", content), nil
|
||||
},
|
||||
})
|
||||
return g
|
||||
}
|
||||
Reference in New Issue
Block a user