package cf import ( "strings" "ops-assistant/internal/core/command" "ops-assistant/internal/core/ecode" coremodule "ops-assistant/internal/core/module" "ops-assistant/internal/core/runbook" "gorm.io/gorm" ) type Module struct { db *gorm.DB exec *runbook.Executor runner *coremodule.Runner } func New(db *gorm.DB, exec *runbook.Executor) *Module { return &Module{db: db, exec: exec, runner: coremodule.NewRunner(db, exec)} } func (m *Module) Handle(userID int64, cmd *command.ParsedCommand) (string, error) { text := strings.TrimSpace(cmd.Raw) if text == "/cf" || strings.HasPrefix(text, "/cf help") { return "CF 模块\n- /cf status [--dry-run]\n- /cf zones\n- /cf dns list \n- /cf dns update [ttl] [proxied:true|false]\n- /cf dnsadd [on|off] [type]\n- /cf dnsset [true]\n- /cf dnsdel YES\n- /cf dnsproxy on|off\n- /cf workers list", nil } specs := commandSpecs() if sp, ok := coremodule.MatchCommand(text, specs); ok { jobID, out, err := coremodule.ExecTemplate(m.runner, userID, cmd.Raw, sp.Template) if err != nil { return ecode.Tag(ecode.ErrStepFailed, coremodule.FormatExecError(sp, err)), nil } if out == "dry-run" { return ecode.Tag("OK", coremodule.FormatDryRunMessage(sp.Template)), nil } return ecode.Tag("OK", coremodule.FormatSuccessMessage(sp.Template, jobID)), nil } return ecode.Tag(ecode.ErrStepFailed, "CF 模块已接入,当前支持:/cf status, /cf help"), nil }