summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Gerus <rgerus@dpd.com.pl>2015-12-11 07:42:42 +0100
committerRobert Gerus <rgerus@dpd.com.pl>2015-12-11 07:42:42 +0100
commit759edd3c5c44df69cfe0d0bfb1dc16a2ef6c2c4b (patch)
treee0114986a680b05f7b07c10051f5e7d86290cdd3
parentfe569360ae2c74ac7032c26784b6d989c06901ff (diff)
downloadgorepost-759edd3c5c44df69cfe0d0bfb1dc16a2ef6c2c4b.tar.gz
gorepost-759edd3c5c44df69cfe0d0bfb1dc16a2ef6c2c4b.tar.bz2
gorepost-759edd3c5c44df69cfe0d0bfb1dc16a2ef6c2c4b.tar.xz
gorepost-759edd3c5c44df69cfe0d0bfb1dc16a2ef6c2c4b.zip
Limit dice size and number of rolls.
-rw-r--r--bot/plugins_test.go18
-rw-r--r--bot/roll.go4
2 files changed, 22 insertions, 0 deletions
diff --git a/bot/plugins_test.go b/bot/plugins_test.go
index 850e0b0..650013b 100644
--- a/bot/plugins_test.go
+++ b/bot/plugins_test.go
@@ -428,6 +428,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{
Command: "PRIVMSG",
diff --git a/bot/roll.go b/bot/roll.go
index efd6f18..fe1058a 100644
--- a/bot/roll.go
+++ b/bot/roll.go
@@ -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++ {