diff --git a/lib/commands/get.pm b/lib/commands/get.pm index f16b47d903e34b1f341e96b0d26431355554d8bb..9bd2fe01e152c27a1ff19114e8304acba43a5ae8 100644 --- a/lib/commands/get.pm +++ b/lib/commands/get.pm @@ -21,6 +21,14 @@ sub exec { query => ($msg) ? $msg : '' ); + if (scalar @{$query->words} == 1 + and scalar @{$query->tags} == 0 + and not $query->is_single_word) + { + $irc->yield(privmsg => $chan => "pour faire une recherche avec un seul mot, ajouter l'option -jesuisunspammeur (sinon on peut faire une recherche en query aussi)"); + return; + } + my $db_query = utils::db::get->new(); my $content = $db_query->get($query); my $rows = $db_query->get_rows($query); diff --git a/lib/commands/get/query.pm b/lib/commands/get/query.pm index 581e6aa5536eb42efbdbadf0abdb5e8873e7397e..ed65715962f3b9be0bb2b46c2a3011a8a963066d 100644 --- a/lib/commands/get/query.pm +++ b/lib/commands/get/query.pm @@ -24,6 +24,14 @@ has 'is_global' => ( init_arg => undef ); +has 'is_single_word' => ( + is => 'ro', + isa => 'Bool', + lazy => 1, + builder => '_build_is_single_word', + init_arg => undef +); + has 'tags' => ( is => 'ro', isa => 'ArrayRef[Str]', @@ -59,6 +67,16 @@ sub _build_is_global { } } +sub _build_is_single_word { + my $self = shift; + + if ($self->chan !~ /^#/ || $self->query =~ /(^|\s)-(jesuisunspammeur|1)($|\s)/) { + return 1; + } else { + return 0; + } +} + sub _build_tags { my $self = shift; @@ -72,7 +90,8 @@ sub _build_words { my $self = shift; my $query = $self->query; - $query =~ s/(^|\s)-a(ll)?($|\s)//; + $query =~ s/(^|\s)-a(ll)?($|\s)/ /; + $query =~ s/(^|\s)-(jesuisunspammeur|1)($|\s)/ /; return [$query =~ /(?:^| )([^#\s]+)/g]; }