From ccf1d35a54678c325a3e6b27bcaf5c404d3fdddd Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 23 Aug 2012 22:50:07 +0000 Subject: [PATCH] Improvements in interpreter; tell about ; etc --- PBot/BotAdminCommands.pm | 1 + PBot/ChanOps.pm | 9 ++++--- PBot/FactoidModuleLauncher.pm | 4 +++ PBot/Factoids.pm | 49 +++++++++++++++++++---------------- PBot/Interpreter.pm | 26 +++++++++++-------- PBot/VERSION.pm | 4 +-- modules/get_title.pl | 1 + modules/google.pl | 2 +- 8 files changed, 56 insertions(+), 40 deletions(-) diff --git a/PBot/BotAdminCommands.pm b/PBot/BotAdminCommands.pm index 8d746f7e..f9428884 100644 --- a/PBot/BotAdminCommands.pm +++ b/PBot/BotAdminCommands.pm @@ -165,6 +165,7 @@ sub ack_die { } sub export { + my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; if(not defined $arguments) { diff --git a/PBot/ChanOps.pm b/PBot/ChanOps.pm index 6b448a95..9fce476b 100644 --- a/PBot/ChanOps.pm +++ b/PBot/ChanOps.pm @@ -119,8 +119,8 @@ sub check_unban_timeouts { if($self->{unban_timeout}->hash->{$mask}{timeout} < $now) { $self->unban_user($mask, $self->{unban_timeout}->hash->{$mask}{channel}); } else { - #my $timediff = $unban_timeout{$mask}{timeout} - $now; - #$logger->log "ban: $mask has $timediff seconds remaining\n" + # my $timediff = $self->{unban_timeout}->hash->{$mask}{timeout} - $now; + # $self->{pbot}->logger->log("ban: $mask has $timediff seconds remaining\n"); } } } @@ -132,9 +132,10 @@ sub check_opped_timeouts { foreach my $channel (keys %{ $self->{is_opped} }) { if($self->{is_opped}->{$channel}{timeout} < $now) { $self->lose_ops($channel); + delete $self->{is_opped}->{$channel}; # assume chanserv is alive and deop will succeed } else { - # my $timediff = $is_opped{$channel}{timeout} - $now; - # $logger->log("deop $channel in $timediff seconds\n"); + # my $timediff = $self->{is_opped}->{$channel}{timeout} - $now; + # $self->{pbot}->logger->log("deop $channel in $timediff seconds\n"); } } } diff --git a/PBot/FactoidModuleLauncher.pm b/PBot/FactoidModuleLauncher.pm index ac36095a..959ac7ad 100644 --- a/PBot/FactoidModuleLauncher.pm +++ b/PBot/FactoidModuleLauncher.pm @@ -135,6 +135,10 @@ sub execute_module { $self->{pbot}->logger->log("($from): $nick!$user\@$host) sent to $tonick\n"); $text = `$module_dir/$module $arguments`; if(defined $text && length $text > 0) { + # get rid of original caller's nick + $text =~ s/^\/([^ ]+) \Q$nick\E:\s+/\/$1 /; + $text =~ s/^\Q$nick\E:\s+//; + return "$tonick: $text"; } else { return ""; diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index dd521d9b..21027b5a 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -259,7 +259,7 @@ sub interpreter { elsif($found == 1) { $pbot->logger->log("Found '$original_keyword' as '$fwd_trig' in [$fwd_chan]\n"); - return $pbot->factoids->interpreter($from, $nick, $user, $host, $count, $fwd_trig, $arguments, undef, $fwd_chan); + return $pbot->factoids->interpreter($from, $nick, $user, $host, $count, $fwd_trig, $arguments, $tonick, $fwd_chan); } # otherwise keyword hasn't been found, display similiar matches for all channels else { @@ -293,7 +293,7 @@ sub interpreter { $self->factoids->hash->{$channel}->{$keyword}->{ref_user} = $nick; $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday; - return $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $command); + return $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $command, $tonick); } my $last_ref_in = 0; @@ -338,24 +338,7 @@ sub interpreter { $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday; $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in} = $from || "stdin"; - if(defined $tonick) { # !tell foo about bar - $self->{pbot}->logger->log("($from): $nick!$user\@$host) sent to $tonick\n"); - my $fromnick = $self->{pbot}->admins->loggedin($from, "$nick!$user\@$host") ? "" : "$nick wants you to know: "; - $result = $self->factoids->hash->{$channel}->{$keyword}->{action}; - - my $botnick = $self->{pbot}->botnick; - - if($result =~ s/^\/say\s+//i || $result =~ s/^\/me\s+/* $botnick /i - || $result =~ /^\/msg\s+/i) { - $result = "/msg $tonick $fromnick$result"; - } else { - $result = "/msg $tonick $fromnick$keyword is $result"; - } - - $self->{pbot}->logger->log("result set to [$result]\n"); - } else { - $result = $self->factoids->hash->{$channel}->{$keyword}->{action}; - } + $result = $self->factoids->hash->{$channel}->{$keyword}->{action}; if(length $arguments) { if(exists $self->factoids->hash->{$channel}->{$keyword}->{action_with_args}) { @@ -378,7 +361,29 @@ sub interpreter { } } else { # no arguments supplied - $result =~ s/\$args/$nick/gi; + if(defined $tonick) { + $result =~ s/\$args/$tonick/gi; + } else { + $result =~ s/\$args/$nick/gi; + } + } + + if(defined $tonick) { # !tell foo about bar + $self->{pbot}->logger->log("($from): $nick!$user\@$host) sent to $tonick\n"); + my $botnick = $self->{pbot}->botnick; + + # get rid of original caller's nick + $result =~ s/^\/([^ ]+) \Q$nick\E:\s+/\/$1 /; + $result =~ s/^\Q$nick\E:\s+//; + + if($result =~ s/^\/say\s+//i || $result =~ s/^\/me\s+/* $botnick /i + || $result =~ /^\/msg\s+/i) { + $result = "/say $tonick: $result"; + } else { + $result = "/say $tonick: $keyword is $result"; + } + + $self->{pbot}->logger->log("result set to [$result]\n"); } $self->{pbot}->logger->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host): $keyword: Displaying text \"" . $result . "\"\n"); @@ -442,7 +447,7 @@ sub interpreter { $cmd = $self->factoids->hash->{$channel}->{$keyword}->{action}; } - $result = $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $cmd); + $result = $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $cmd, $tonick); return $result; }; diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index a1c7d30e..c6b44a44 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -106,12 +106,12 @@ sub process_line { my $preserve_whitespace = 0; - if($text =~ /^.?$mynick.?\s+(.*?)([?!.]*)$/i) { - $command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : ""); - } elsif($text =~ /^(.*?),?\s+$mynick([?!.]*)$/i) { - $command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : ""); - } elsif($text =~ /^\Q$pbot->{trigger}\E(.*?)([?!.]*)$/) { - $command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : ""); + if($text =~ /^\Q$pbot->{trigger}\E(.*)$/) { + $command = $1; + } elsif($text =~ /^.?$mynick.?\s+(.*?)$/i) { + $command = $1; + } elsif($text =~ /^(.*?),?\s+$mynick[?!.]*$/i) { + $command = $1; } elsif($text =~ /https?:\/\/([^\s]+)/i) { $has_url = $1; } elsif($text =~ /^\s*([^,:\(\)\+\*\/ ]+)[,:]*\s*{\s*(.*)\s*}\s*$/) { @@ -198,8 +198,8 @@ sub process_line { sub interpret { my $self = shift; - my ($from, $nick, $user, $host, $count, $command) = @_; - my ($keyword, $arguments, $tonick); + my ($from, $nick, $user, $host, $count, $command, $tonick) = @_; + my ($keyword, $arguments) = ("", ""); my $text; my $pbot = $self->pbot; @@ -234,10 +234,14 @@ sub interpret { } elsif($command =~ /^(.*?)\s+(.*)$/) { ($keyword, $arguments) = ($1, $2); } else { - $keyword = $1 if $command =~ /^(.*)$/; + $keyword = $command; + } + + if($keyword ne "factadd" and $keyword ne "add" and $keyword ne "msg") { + $keyword =~ s/(\w+)([?!.]+)$/$1/; + $arguments =~ s/(\w+)([?!.]+)$/$1/; + $arguments =~ s/(? "PBot", - BUILD_REVISION => 378, - BUILD_DATE => "2012-08-17", + BUILD_REVISION => 379, + BUILD_DATE => "2012-08-23", }; 1; diff --git a/modules/get_title.pl b/modules/get_title.pl index f7ada368..2de6dc81 100755 --- a/modules/get_title.pl +++ b/modules/get_title.pl @@ -27,6 +27,7 @@ exit if($arguments =~ m/wiki.osdev.org/i); exit if($arguments =~ m/wikipedia.org/i); exit if($arguments =~ m/everfall.com/i); exit if($arguments =~ m/\/paste\//i); +exit if($arguments =~ m/paste\./i); exit if($arguments =~ m/pastie/i); exit if($arguments =~ m/ideone.com/i); exit if($arguments =~ m/codepad.org/i); diff --git a/modules/google.pl b/modules/google.pl index 01642d1b..73b2d6ca 100755 --- a/modules/google.pl +++ b/modules/google.pl @@ -12,7 +12,7 @@ $matches = 1; if ($#ARGV < 0) { - print "Usage: !google [number of results] query\n"; + print "Usage: google [number of results] query\n"; die; }