mirror of
				https://github.com/pragma-/pbot.git
				synced 2025-10-31 14:47:27 +01:00 
			
		
		
		
	Improve handling of word-boundaries in searches
This commit is contained in:
		
							parent
							
								
									593fe59263
								
							
						
					
					
						commit
						3fa12c208e
					
				| @ -891,6 +891,10 @@ sub factfind { | ||||
|   $last_chan = ""; | ||||
|   $i = 0; | ||||
|   eval { | ||||
|     my $regex = ($arguments =~ m/^\w/) ? '\b' : '\B'; | ||||
|     $regex .= quotemeta $arguments; | ||||
|     $regex .= ($arguments =~ m/\w$/) ? '\b' : '\B'; | ||||
| 
 | ||||
|     foreach my $chan (sort keys %{ $factoids }) { | ||||
|       next if defined $channel and $chan !~ /$channel/i; | ||||
|       foreach my $trigger (sort keys %{ $factoids->{$chan} }) { | ||||
| @ -898,7 +902,7 @@ sub factfind { | ||||
|           if($factoids->{$chan}->{$trigger}->{owner} =~ /$owner/i  | ||||
|             && $factoids->{$chan}->{$trigger}->{ref_user} =~ /$refby/i | ||||
|             && (exists $factoids->{$chan}->{$trigger}->{edited_by} ? $factoids->{$chan}->{$trigger}->{edited_by} =~ /$editby/i : 1)) { | ||||
|             next if($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /\b$arguments\b/i && $trigger !~ /\b$arguments\b/i); | ||||
|             next if($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /$regex/i && $trigger !~ /$regex/i); | ||||
| 
 | ||||
|             $i++; | ||||
|              | ||||
|  | ||||
| @ -508,7 +508,10 @@ sub get_message_context { | ||||
|   my ($messages_before, $messages_after, $messages_count); | ||||
| 
 | ||||
|   if (defined $count and $count > 1) { | ||||
|     my $regex = '\b' . quotemeta($text) . '\b'; | ||||
|     my $regex = '(?i)'; | ||||
|     $regex .= ($text =~ m/^\w/) ? '\b' : '\B'; | ||||
|     $regex .= quotemeta $text; | ||||
|     $regex .= ($text =~ m/\w$/) ? '\b' : '\B'; | ||||
| 
 | ||||
|     $messages_count = eval { | ||||
|       my $sth; | ||||
| @ -518,13 +521,13 @@ sub get_message_context { | ||||
|         $sth->bind_param(2, $message->{channel}); | ||||
|         $sth->bind_param(3, $regex); | ||||
|         $sth->bind_param(4, $message->{timestamp}); | ||||
|         $sth->bind_param(5, $count); | ||||
|         $sth->bind_param(5, $count - 1); | ||||
|       } else { | ||||
|         $sth = $self->{dbh}->prepare('SELECT id, msg, mode, timestamp, channel FROM Messages WHERE channel = ? AND msg REGEXP ? AND timestamp < ? AND mode = 0 ORDER BY timestamp DESC LIMIT ?'); | ||||
|         $sth->bind_param(1, $message->{channel}); | ||||
|         $sth->bind_param(2, $regex); | ||||
|         $sth->bind_param(3, $message->{timestamp}); | ||||
|         $sth->bind_param(4, $count); | ||||
|         $sth->bind_param(4, $count - 1); | ||||
|       } | ||||
|       $sth->execute(); | ||||
|       return [reverse @{$sth->fetchall_arrayref({})}]; | ||||
| @ -634,7 +637,10 @@ sub recall_message_by_count { | ||||
| sub recall_message_by_text { | ||||
|   my ($self, $id, $channel, $text, $ignore_command) = @_; | ||||
|    | ||||
|   my $regex = '\b' . quotemeta($text) . '\b'; | ||||
|   my $regex = '(?i)'; | ||||
|   $regex .= ($text =~ m/^\w/) ? '\b' : '\B'; | ||||
|   $regex .= quotemeta $text; | ||||
|   $regex .= ($text =~ m/\w$/) ? '\b' : '\B'; | ||||
| 
 | ||||
|   my $messages; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pragmatic Software
						Pragmatic Software