Skip to content

Commit

Permalink
chore: dice rolling tool (#473)
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Price <[email protected]>
  • Loading branch information
drpebcak authored Mar 6, 2025
1 parent 42ba60b commit cebcaa9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions die-roller/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/obot-platform/tools/die-roller

go 1.24.0

require github.com/travis-g/dice v0.0.0-20240426015834-4e95258df453

require github.com/pkg/errors v0.9.1 // indirect
4 changes: 4 additions & 0 deletions die-roller/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/travis-g/dice v0.0.0-20240426015834-4e95258df453 h1:qAtlSxGsluspg9Y4ORagsMVwgi5TqBJWphHV5UdvBCM=
github.com/travis-g/dice v0.0.0-20240426015834-4e95258df453/go.mod h1:+lVHixBi/3xTQTclocBAhiroWtnpPkWNLnMe5sJnCkY=
50 changes: 50 additions & 0 deletions die-roller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"context"
"fmt"
"github.com/travis-g/dice"
"log"
"os"
"strconv"
)

func main() {
if len(os.Args) < 2 {
log.Fatal("usage: roll-dice <command>")
}
ctx := context.Background()

command := os.Args[1]

numDice, err := strconv.Atoi(os.Getenv("NUM_DICE"))
if err != nil {
log.Fatal("num_dice was not set to a number")
}

numSides, err := strconv.Atoi(os.Getenv("NUM_SIDES"))
if err != nil {
log.Fatal("num_sides was not set to a number")
}

switch command {
case "rollDice":
group, err := dice.NewRollerGroup(
&dice.RollerProperties{
Size: numSides,
Count: numDice,
})
if err != nil {
log.Fatal(err)
}
err = group.FullRoll(ctx)
if err != nil {
log.Fatal(err)
}
result, err := group.Total(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%dd%d rolled, result: %d\n", numDice, numSides, int(result))
}
}
13 changes: 13 additions & 0 deletions die-roller/tool.gpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
Name: Die Roller
Description: Tool to roll dice and return the result
Metadata: bundle: true
Share Tools: Roll Dice

---
Name: Roll Dice
Description: Roll n-number of dice with n-sides. The user might use notation like `{number of dice}d{number of sides per die}` - ex 1d6, 2d20, etc.
Param: num_dice: The number of dice to roll
Param: num_sides: The number of sides each die should have

#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool rollDice

0 comments on commit cebcaa9

Please sign in to comment.