package give import ( "context" "fmt" "strings" "github.com/ollama/ollama/api" "tipsy.codes/charles/mc-god/v2/internal/pkg/rcon" ) type Give struct{} func Get() *Give { return &Give{} } func (g *Give) Do(ctx context.Context, toolCall api.ToolCall, client *rcon.Client) error { // Extract the arguments from the tool call args := toolCall.Function.Arguments player, found := args.Get("player") if !found { return fmt.Errorf("missing player argument") } playerString, ok := player.(string) if !ok { return fmt.Errorf("incorrect data type %v; want string", player) } item, found := args.Get("item") if !found { return fmt.Errorf("missing item argument") } itemString, ok := item.(string) if !ok { return fmt.Errorf("incorrect data type %T; want int", item) } // Handle count (optional, default to 1) count := 1 countVal, found := args.Get("count") if found { if countFloat, ok := countVal.(float64); ok { count = int(countFloat) } else { return fmt.Errorf("incorrect data type %T; want number", countVal) } } // Validate that we have valid player and item names (basic validation) if strings.TrimSpace(playerString) == "" { return fmt.Errorf("player and item names cannot be empty") } // Send the give command to the Minecraft server command := "/give " + playerString + " " + itemString + " " + fmt.Sprintf("%d", count) _, err := client.Execute(command) if err != nil { return fmt.Errorf("failed to execute give command: %w", err) } return nil } func (g *Give) Desc() api.Tool { toolPropertiesMap := api.NewToolPropertiesMap() toolPropertiesMap.Set("player", api.ToolProperty{ Type: api.PropertyType{"string"}, Description: "The player to give the item to", }) toolPropertiesMap.Set("item", api.ToolProperty{ Type: api.PropertyType{"string"}, Description: `The item to give. Items can include: - dirt - carrot - reeds `, }) toolPropertiesMap.Set("count", api.ToolProperty{ Type: api.PropertyType{"integer"}, Description: "The number of items to give (default is 1)", }) return api.Tool{ Type: "function", Function: api.ToolFunction{ Name: g.Name(), Description: "Give items to a player in Minecraft", Parameters: api.ToolFunctionParameters{ Type: "object", Properties: toolPropertiesMap, Required: []string{"player", "item"}, }, }, } } func (g *Give) Name() string { return "give" }