init: ops-assistant codebase

This commit is contained in:
OpenClaw Agent
2026-03-19 21:23:28 +08:00
commit 81deba4766
94 changed files with 10767 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
package registry
import (
"sort"
"ops-assistant/internal/core/command"
)
type Handler func(userID int64, cmd *command.ParsedCommand) (string, error)
type Registry struct {
handlers map[string]Handler
moduleHandlers map[string]Handler
}
func New() *Registry {
return &Registry{handlers: map[string]Handler{}, moduleHandlers: map[string]Handler{}}
}
func (r *Registry) Register(name string, h Handler) {
r.handlers[name] = h
}
func (r *Registry) RegisterModule(module string, h Handler) {
r.moduleHandlers[module] = h
}
func (r *Registry) Handle(userID int64, cmd *command.ParsedCommand) (string, bool, error) {
if h, ok := r.handlers[cmd.Name]; ok {
out, err := h(userID, cmd)
return out, true, err
}
if h, ok := r.moduleHandlers[cmd.Module]; ok {
out, err := h(userID, cmd)
return out, true, err
}
return "", false, nil
}
func (r *Registry) ListModules() []string {
mods := make([]string, 0, len(r.moduleHandlers))
for m := range r.moduleHandlers {
mods = append(mods, m)
}
sort.Strings(mods)
return mods
}