feat(internal/controller): split trigger from controller.go as a seperate module.
feat(internal/controller/pipes/qq_napcat): add message receive debug output.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user