Total Lines | 24 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package cmd |
||
2 | |||
3 | import ( |
||
4 | "fmt" |
||
5 | "math/rand" |
||
6 | "strconv" |
||
7 | |||
8 | "github.com/FlameInTheDark/dtbot/bot" |
||
9 | ) |
||
10 | |||
11 | // DiceCommand handle dice |
||
12 | func DiceCommand(ctx bot.Context) { |
||
13 | ctx.MetricsCommand("dice", "main") |
||
14 | if len(ctx.Args) > 0 { |
||
15 | val, err := strconv.Atoi(ctx.Args[0]) |
||
16 | if err != nil { |
||
17 | return |
||
18 | } |
||
19 | if val <= 0 { |
||
20 | return |
||
21 | } |
||
22 | ctx.Reply(fmt.Sprintf("Dice: %v", rand.Intn(val)+1)) |
||
23 | } else { |
||
24 | ctx.Reply(fmt.Sprintf("Dice: %v", rand.Intn(6)+1)) |
||
25 | } |
||
27 |