style(controller): re-organize controller project structure: split controller and pipes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package controller
|
||||
package pipes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package controller
|
||||
package pipes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package controller
|
||||
package pipes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"nukumizu-backend/internal/node"
|
||||
"nukumizu-backend/internal/template"
|
||||
"nukumizu-backend/postLog"
|
||||
"nukumizu-backend/internal/controller"
|
||||
)
|
||||
|
||||
// QQController handles QQ Bot interactions via napcat-bridge.
|
||||
@@ -57,8 +58,8 @@ func (q *QQController) IsEnabled() bool {
|
||||
}
|
||||
|
||||
// HandleCommand processes a bot command and returns a response string.
|
||||
func (q *QQController) HandleCommand(cmd Command) (string, error) {
|
||||
parsed, ok := ParseCommand(cmd.RawText)
|
||||
func (q *QQController) HandleCommand(cmd controller.Command) (string, error) {
|
||||
parsed, ok := controller.ParseCommand(cmd.RawText)
|
||||
if !ok {
|
||||
// Not a command. In "global" mode, silently ignore.
|
||||
// In "at" mode, this would be an error - but at detection happens at the message level.
|
||||
@@ -81,7 +82,7 @@ func (q *QQController) HandleCommand(cmd Command) (string, error) {
|
||||
return q.executeCommand(parsed)
|
||||
}
|
||||
|
||||
func (q *QQController) executeCommand(cmd Command) (string, error) {
|
||||
func (q *QQController) executeCommand(cmd controller.Command) (string, error) {
|
||||
// Validate against supported commands.
|
||||
switch cmd.Command {
|
||||
case "list":
|
||||
@@ -118,7 +119,7 @@ func (q *QQController) handleList() (string, error) {
|
||||
return template.Render(cfg.ControllerMessage.ServerList, params), nil
|
||||
}
|
||||
|
||||
func (q *QQController) handleStatus(cmd Command) (string, error) {
|
||||
func (q *QQController) handleStatus(cmd controller.Command) (string, error) {
|
||||
if len(cmd.Args) < 1 {
|
||||
return "Usage: /status <uuid>", nil
|
||||
}
|
||||
@@ -154,7 +155,7 @@ func (q *QQController) handleStatus(cmd Command) (string, error) {
|
||||
return sb.String(), nil
|
||||
}
|
||||
|
||||
func (q *QQController) handleShutdown(cmd Command) (string, error) {
|
||||
func (q *QQController) handleShutdown(cmd controller.Command) (string, error) {
|
||||
if !q.isAdmin(cmd.SenderID) {
|
||||
return "Permission denied: admin only", nil
|
||||
}
|
||||
@@ -176,7 +177,7 @@ func (q *QQController) handleShutdown(cmd Command) (string, error) {
|
||||
return fmt.Sprintf("Shutdown command sent to server %s", uuid), nil
|
||||
}
|
||||
|
||||
func (q *QQController) handleReboot(cmd Command) (string, error) {
|
||||
func (q *QQController) handleReboot(cmd controller.Command) (string, error) {
|
||||
if !q.isAdmin(cmd.SenderID) {
|
||||
return "Permission denied: admin only", nil
|
||||
}
|
||||
@@ -198,7 +199,7 @@ func (q *QQController) handleReboot(cmd Command) (string, error) {
|
||||
return fmt.Sprintf("Reboot command sent to server %s", uuid), nil
|
||||
}
|
||||
|
||||
func (q *QQController) handleRun(cmd Command) (string, error) {
|
||||
func (q *QQController) handleRun(cmd controller.Command) (string, error) {
|
||||
if !q.isAdmin(cmd.SenderID) {
|
||||
return "Permission denied: admin only", nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package controller
|
||||
package pipes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"nukumizu-backend/internal/node"
|
||||
"nukumizu-backend/internal/template"
|
||||
"nukumizu-backend/postLog"
|
||||
"nukumizu-backend/internal/controller"
|
||||
)
|
||||
|
||||
// TelegramController handles Telegram Bot interactions via long polling.
|
||||
@@ -70,8 +71,8 @@ func (t *TelegramController) pollLoop() {
|
||||
}
|
||||
|
||||
// HandleCommand processes a bot command and returns a response string.
|
||||
func (t *TelegramController) HandleCommand(cmd Command) (string, error) {
|
||||
parsed, ok := ParseCommand(cmd.RawText)
|
||||
func (t *TelegramController) HandleCommand(cmd controller.Command) (string, error) {
|
||||
parsed, ok := controller.ParseCommand(cmd.RawText)
|
||||
if !ok {
|
||||
if t.cfg.ListenMethod == "at" {
|
||||
return "Unknown command format. Use /command args", nil
|
||||
@@ -86,7 +87,7 @@ func (t *TelegramController) HandleCommand(cmd Command) (string, error) {
|
||||
return t.executeCommand(parsed)
|
||||
}
|
||||
|
||||
func (t *TelegramController) executeCommand(cmd Command) (string, error) {
|
||||
func (t *TelegramController) executeCommand(cmd controller.Command) (string, error) {
|
||||
switch cmd.Command {
|
||||
case "list":
|
||||
return t.handleList()
|
||||
@@ -122,7 +123,7 @@ func (t *TelegramController) handleList() (string, error) {
|
||||
return template.Render(cfg.ControllerMessage.ServerList, params), nil
|
||||
}
|
||||
|
||||
func (t *TelegramController) handleStatus(cmd Command) (string, error) {
|
||||
func (t *TelegramController) handleStatus(cmd controller.Command) (string, error) {
|
||||
if len(cmd.Args) < 1 {
|
||||
return "Usage: /status <uuid>", nil
|
||||
}
|
||||
@@ -155,7 +156,7 @@ func (t *TelegramController) handleStatus(cmd Command) (string, error) {
|
||||
return sb.String(), nil
|
||||
}
|
||||
|
||||
func (t *TelegramController) handleShutdown(cmd Command) (string, error) {
|
||||
func (t *TelegramController) handleShutdown(cmd controller.Command) (string, error) {
|
||||
if !t.isAdmin(cmd.SenderID) {
|
||||
return "Permission denied: admin only", nil
|
||||
}
|
||||
@@ -177,7 +178,7 @@ func (t *TelegramController) handleShutdown(cmd Command) (string, error) {
|
||||
return fmt.Sprintf("Shutdown command sent to server %s", uuid), nil
|
||||
}
|
||||
|
||||
func (t *TelegramController) handleReboot(cmd Command) (string, error) {
|
||||
func (t *TelegramController) handleReboot(cmd controller.Command) (string, error) {
|
||||
if !t.isAdmin(cmd.SenderID) {
|
||||
return "Permission denied: admin only", nil
|
||||
}
|
||||
@@ -199,7 +200,7 @@ func (t *TelegramController) handleReboot(cmd Command) (string, error) {
|
||||
return fmt.Sprintf("Reboot command sent to server %s", uuid), nil
|
||||
}
|
||||
|
||||
func (t *TelegramController) handleRun(cmd Command) (string, error) {
|
||||
func (t *TelegramController) handleRun(cmd controller.Command) (string, error) {
|
||||
if !t.isAdmin(cmd.SenderID) {
|
||||
return "Permission denied: admin only", nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package controller
|
||||
package pipes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"nukumizu-backend/config"
|
||||
"nukumizu-backend/database"
|
||||
"nukumizu-backend/internal/controller"
|
||||
"nukumizu-backend/internal/controller/pipes"
|
||||
"nukumizu-backend/internal/komari"
|
||||
"nukumizu-backend/internal/node"
|
||||
"nukumizu-backend/postLog"
|
||||
@@ -158,7 +159,7 @@ func initControllers() {
|
||||
}
|
||||
|
||||
// QQ (Napcat) controller.
|
||||
qqCtrl := controller.NewQQController(cfg.ControllerMethod.QQ)
|
||||
qqCtrl := pipes.NewQQController(cfg.ControllerMethod.QQ)
|
||||
mgr.Register(qqCtrl)
|
||||
go func() {
|
||||
defer func() {
|
||||
@@ -172,7 +173,7 @@ func initControllers() {
|
||||
}()
|
||||
|
||||
// Telegram controller.
|
||||
tgCtrl := controller.NewTelegramController(cfg.ControllerMethod.Telegram)
|
||||
tgCtrl := pipes.NewTelegramController(cfg.ControllerMethod.Telegram)
|
||||
mgr.Register(tgCtrl)
|
||||
go func() {
|
||||
defer func() {
|
||||
@@ -186,7 +187,7 @@ func initControllers() {
|
||||
}()
|
||||
|
||||
// Email controller (status-only).
|
||||
emailCtrl := controller.NewEmailController(cfg.ControllerMethod.Email)
|
||||
emailCtrl := pipes.NewEmailController(cfg.ControllerMethod.Email)
|
||||
mgr.Register(emailCtrl)
|
||||
go func() {
|
||||
defer func() {
|
||||
@@ -200,7 +201,7 @@ func initControllers() {
|
||||
}()
|
||||
|
||||
// Ntfy controller (status-only).
|
||||
ntfyCtrl := controller.NewNtfyController(cfg.ControllerMethod.Ntfy)
|
||||
ntfyCtrl := pipes.NewNtfyController(cfg.ControllerMethod.Ntfy)
|
||||
mgr.Register(ntfyCtrl)
|
||||
go func() {
|
||||
defer func() {
|
||||
@@ -214,7 +215,7 @@ func initControllers() {
|
||||
}()
|
||||
|
||||
// Webhook controller (status-only).
|
||||
webhookCtrl := controller.NewWebhookController(cfg.ControllerMethod.Webhook)
|
||||
webhookCtrl := pipes.NewWebhookController(cfg.ControllerMethod.Webhook)
|
||||
mgr.Register(webhookCtrl)
|
||||
go func() {
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user