roll

package
v1.24.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	CmdCategory:     commands.CategoryFun,
	Name:            "Roll",
	Description:     "Roll dices, specify nothing for 6 sides, specify a number for max sides, or rpg dice syntax.",
	LongDescription: "Example: `-roll 2d6`",
	Arguments: []*dcmd.ArgDef{
		{Name: "RPG Dice", Type: dcmd.String},
		{Name: "Sides", Default: 0, Type: dcmd.Int},
	},
	ArgumentCombos: [][]int{[]int{1}, []int{0}, []int{}},
	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		if data.Args[0].Value != nil {

			r, _, err := dice.Roll(data.Args[0].Str())
			if err != nil {
				return err.Error(), nil
			}

			output := r.String()
			if len(output) > 100 {
				output = output[:100] + "..."
			}
			return output, nil
		}

		sides := data.Args[1].Int()
		if sides < 1 {
			sides = 6
		}

		result := rand.Intn(sides)
		output := fmt.Sprintf(":game_die: %d (1 - %d)", result+1, sides)
		return output, nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL