aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-06-07 06:50:46 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-06-07 06:50:46 +0200
commit1be55051c1d93e8322ce4095e2c41d5c01019fab (patch)
treed6a0711db92b40998c0ea863e7bb954f768dab7f
parent96fa9e3cb8b893362e0b59065960ca5b56bfc1db (diff)
downloadIRC::Client::Plugin::DiceRolls-1be55051c1d93e8322ce4095e2c41d5c01019fab.tar.gz
IRC::Client::Plugin::DiceRolls-1be55051c1d93e8322ce4095e2c41d5c01019fab.tar.bz2
Add limits to the dice rolls
-rw-r--r--META6.json4
-rw-r--r--lib/IRC/Client/Plugin/DiceRolls.rakumod28
2 files changed, 24 insertions, 8 deletions
diff --git a/META6.json b/META6.json
index bece291..b868f72 100644
--- a/META6.json
+++ b/META6.json
@@ -6,7 +6,7 @@
],
"depends": [
"Config",
- "Grammar::DiceRolls",
+ "Grammar::DiceRolls:ver<0.3.0>",
"IRC::Client"
],
"description": "A plugin for IRC::Client to do D&D-style dice rolls",
@@ -18,4 +18,4 @@
},
"source-url": "https://home.tyil.nl/git/raku/IRC::Client::Plugin::DiceRolls/",
"version": "0.1.0"
-} \ No newline at end of file
+}
diff --git a/lib/IRC/Client/Plugin/DiceRolls.rakumod b/lib/IRC/Client/Plugin/DiceRolls.rakumod
index 46ba6be..4bb83ac 100644
--- a/lib/IRC/Client/Plugin/DiceRolls.rakumod
+++ b/lib/IRC/Client/Plugin/DiceRolls.rakumod
@@ -7,6 +7,8 @@ use Grammar::DiceRolls;
use Grammar::DiceRolls::CountActions;
use Grammar::DiceRolls::ListActions;
use IRC::Client;
+use X::Grammar::DiceRolls::TooManyDice;
+use X::Grammar::DiceRolls::TooManySides;
unit class IRC::Client::Plugin::DiceRolls does IRC::Client::Plugin;
@@ -37,17 +39,21 @@ multi method irc-privmsg (
) {
my $roll = $event.text.substr($!prefix.chars).trim || '1d20';
+ .debug("Rolling for $roll") with $*LOG;
+
given ($!config.get('irc.plugins.dicerolls.style', 'list').fc) {
when 'list' {
my @outcomes = Grammar::DiceRolls.parse(
$roll,
- :actions(Grammar::DiceRolls::ListActions)
+ :actions(Grammar::DiceRolls::ListActions.new(
+ limit-dice => $!config.get('irc.plugins.dicerolls.limit-dice', 30),
+ limit-sides => $!config.get('irc.plugins.dicerolls.limit-sides', 1_000_000_000),
+ ))
).made;
return "Invalid roll ($roll)" unless @outcomes;
return "$roll = {@outcomes.first}" if @outcomes.elems < 2;
-
- "$roll = {@outcomes.join(' + ')} = {@outcomes.sum}";
+ return "$roll = {@outcomes.join(' + ')} = {@outcomes.sum}";
}
when 'count' {
my $outcome = Grammar::DiceRolls.parse(
@@ -56,11 +62,21 @@ multi method irc-privmsg (
).made;
return "Invalid roll ($roll)" unless $outcome;
-
- "$roll = $outcome";
+ return "$roll = $outcome";
}
default {
- .alert("Invalid rolling style for irc.plugins.dicerolls.style ($_)") with $*LOG;
+ .alert('Invalid rolling style for irc.plugins.dicerolls.style') with $*LOG;
+ }
+ }
+
+ CATCH {
+ when X::Grammar::DiceRolls::TooManyDice {
+ .error("Too many dice in $roll") with $*LOG;
+ return 'No dice';
+ }
+ when X::Grammar::DiceRolls::TooManySides {
+ .error("Too many sides in $roll") with $*LOG;
+ return 'No dice';
}
}
}