From 10c3727b016f2e88ed24c0b1bb7615dfa9933af6 Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Thu, 6 Aug 2026 17:17:01 +0800 Subject: [PATCH] feat(internal/controller): split trigger from controller.go as a seperate module. feat(internal/controller/pipes/qq_napcat): add message receive debug output. --- internal/controller/controller.go | 45 +----------------- internal/controller/pipes/qq_napcat/qq.go | 4 ++ internal/controller/trigger.go | 57 +++++++++++++++++++++++ 3 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 internal/controller/trigger.go diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 884814f..9bbf549 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -2,7 +2,6 @@ package controller import ( "fmt" - "strings" "sync" "nukumizu-backend/config" @@ -110,46 +109,4 @@ func (m *Manager) NotifyAllAdmins(message string) { } postLog.Info(fmt.Sprintf("Notifying via %s: %s", ctrl.Name(), message)) } -} - -// ParseCommand parses a raw message text into a Command. -// Format: /{{command}} {{args...}} -func ParseCommand(rawText string) (cmd Command, ok bool) { - rawText = strings.TrimSpace(rawText) - if !strings.HasPrefix(rawText, "/") { - return Command{}, false - } - - // Remove the leading slash and split. - parts := strings.SplitN(rawText[1:], " ", 2) - cmd.Command = strings.ToLower(parts[0]) - cmd.RawText = rawText - - if len(parts) > 1 { - argStr := strings.TrimSpace(parts[1]) - - // Special handling for /run: first arg is uuid, rest is command. - if cmd.Command == "run" { - spaceIdx := strings.Index(argStr, " ") - if spaceIdx > 0 { - cmd.Args = []string{argStr[:spaceIdx], strings.TrimSpace(argStr[spaceIdx+1:])} - } else { - cmd.Args = []string{argStr} - } - } else { - cmd.Args = strings.Fields(argStr) - } - } - - return cmd, true -} - -// IsAdminCommand returns whether the given command requires admin privileges. -func IsAdminCommand(command string) bool { - switch command { - case "shutdown", "reboot", "run": - return true - default: - return false - } -} +} \ No newline at end of file diff --git a/internal/controller/pipes/qq_napcat/qq.go b/internal/controller/pipes/qq_napcat/qq.go index f611256..f4ea6ae 100644 --- a/internal/controller/pipes/qq_napcat/qq.go +++ b/internal/controller/pipes/qq_napcat/qq.go @@ -95,6 +95,10 @@ func (q *QQController) handleNapcatEvent(raw []byte) { return } + if config.GetConfig().System.DebugMode && config.GetConfig().Debug.ShowNapcatMsg { + postLog.Debug("Napcat WS event received: " + string(raw)) + } + // Only handle message events; ignore notice/request/meta_event. if ev.PostType != "message" { return diff --git a/internal/controller/trigger.go b/internal/controller/trigger.go new file mode 100644 index 0000000..61dc5be --- /dev/null +++ b/internal/controller/trigger.go @@ -0,0 +1,57 @@ +package controller + +import ( + "strings" + + "nukumizu-backend/config" + "nukumizu-backend/postLog" +) + +// Trigger is a placeholder for triggering commands across all controllers. +func (m *Manager) Trigger (command string, args []string) { + if config.GetConfig().System.DebugMode { + postLog.Debug("Received command: " + command + " with args: " + strings.Join(args, ", ")) + } +} + +// ParseCommand parses a raw message text into a Command. +// Format: /{{command}} {{args...}} +func ParseCommand(rawText string) (cmd Command, ok bool) { + rawText = strings.TrimSpace(rawText) + if !strings.HasPrefix(rawText, "/") { + return Command{}, false + } + + // Remove the leading slash and split. + parts := strings.SplitN(rawText[1:], " ", 2) + cmd.Command = strings.ToLower(parts[0]) + cmd.RawText = rawText + + if len(parts) > 1 { + argStr := strings.TrimSpace(parts[1]) + + // Special handling for /run: first arg is uuid, rest is command. + if cmd.Command == "run" { + spaceIdx := strings.Index(argStr, " ") + if spaceIdx > 0 { + cmd.Args = []string{argStr[:spaceIdx], strings.TrimSpace(argStr[spaceIdx+1:])} + } else { + cmd.Args = []string{argStr} + } + } else { + cmd.Args = strings.Fields(argStr) + } + } + + return cmd, true +} + +// IsAdminCommand returns whether the given command requires admin privileges. +func IsAdminCommand(command string) bool { + switch command { + case "shutdown", "reboot", "run": + return true + default: + return false + } +}