mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-03 16:42:38 +01:00
factfind now works; find aliases factfind for all channels
This commit is contained in:
parent
58f19984bf
commit
7aa724569e
@ -48,15 +48,15 @@ sub initialize {
|
|||||||
$pbot->commands->register(sub { return $self->factchange(@_) }, "factchange", 0);
|
$pbot->commands->register(sub { return $self->factchange(@_) }, "factchange", 0);
|
||||||
$pbot->commands->register(sub { return $self->factalias(@_) }, "factalias", 0);
|
$pbot->commands->register(sub { return $self->factalias(@_) }, "factalias", 0);
|
||||||
$pbot->commands->register(sub { return $self->call_factoid(@_) }, "fact", 0);
|
$pbot->commands->register(sub { return $self->call_factoid(@_) }, "fact", 0);
|
||||||
|
$pbot->commands->register(sub { return $self->factfind(@_) }, "factfind", 0);
|
||||||
|
|
||||||
# the following commands have not yet been updated to use the new factoid structure
|
# the following commands have not yet been updated to use the new factoid structure
|
||||||
# DO NOT USE!! Factoid corruption may occur.
|
# DO NOT USE!! Factoid corruption may occur.
|
||||||
$pbot->commands->register(sub { return $self->list(@_) }, "list", 999);
|
$pbot->commands->register(sub { return $self->list(@_) }, "list", 0);
|
||||||
$pbot->commands->register(sub { return $self->add_regex(@_) }, "regex", 999);
|
$pbot->commands->register(sub { return $self->add_regex(@_) }, "regex", 999);
|
||||||
$pbot->commands->register(sub { return $self->histogram(@_) }, "histogram", 999);
|
$pbot->commands->register(sub { return $self->histogram(@_) }, "histogram", 999);
|
||||||
$pbot->commands->register(sub { return $self->top20(@_) }, "top20", 999);
|
$pbot->commands->register(sub { return $self->top20(@_) }, "top20", 999);
|
||||||
$pbot->commands->register(sub { return $self->count(@_) }, "count", 999);
|
$pbot->commands->register(sub { return $self->count(@_) }, "count", 999);
|
||||||
$pbot->commands->register(sub { return $self->find(@_) }, "find", 999);
|
|
||||||
$pbot->commands->register(sub { return $self->load_module(@_) }, "load", 999);
|
$pbot->commands->register(sub { return $self->load_module(@_) }, "load", 999);
|
||||||
$pbot->commands->register(sub { return $self->unload_module(@_) }, "unload", 999);
|
$pbot->commands->register(sub { return $self->unload_module(@_) }, "unload", 999);
|
||||||
$pbot->commands->register(sub { return $self->enable_command(@_) }, "enable", 999);
|
$pbot->commands->register(sub { return $self->enable_command(@_) }, "enable", 999);
|
||||||
@ -490,21 +490,18 @@ sub count {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub find {
|
sub factfind {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
my $factoids = $self->{pbot}->factoids->factoids;
|
my $factoids = $self->{pbot}->factoids->factoids->hash;
|
||||||
my $text;
|
|
||||||
my $type;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(not defined $arguments) {
|
if(not defined $arguments) {
|
||||||
return "/msg $nick Usage: !find [-owner nick] [-by nick] [text]";
|
return "/msg $nick Usage: !find [-channel channel] [-owner nick] [-by nick] [text]";
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($owner, $by);
|
my ($channel, $owner, $by);
|
||||||
|
|
||||||
|
$channel = $1 if $arguments =~ s/-channel\s+([^\b\s]+)//i;
|
||||||
$owner = $1 if $arguments =~ s/-owner\s+([^\b\s]+)//i;
|
$owner = $1 if $arguments =~ s/-owner\s+([^\b\s]+)//i;
|
||||||
$by = $1 if $arguments =~ s/-by\s+([^\b\s]+)//i;
|
$by = $1 if $arguments =~ s/-by\s+([^\b\s]+)//i;
|
||||||
|
|
||||||
@ -538,20 +535,29 @@ sub find {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(not defined $argtype) {
|
if(not defined $argtype) {
|
||||||
return "/msg $nick Usage: !find [-owner nick] [-by nick] [text]";
|
return "/msg $nick Usage: !find [-channel] [-owner nick] [-by nick] [text]";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $i = 0;
|
my ($text, $last_trigger, $last_chan, $i);
|
||||||
|
$last_chan = "";
|
||||||
|
$i = 0;
|
||||||
eval {
|
eval {
|
||||||
foreach my $command (sort keys %{ $factoids }) {
|
foreach my $chan (sort keys %{ $factoids }) {
|
||||||
if(exists $factoids->{$command}{text} || exists $factoids->{$command}{regex}) {
|
next if defined $channel and $chan !~ /$channel/i;
|
||||||
$type = 'text' if(exists $factoids->{$command}{text});
|
foreach my $trigger (sort keys %{ $factoids->{$chan} }) {
|
||||||
$type = 'regex' if(exists $factoids->{$command}{regex});
|
if($factoids->{$chan}->{$trigger}->{type} eq 'text' or $factoids->{$chan}->{$trigger}->{type} eq 'regex') {
|
||||||
|
if($factoids->{$chan}->{$trigger}->{owner} =~ /$owner/i && $factoids->{$chan}->{$trigger}->{ref_user} =~ /$by/i) {
|
||||||
|
next if($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /$arguments/i && $trigger !~ /$arguments/i);
|
||||||
|
|
||||||
if($factoids->{$command}{owner} =~ /$owner/i && $factoids->{$command}{ref_user} =~ /$by/i) {
|
$i++;
|
||||||
next if($arguments ne "" && $factoids->{$command}{$type} !~ /$arguments/i && $command !~ /$arguments/i);
|
|
||||||
$i++;
|
if($chan ne $last_chan) {
|
||||||
$text .= "$command ";
|
$text .= $chan eq '.*' ? "[all channels] " : "[$chan] ";
|
||||||
|
$last_chan = $chan;
|
||||||
|
}
|
||||||
|
$text .= "$trigger ";
|
||||||
|
$last_trigger = $trigger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,12 +567,12 @@ sub find {
|
|||||||
|
|
||||||
if($i == 1) {
|
if($i == 1) {
|
||||||
chop $text;
|
chop $text;
|
||||||
$type = 'text' if exists $factoids->{$text}{text};
|
return "found one factoid submitted for " . ($last_chan eq '.*' ? 'all channels' : $last_chan) . " " . $argtype . ": '$last_trigger' is '" . $factoids->{$last_chan}->{$last_trigger}->{action} . "'";
|
||||||
$type = 'regex' if exists $factoids->{$text}{regex};
|
|
||||||
return "found one factoid " . $argtype . ": '$text' is '$factoids->{$text}{$type}'";
|
|
||||||
} else {
|
} else {
|
||||||
return "$i factoids " . $argtype . ": $text" unless $i == 0;
|
return "$i factoids " . $argtype . ": $text" unless $i == 0;
|
||||||
return "No factoids " . $argtype;
|
|
||||||
|
my $chans = (defined $channel ? ($channel eq '.*' ? 'all channels' : $channel) : 'any channels');
|
||||||
|
return "No factoids " . $argtype . " submitted for $chans";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 210,
|
BUILD_REVISION => 211,
|
||||||
BUILD_DATE => "2010-06-28",
|
BUILD_DATE => "2010-06-28",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
493
data/factoids
493
data/factoids
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user