Limit dice size and number of rolls.

master
Robert Gerus 2015-12-11 07:42:42 +01:00
parent fe569360ae
commit 759edd3c5c
2 changed files with 22 additions and 0 deletions

View File

@ -427,6 +427,24 @@ var eventTests = []struct {
},
},
},
{
desc: "roll 1000000",
in: irc.Message{
Command: "PRIVMSG",
Trailing: ":roll 2000000",
Params: []string{"#testchan-1"},
Prefix: &irc.Prefix{
Name: "idontexist",
},
},
expectedOut: []irc.Message{
{
Command: "PRIVMSG",
Params: []string{"#testchan-1"},
Trailing: "Number of rolls and dice size is limited to 1000000",
},
},
},
{
desc: "roll 0",
in: irc.Message{

View File

@ -42,6 +42,10 @@ func roll(output func(irc.Message), msg irc.Message) {
output(reply(msg, "Usage: :roll <sides int> <rolls int>, each roll is [0, n)+1, size has to be >0"))
return
}
if sides > 1000000 || rolls > 1000000 {
output(reply(msg, "Number of rolls and dice size is limited to 1000000"))
return
}
sum := rolls
for i := 0; i < rolls; i++ {