cmd/dicecommand.go   A
last analyzed

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 17
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A cmd.DiceCommand 0 13 4
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
	}
26
}
27