Make roll act more like a real dice.

master
Robert Gerus 2015-12-10 22:59:23 +01:00
parent dee7a7cd73
commit 288e0d6857
2 changed files with 10 additions and 10 deletions

View File

@ -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",
},
},
},

View File

@ -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)
}