diff options
author | David Phillips <david@yeah.nah.nz> | 2018-11-21 22:22:43 +1300 |
---|---|---|
committer | David Phillips <david@yeah.nah.nz> | 2018-11-21 22:22:43 +1300 |
commit | 47e5bdaa4017df0fdb3015b2da57c0a95c0a089b (patch) | |
tree | 9e475f2b0a6593ed80dc3fd26dba5528cfae4362 /Plugin | |
parent | bb7d8655e82c316f6f14b78ac3ec8a4198217d64 (diff) | |
download | idalius-47e5bdaa4017df0fdb3015b2da57c0a95c0a089b.tar.xz |
Men: add roll chance, support unicode and case
Diffstat (limited to 'Plugin')
-rw-r--r-- | Plugin/Men.pm | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Plugin/Men.pm b/Plugin/Men.pm index 38af3ea..7a53a71 100644 --- a/Plugin/Men.pm +++ b/Plugin/Men.pm @@ -2,6 +2,9 @@ package Plugin::Men; use strict; use warnings; +use Encode qw/decode/; + +use IdaliusConfig qw/assert_scalar/; my $config; my $root_config; @@ -10,24 +13,32 @@ sub configure { my $self = shift; shift; # cmdref shift; # run_command - shift; # module config + $config = shift; $root_config = shift; + IdaliusConfig::assert_scalar($config, $self, "chance"); + die "chance must be from 0 to 100" + unless $config->{chance} >= 0 && $config->{chance} <= 100; + return $self; } sub on_message { my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_; + return unless rand(100) < $config->{chance}; + if (ref($where) eq "ARRAY") { $where = $where->[0]; } - if ($what =~ /(\w*men\w*)/) { + $what = Encode::decode('utf8', $what); + + if ($what =~ /(\w*men\w*)/i) { my ($w, $c, $target); $w = $c = $target = $1; - $w =~ s/men/women/; - $c =~ s/men/children/; + $w =~ s/men/women/i; + $c =~ s/men/children/i; return "not just the $target, but the $w and $c too"; } return; |