Make roll act more like a real dice.
parent
dee7a7cd73
commit
288e0d6857
|
@ -351,7 +351,7 @@ var eventTests = []struct {
|
|||
{
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{"#testchan-1"},
|
||||
Trailing: "0",
|
||||
Trailing: "3",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -369,7 +369,7 @@ var eventTests = []struct {
|
|||
{
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{"#testchan-1"},
|
||||
Trailing: "0",
|
||||
Trailing: "1",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -387,7 +387,7 @@ var eventTests = []struct {
|
|||
{
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{"#testchan-1"},
|
||||
Trailing: "Usage: :roll <sides int> <rolls int>, each roll is [0, n), size has to be >0",
|
||||
Trailing: "Usage: :roll <sides int> <rolls int>, each roll is [0, n)+1, size has to be >0",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -405,7 +405,7 @@ var eventTests = []struct {
|
|||
{
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{"#testchan-1"},
|
||||
Trailing: "Usage: :roll <sides int> <rolls int>, each roll is [0, n), size has to be >0",
|
||||
Trailing: "Usage: :roll <sides int> <rolls int>, each roll is [0, n)+1, size has to be >0",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
12
bot/roll.go
12
bot/roll.go
|
@ -23,27 +23,27 @@ func roll(output func(irc.Message), msg irc.Message) {
|
|||
rolls := 1
|
||||
|
||||
if len(args) == 3 {
|
||||
rolls, err = strconv.Atoi(args[1])
|
||||
rolls, err = strconv.Atoi(args[2])
|
||||
if err != nil || rolls < 1 {
|
||||
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n), size has to be >0"))
|
||||
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n)+1, size has to be >0"))
|
||||
return
|
||||
}
|
||||
} else if len(args) != 2 {
|
||||
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n), size has to be >0"))
|
||||
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n)+1, size has to be >0"))
|
||||
return
|
||||
}
|
||||
|
||||
sides, err := strconv.Atoi(args[1])
|
||||
if err != nil {
|
||||
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n), size has to be >0"))
|
||||
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n)+1, size has to be >0"))
|
||||
return
|
||||
}
|
||||
if sides <= 0 {
|
||||
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n), size has to be >0"))
|
||||
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n)+1, size has to be >0"))
|
||||
return
|
||||
}
|
||||
|
||||
sum := 0
|
||||
sum := rolls
|
||||
for i := 0; i < rolls; i++ {
|
||||
sum += rand.Intn(sides)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue