Files
yutu/cmd/comment/markAsSpam.go
T
2026-03-25 22:41:13 +08:00

82 lines
2.1 KiB
Go

// Copyright 2025 eat-pray-ai & OpenWaygate
// SPDX-License-Identifier: Apache-2.0
package comment
import (
"encoding/json"
"io"
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/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 comments as spam"
masLong = "Mark comments as spam. Use this tool to mark comments as spam."
masExample = `# Mark a comment as spam
yutu comment markAsSpam --ids abc123
# Mark multiple comments as spam
yutu comment markAsSpam --ids abc123,def456`
)
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"`),
},
},
}
func init() {
mcp.AddTool(
cmd.Server, &mcp.Tool{
Name: masTool, Title: masShort, Description: masLong,
InputSchema: markAsSpamInSchema, Annotations: &mcp.ToolAnnotations{
DestructiveHint: new(false),
IdempotentHint: false,
OpenWorldHint: new(true),
ReadOnlyHint: false,
},
}, cobramcp.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.MarkFlagRequired("ids")
}
var markAsSpamCmd = &cobra.Command{
Use: "markAsSpam",
Short: masShort,
Long: masLong,
Example: masExample,
Run: func(cmd *cobra.Command, args []string) {
input := comment.NewComment(
comment.WithIds(ids),
comment.WithOutput(output),
)
utils.HandleCmdError(input.MarkAsSpam(cmd.OutOrStdout()), cmd)
},
}