aboutsummaryrefslogtreecommitdiff
path: root/Plugin
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2018-10-23 22:35:37 +1300
committerDavid Phillips <david@yeah.nah.nz>2018-10-23 22:35:37 +1300
commitffd1cdbfdca6c4a0b413c7adb39b6dafc260b1e3 (patch)
tree5ac583e32dd58feda5dff5cc1e4cd1ab874f53de /Plugin
parent5b6bfc52ed295770964cf0d162be4f44c4adb720 (diff)
downloadidalius-ffd1cdbfdca6c4a0b413c7adb39b6dafc260b1e3.tar.xz
Add Hmm.pm
Diffstat (limited to 'Plugin')
-rw-r--r--Plugin/Hmm.pm53
1 files changed, 53 insertions, 0 deletions
diff --git a/Plugin/Hmm.pm b/Plugin/Hmm.pm
new file mode 100644
index 0000000..5ceb66a
--- /dev/null
+++ b/Plugin/Hmm.pm
@@ -0,0 +1,53 @@
+package Plugin::Hmm;
+
+use strict;
+use warnings;
+use threads;
+
+my $root_config;
+my $config;
+my %current_alarm;
+
+sub configure {
+ my $self = shift;
+ shift; # cmdref
+ shift; # run_command
+ $config = shift;
+ $root_config = shift;
+
+ IdaliusConfig::assert_scalar($config, $self, "min_delay_sec");
+ IdaliusConfig::assert_scalar($config, $self, "max_delay_sec");
+
+ return $self;
+}
+
+# FIXME dedup with Natural.pm
+sub some {
+ my @choices = @_;
+ return $choices[rand(@choices)];
+}
+
+sub on_message {
+ my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
+ my $nick = (split /!/, $who)[0];
+
+ # Don't perform this in q to users
+ return if ref($where) ne "ARRAY";
+ $where = $where->[0];
+
+ if (defined $current_alarm{$where}) {
+ $irc->delay_remove($current_alarm{$where});
+ }
+
+ my $response = some("Hmm", "hmm", "hmmmmmm", "oof", "mmm");
+
+ $current_alarm{$where} = $irc->delay([privmsg => $where => $response],
+ $config->{min_delay_sec} + rand($config->{max_delay_sec} - $config->{min_delay_sec}));
+
+ return;
+}
+
+sub on_action {
+ on_message @_;
+}
+1;