72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"fergalla.com/dockerbot/internal/apperrors"
|
|
"github.com/go-telegram/bot"
|
|
)
|
|
|
|
func (appCtx *App) handleDockerAction(ctx context.Context, b *bot.Bot, chatID int64, action string, params []string) {
|
|
|
|
if len(params) == 0 {
|
|
appCtx.sendMessage(ctx, b, chatID,
|
|
appCtx.T("e.container.missing_name", map[string]string{"example": action}),
|
|
true,
|
|
nil,
|
|
)
|
|
return
|
|
}
|
|
|
|
container := params[0]
|
|
|
|
err := appCtx.dockerInfo.ContainerAction(container, action)
|
|
if err != nil {
|
|
appCtx.logger.Error(
|
|
"Failed to execute docker action",
|
|
"module", "Docker",
|
|
"action", action,
|
|
"container", container,
|
|
"error", err,
|
|
)
|
|
var msg string
|
|
if errors.Is(err, apperrors.ErrContainerNotFound) {
|
|
msg = appCtx.T("e.docker.connection")
|
|
} else {
|
|
msg = appCtx.T("e.container.action")
|
|
}
|
|
appCtx.sendMessage(ctx, b, chatID, msg, true, nil)
|
|
return
|
|
}
|
|
|
|
// 🔄 invalidar cache
|
|
appCtx.containerCache.Invalidate()
|
|
|
|
// 🎨 render vista actualizada
|
|
text, keyboard, err := appCtx.renderContainerDetail(ctx, container, 0)
|
|
if err != nil {
|
|
appCtx.logger.Error(
|
|
"Failed to render container detail after action",
|
|
"module", "Bot",
|
|
"container", container,
|
|
"error", err,
|
|
)
|
|
var msg string
|
|
if errors.Is(err, apperrors.ErrContainerNotFound) {
|
|
msg = appCtx.T("e.container.not_found")
|
|
} else {
|
|
msg = appCtx.T("e.container.info")
|
|
}
|
|
appCtx.sendMessage(ctx, b, chatID, msg, true, nil)
|
|
return
|
|
}
|
|
|
|
// ✅ feedback + vista
|
|
finalText := appCtx.T("a.container."+action, map[string]string{
|
|
"name": container,
|
|
}) + "\n\n" + text
|
|
|
|
appCtx.sendMessage(ctx, b, chatID, finalText, true, keyboard)
|
|
}
|