Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: dice rolling tool #473

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading