-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Taylor Price <[email protected]>
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |