// Copyright 2025 eat-pray-ai & OpenWaygate
// SPDX-License-Identifier: Apache-2.0
package comment
import (
"encoding/json"
"io"
"github.com/eat-pray-ai/yutu/cmd"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/comment"
"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 (
masTool = "comment-markAsSpam"
masShort = "Mark YouTube comments as spam"
masLong = "Mark YouTube comments as spam by ids"
)
var markAsSpamInSchema = &jsonschema.Schema{
Type: "object",
Required: []string{"ids"},
Properties: map[string]*jsonschema.Schema{
"ids": {
Type: "array", Description: idsUsage,
Items: &jsonschema.Schema{Type: "string"},
},
"output": {
Type: "string", Enum: []any{"json", "yaml", "silent", ""},
Description: pkg.SilentUsage, Default: json.RawMessage(`"yaml"`),
},
"jsonpath": {Type: "string", Description: pkg.JPUsage},
},
}
func init() {
mcp.AddTool(
cmd.Server, &mcp.Tool{
Name: masTool, Title: masShort, Description: masLong,
InputSchema: markAsSpamInSchema, Annotations: &mcp.ToolAnnotations{
DestructiveHint: jsonschema.Ptr(false),
IdempotentHint: false,
OpenWorldHint: jsonschema.Ptr(true),
ReadOnlyHint: false,
},
}, cmd.GenToolHandler(
masTool, func(input comment.Comment, writer io.Writer) error {
return input.MarkAsSpam(writer)
},
),
)
commentCmd.AddCommand(markAsSpamCmd)
markAsSpamCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, idsUsage)
markAsSpamCmd.Flags().StringVarP(&output, "output", "o", "", pkg.SilentUsage)
markAsSpamCmd.Flags().StringVarP(&jsonpath, "jsonpath", "j", "", pkg.JPUsage)
_ = markAsSpamCmd.MarkFlagRequired("ids")
}
var markAsSpamCmd = &cobra.Command{
Use: "markAsSpam",
Short: masShort,
Long: masLong,
Run: func(cmd *cobra.Command, args []string) {
input := comment.NewComment(
comment.WithIds(ids),
comment.WithOutput(output),
comment.WithJsonpath(jsonpath),
)
utils.HandleCmdError(input.MarkAsSpam(cmd.OutOrStdout()), cmd)
},
}