Files

76 lines
1.8 KiB
Go
Raw Permalink Normal View History

2026-02-17 09:01:41 -08:00
package say
import (
"context"
"fmt"
"github.com/ollama/ollama/api"
"tipsy.codes/charles/mc-god/v2/internal/pkg/rcon"
)
type Say struct{}
func Get() *Say {
return &Say{}
}
func (s *Say) Do(ctx context.Context, toolCall api.ToolCall, client *rcon.Client) error {
// Extract the message from the tool call
message, found := toolCall.Function.Arguments.Get("message")
if !found {
return fmt.Errorf("missing message argument")
}
messageString, ok := message.(string)
if !ok {
return fmt.Errorf("incorrect data type %v; want string", message)
}
player, found := toolCall.Function.Arguments.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)
}
// Send the say command to the Minecraft server
command := fmt.Sprintf("/execute as %q run say %s", playerString, messageString)
_, err := client.Execute(command)
if err != nil {
return fmt.Errorf("failed to execute say command: %w", err)
}
return nil
}
func (s *Say) Desc() api.Tool {
toolPropertiesMap := api.NewToolPropertiesMap()
toolPropertiesMap.Set("message", api.ToolProperty{
Type: api.PropertyType{"string"},
Description: "The message to send to the server chat",
})
toolPropertiesMap.Set("player", api.ToolProperty{
Type: api.PropertyType{"string"},
Description: "The player to speak as",
})
return api.Tool{
Type: "function",
Function: api.ToolFunction{
Name: s.Name(),
Description: "Speak as a player, sending a message to the server chat as that player",
Parameters: api.ToolFunctionParameters{
Type: "object",
Properties: toolPropertiesMap,
Required: []string{"player", "message"},
},
},
}
}
func (s *Say) Name() string {
return "say"
}