aboutsummaryrefslogtreecommitdiff
path: root/Plugin
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2019-06-23 17:21:28 +1200
committerDavid Phillips <david@sighup.nz>2019-06-23 17:21:28 +1200
commit688f221efc904526cbd099f53fe2ce6cc76e50ff (patch)
treef31d4bed7507ce2f02b23e48992438b94c1be57a /Plugin
parentd681b6ceba2fa4d9d7c7182dc990f754cc7c4cf0 (diff)
downloadidalius-688f221efc904526cbd099f53fe2ce6cc76e50ff.tar.xz
Add Dad plugin for dadjokes
Diffstat (limited to 'Plugin')
-rw-r--r--Plugin/Dad.pm43
1 files changed, 43 insertions, 0 deletions
diff --git a/Plugin/Dad.pm b/Plugin/Dad.pm
new file mode 100644
index 0000000..096017f
--- /dev/null
+++ b/Plugin/Dad.pm
@@ -0,0 +1,43 @@
+package Plugin::Dad;
+
+use strict;
+use warnings;
+use Encode qw/decode/;
+
+use IdaliusConfig qw/assert_scalar/;
+
+my $config;
+my $root_config;
+
+sub configure {
+ my $self = shift;
+ shift; # cmdref
+ shift; # run_command
+ $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, $who, $where, $raw_what, $what, $irc) = @_;
+
+ return unless rand(100) < $config->{chance};
+
+ if (ref($where) eq "ARRAY") {
+ $where = $where->[0];
+ }
+
+ $what = Encode::decode('utf8', $what);
+
+ print "$what\n";
+ if ($what =~ /^i('\''|\s+a)m\s+(\w+)\s*$/) {
+ return "Hi ".$2.", I'm dad";
+ }
+ return;
+}
+1;