mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-10 20:12:35 +01:00
Improvements in interpreter; tell <nick> about <command>; etc
This commit is contained in:
parent
09cb762c6f
commit
ccf1d35a54
@ -165,6 +165,7 @@ sub ack_die {
|
||||
}
|
||||
|
||||
sub export {
|
||||
my $self = shift;
|
||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||
|
||||
if(not defined $arguments) {
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 "";
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
$arguments =~ s/(?<![\w\/])me\b/$nick/gi if defined $arguments;
|
||||
if($keyword ne "factadd" and $keyword ne "add" and $keyword ne "msg") {
|
||||
$keyword =~ s/(\w+)([?!.]+)$/$1/;
|
||||
$arguments =~ s/(\w+)([?!.]+)$/$1/;
|
||||
$arguments =~ s/(?<![\w\/\-])me\b/$nick/gi if defined $arguments;
|
||||
}
|
||||
|
||||
if(defined $arguments && $arguments =~ m/^(your|him|her|its|it|them|their)(self|selves)$/i) {
|
||||
return "Why would I want to do that to myself?";
|
||||
|
@ -13,8 +13,8 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 378,
|
||||
BUILD_DATE => "2012-08-17",
|
||||
BUILD_REVISION => 379,
|
||||
BUILD_DATE => "2012-08-23",
|
||||
};
|
||||
|
||||
1;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user