diff options
author | David Phillips <david@yeah.nah.nz> | 2018-10-02 19:23:15 +1300 |
---|---|---|
committer | David Phillips <david@yeah.nah.nz> | 2018-10-02 19:23:15 +1300 |
commit | 5545685353d1ba4ddeccbe4c8658da4674127d33 (patch) | |
tree | 76ccc08160c2d8d10e827465bd9144532feeefb7 /Plugin | |
parent | 8c1c7bd5e29f0b4574e65f67091f9ed9d5b53940 (diff) | |
download | idalius-5545685353d1ba4ddeccbe4c8658da4674127d33.tar.xz |
Natural: refactor, add response delay
Diffstat (limited to 'Plugin')
-rw-r--r-- | Plugin/Natural.pm | 25 |
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 @_; } |