aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2018-10-02 19:23:15 +1300
committerDavid Phillips <david@yeah.nah.nz>2018-10-02 19:23:15 +1300
commit5545685353d1ba4ddeccbe4c8658da4674127d33 (patch)
tree76ccc08160c2d8d10e827465bd9144532feeefb7
parent8c1c7bd5e29f0b4574e65f67091f9ed9d5b53940 (diff)
downloadidalius-5545685353d1ba4ddeccbe4c8658da4674127d33.tar.xz
Natural: refactor, add response delay
-rw-r--r--Plugin/Natural.pm25
1 files changed, 19 insertions, 6 deletions
diff --git a/Plugin/Natural.pm b/Plugin/Natural.pm
index fabdf0c..64cc755 100644
--- a/Plugin/Natural.pm
+++ b/Plugin/Natural.pm
@@ -32,12 +32,8 @@ sub some {
return $choices[rand(@choices)];
}
-sub on_message {
- my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
- my $nick = (split /!/, $who)[0];
-
- return unless $what =~ /\b$root_config->{current_nick}\b/;
- return unless mention_odds();
+sub choose_response {
+ my ($what, $nick) = @_;
if ($what =~ /\b(hi|hey|sup|morning|hello|hiya)\b/i) {
return some("hi $nick", "hey $nick", "sup $nick") . some("", ", how goes it?");
@@ -51,6 +47,23 @@ sub on_message {
return;
}
+sub on_message {
+ my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
+ my $nick = (split /!/, $who)[0];
+
+ if (ref($where) eq "ARRAY") {
+ $where = $where->[0];
+ }
+
+ return unless $what =~ /\b$root_config->{current_nick}\b/;
+ return unless mention_odds();
+
+ my $response = choose_response($what, $nick);
+ $irc->delay([privmsg => $where => $response], rand(10)) if $response;
+
+ return;
+}
+
sub on_action {
on_message @_;
}