From 5545685353d1ba4ddeccbe4c8658da4674127d33 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 2 Oct 2018 19:23:15 +1300 Subject: Natural: refactor, add response delay --- Plugin/Natural.pm | 25 +++++++++++++++++++------ 1 file 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 @_; } -- cgit v1.1