aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2018-11-16 00:25:57 +1300
committerDavid Phillips <david@yeah.nah.nz>2018-11-16 00:25:57 +1300
commitef496bbdb26f6e981c7ab76237725ea6760dd05d (patch)
tree0e9e6e4c4d4492848dcd88ba76ba76843fe3814d
parentfb14ff03139a580a903aab4fa9b427b59475f4f5 (diff)
downloadidalius-ef496bbdb26f6e981c7ab76237725ea6760dd05d.tar.xz
Greet: add chance
-rw-r--r--Plugin/Greet.pm23
1 files changed, 20 insertions, 3 deletions
diff --git a/Plugin/Greet.pm b/Plugin/Greet.pm
index d291682..9933104 100644
--- a/Plugin/Greet.pm
+++ b/Plugin/Greet.pm
@@ -1,24 +1,39 @@
package Plugin::Greet;
# FIXME add configurable messages
-# FIXME add configurable chance of replying
-# FIXME factor out `some` with other plugins
use strict;
use warnings;
+my $config;
my $root_config;
sub configure {
my $self = shift;
shift; # cmdref
shift; # run_command
- shift; # module config
+ $config = shift;
$root_config = shift;
+ IdaliusConfig::assert_scalar($config, $self, "chance_self");
+ IdaliusConfig::assert_scalar($config, $self, "chance_other");
+ die "chance_self must be from 0 to 100"
+ if ($config->{chance_self} < 0 || $config->{chance_self} > 100);
+ die "chance_other must be from 0 to 100"
+ if ($config->{chance_other} < 0 || $config->{chance_other} > 100);
+
return $self;
}
+sub self_odds {
+ return int(rand(100)) < $config->{chance_self};
+}
+
+sub other_odds {
+ return int(rand(100)) < $config->{chance_other};
+}
+
+# FIXME factor out `some` with other plugins
sub some {
my @choices = @_;
return $choices[rand(@choices)];
@@ -42,8 +57,10 @@ sub on_join {
my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
my $nick = (split /!/, $who)[0];
if ($nick eq $root_config->{current_nick}) {
+ return unless self_odds();
return some @own_responses;
} else {
+ return unless other_odds();
return some(
"hi $nick",
"oh look, $nick is here",