Files
yutu/cmd/liveChatMessage/delete.go
T

89 lines
2.5 KiB
Go

// Copyright 2026 eat-pray-ai & OpenWaygate
// SPDX-License-Identifier: Apache-2.0
package liveChatMessage
import (
"fmt"
"io"
"strings"
cobramcp "github.com/eat-pray-ai/cobra-mcp"
"github.com/eat-pray-ai/yutu/cmd"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/liveChatMessage"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/spf13/cobra"
)
const (
deleteTool = "liveChatMessage-delete"
deleteConfirm = "Delete live chat message(s): %s"
deleteIdsUsage = "IDs of the live chat messages to delete"
deleteShort = "Delete live chat messages"
deleteLong = "Delete live chat messages. Use this tool to remove messages from a live chat by their IDs."
deleteExample = `# Delete a live chat message by ID
yutu liveChatMessage delete --ids abc123
# Delete multiple live chat messages
yutu liveChatMessage delete --ids abc123,def456`
)
var deleteInSchema = &jsonschema.Schema{
Type: "object",
Required: []string{"ids"},
Properties: map[string]*jsonschema.Schema{
"ids": {
Type: "array", Description: deleteIdsUsage,
Items: &jsonschema.Schema{Type: "string"},
},
},
}
func init() {
mcp.AddTool(
cmd.Server, &mcp.Tool{
Name: deleteTool, Title: deleteShort, Description: deleteLong,
InputSchema: deleteInSchema, Annotations: &mcp.ToolAnnotations{
DestructiveHint: new(true),
IdempotentHint: true,
OpenWorldHint: new(true),
ReadOnlyHint: false,
},
}, cobramcp.GenToolHandlerWithMRTR(
deleteTool, cobramcp.ConfirmThen(
func(input liveChatMessage.LiveChatMessage) string {
return fmt.Sprintf(deleteConfirm, strings.Join(input.Ids, ", "))
},
func(input liveChatMessage.LiveChatMessage, w io.Writer) error {
return input.Delete(w)
},
),
),
)
liveChatMessageCmd.AddCommand(deleteCmd)
deleteCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, deleteIdsUsage)
deleteCmd.Flags().Bool("yes", false, pkg.ConfirmedUsage)
_ = deleteCmd.MarkFlagRequired("ids")
}
var deleteCmd = &cobra.Command{
Use: "delete",
Short: deleteShort,
Long: deleteLong,
Example: deleteExample,
PreRunE: func(c *cobra.Command, _ []string) error {
return utils.ConfirmPreRun(
c, fmt.Sprintf(deleteConfirm, strings.Join(ids, ", ")),
)
},
Run: func(c *cobra.Command, _ []string) {
input := liveChatMessage.NewLiveChatMessage(
liveChatMessage.WithIds(ids),
)
utils.HandleCmdError(input.Delete(c.OutOrStdout()), c)
},
}