roll

package
v1.31.22 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 6 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: "Sides", Default: 0, Type: dcmd.Int},
		{Name: "RPG-Dice", Type: dcmd.String},
	},
	ArgumentCombos:      [][]int{{0}, {1}, {}},
	DefaultEnabled:      true,
	SlashCommandEnabled: true,
	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		if data.Args[1].Value != nil {

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

			output := r.String()
			if len(output) > 100 {
				output = output[:100] + "..."
			} else {
				output = strings.TrimSuffix(output, "([])")
			}

			return ":game_die: " + output, nil
		}

		sides := data.Args[0].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