Files
mc-god/internal/pkg/tools/teleport/teleport.go
2026-02-17 09:01:41 -08:00

83 lines
2.0 KiB
Go

package teleport
import (
"context"
"fmt"
"strings"
"github.com/ollama/ollama/api"
"tipsy.codes/charles/mc-god/v2/internal/pkg/rcon"
)
type Teleport struct{}
func Get() *Teleport {
return &Teleport{}
}
func (t *Teleport) Do(ctx context.Context, toolCall api.ToolCall, client *rcon.Client) error {
// Extract the arguments from the tool call
args := toolCall.Function.Arguments
source, found := args.Get("source")
if !found {
return fmt.Errorf("missing source argument")
}
sourceString, ok := source.(string)
if !ok {
return fmt.Errorf("incorrect data type %v; want string", source)
}
target, found := args.Get("target")
if !found {
return fmt.Errorf("missing target argument")
}
targetString, ok := target.(string)
if !ok {
return fmt.Errorf("incorrect data type %v; want string", target)
}
// Validate that we have valid player names (basic validation)
if strings.TrimSpace(sourceString) == "" || strings.TrimSpace(targetString) == "" {
return fmt.Errorf("source and target player names cannot be empty")
}
// Send the teleport command to the Minecraft server
command := "/tp " + sourceString + " " + targetString
_, err := client.Execute(command)
if err != nil {
return fmt.Errorf("failed to execute teleport command: %w", err)
}
return nil
}
func (t *Teleport) Desc() api.Tool {
toolPropertiesMap := api.NewToolPropertiesMap()
toolPropertiesMap.Set("source", api.ToolProperty{
Type: api.PropertyType{"string"},
Description: "The player who will be teleported",
})
toolPropertiesMap.Set("target", api.ToolProperty{
Type: api.PropertyType{"string"},
Description: "The player to teleport to",
})
return api.Tool{
Type: "function",
Function: api.ToolFunction{
Name: t.Name(),
Description: "Teleport one player to another player in Minecraft",
Parameters: api.ToolFunctionParameters{
Type: "object",
Properties: toolPropertiesMap,
Required: []string{"source", "target"},
},
},
}
}
func (t *Teleport) Name() string {
return "teleport"
}