-
Notifications
You must be signed in to change notification settings - Fork 926
/
roll.go
41 lines (36 loc) · 1.01 KB
/
roll.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package roll
import (
"fmt"
"math/rand"
"github.com/jonas747/dcmd"
"github.com/jonas747/dice"
"github.com/jonas747/yagpdb/commands"
)
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 {
// Special dice syntax if string
r, _, err := dice.Roll(data.Args[0].Str())
if err != nil {
return err.Error(), nil
}
return r.String(), nil
}
// normal, n sides dice rolling
sides := data.Args[1].Int()
if sides < 1 {
sides = 6
}
result := rand.Intn(sides)
return fmt.Sprintf(":game_die: %d (1 - %d)", result+1, sides), nil
},
}