mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 23:39:24 +01:00
FactoidCommands: Optimize factfind()
This commit is contained in:
parent
5d3dca94b9
commit
4c7b7551e2
@ -29,7 +29,6 @@ our %factoid_metadata_capabilities = (
|
|||||||
enabled => 'chanop',
|
enabled => 'chanop',
|
||||||
last_referenced_in => 'botowner',
|
last_referenced_in => 'botowner',
|
||||||
last_referenced_on => 'botowner',
|
last_referenced_on => 'botowner',
|
||||||
modulelauncher_subpattern => 'botowner',
|
|
||||||
owner => 'botowner',
|
owner => 'botowner',
|
||||||
rate_limit => 'chanop',
|
rate_limit => 'chanop',
|
||||||
ref_count => 'botowner',
|
ref_count => 'botowner',
|
||||||
@ -910,9 +909,8 @@ sub factrem {
|
|||||||
if ($factoids->get_data($channel, $trigger, 'locked')) { return "/say $trigger_name is locked; unlock before deleting."; }
|
if ($factoids->get_data($channel, $trigger, 'locked')) { return "/say $trigger_name is locked; unlock before deleting."; }
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log("$nick!$user\@$host removed [$channel][$trigger][" . $factoids->get_data($channel, $trigger, 'action') . "]\n");
|
$self->{pbot}->{logger}->log("$nick!$user\@$host removed [$channel][$trigger][" . $factoids->get_data($channel, $trigger, 'action') . "]\n");
|
||||||
$self->{pbot}->{factoids}->remove_factoid($channel, $trigger);
|
|
||||||
$self->log_factoid($channel, $trigger, "$nick!$user\@$host", "deleted", 1);
|
$self->log_factoid($channel, $trigger, "$nick!$user\@$host", "deleted", 1);
|
||||||
return "/say $trigger_name removed from $channel_name.";
|
return $self->{pbot}->{factoids}->remove_factoid($channel, $trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub histogram {
|
sub histogram {
|
||||||
@ -1324,24 +1322,38 @@ sub factfind {
|
|||||||
|
|
||||||
foreach my $chan (sort $factoids->get_keys) {
|
foreach my $chan (sort $factoids->get_keys) {
|
||||||
next if defined $channel and $chan !~ /^$channel$/i;
|
next if defined $channel and $chan !~ /^$channel$/i;
|
||||||
foreach my $trigger (sort $factoids->get_keys($chan)) {
|
foreach my $factoid ($factoids->get(index1 => $chan, index2 => undef, owner => undef, ref_user => undef, edited_by => undef, action => undef)) {
|
||||||
next if $trigger eq '_name';
|
my $match = 0;
|
||||||
if ($factoids->get_data($chan, $trigger, 'type') eq 'text' or $factoids->get_data($chan, $trigger, 'type') eq 'regex') {
|
|
||||||
if ( $factoids->get_data($chan, $trigger, 'owner') =~ /^$owner$/i
|
if ($owner eq '.*') {
|
||||||
&& $factoids->get_data($chan, $trigger, 'ref_user') =~ /^$refby$/i
|
$match = 1;
|
||||||
&& ($factoids->exists($chan, $trigger, 'edited_by') ? $factoids->get_data($chan, $trigger, 'edited_by') =~ /^$editby$/i : 1))
|
} else {
|
||||||
{
|
$match = 1 if $factoid->{owner} =~ /^$owner/i;
|
||||||
next if ($arguments ne "" && $factoids->get_data($chan, $trigger, 'action') !~ /$regex/i && $trigger !~ /$regex/i);
|
}
|
||||||
$i++;
|
|
||||||
if ($chan ne $last_chan) {
|
if ($refby eq '.*') {
|
||||||
$text .= $chan eq '.*' ? '[global channel] ' : '[' . $factoids->get_data($chan, '_name') . '] ';
|
$match = 1;
|
||||||
$last_chan = $chan;
|
} else {
|
||||||
}
|
$match = 1 if $factoid->{ref_user} =~ /^$refby/i;
|
||||||
my $trigger_name = $factoids->get_data($chan, $trigger, '_name');
|
}
|
||||||
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
|
|
||||||
$text .= "$trigger_name ";
|
if ($editby eq '.*') {
|
||||||
$last_trigger = $trigger_name;
|
$match = 1;
|
||||||
|
} else {
|
||||||
|
$match = 1 if $factoid->{edited_by} =~ /^$editby/i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($match) {
|
||||||
|
next if ($arguments ne "" && $factoid->{action} !~ /$regex/i && $factoid->{index2} !~ /$regex/i);
|
||||||
|
$i++;
|
||||||
|
if ($chan ne $last_chan) {
|
||||||
|
$text .= $chan eq '.*' ? '[global channel] ' : '[' . $factoids->get_data($chan, '_name') . '] ';
|
||||||
|
$last_chan = $chan;
|
||||||
}
|
}
|
||||||
|
my $trigger_name = $factoids->get_data($chan, $factoid->{index2}, '_name');
|
||||||
|
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
|
||||||
|
$text .= "$trigger_name ";
|
||||||
|
$last_trigger = $trigger_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user