From 1b3d5d3ca8a43baba8abd002ea534b5a30339f2b Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Sat, 22 Aug 2015 13:57:30 +0200
Subject: [PATCH] -jesuisunspammeur becomes -f and is more clever

---
 lib/commands/get.pm       | 13 +++++++------
 lib/commands/get/query.pm | 10 +++++-----
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/commands/get.pm b/lib/commands/get.pm
index e83a915..f8f77f0 100644
--- a/lib/commands/get.pm
+++ b/lib/commands/get.pm
@@ -21,18 +21,19 @@ sub exec {
         query  => ($msg) ? $msg : ''
     );
 
-    if (scalar @{$query->words} == 1
-            and scalar @{$query->tags} == 0
+    my $db_query = utils::db::get->new();
+    my $rows = $db_query->get_rows($query);
+
+    if (scalar @{$query->tags} == 0
             and $query->id == -1
-            and not $query->is_single_word)
+            and $rows > 10
+            and not $query->force)
     {
-        $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)");
+        $irc->yield(privmsg => $chan => "trop de résultats ($rows), utiliser -f pour forcer la recherche");
         return;
     }
 
-    my $db_query = utils::db::get->new();
     my $content = $db_query->get($query);
-    my $rows = $db_query->get_rows($query);
 
     if (!$content) {
         if ($rows > 0) {
diff --git a/lib/commands/get/query.pm b/lib/commands/get/query.pm
index ed65715..12f6d8a 100644
--- a/lib/commands/get/query.pm
+++ b/lib/commands/get/query.pm
@@ -24,11 +24,11 @@ has 'is_global' => (
     init_arg    => undef
 );
 
-has 'is_single_word' => (
+has 'force' => (
     is          => 'ro',
     isa         => 'Bool',
     lazy        => 1,
-    builder     => '_build_is_single_word',
+    builder     => '_build_force',
     init_arg    => undef
 );
 
@@ -67,10 +67,10 @@ sub _build_is_global {
     }
 }
 
-sub _build_is_single_word {
+sub _build_force {
     my $self = shift;
 
-    if ($self->chan !~ /^#/ || $self->query =~ /(^|\s)-(jesuisunspammeur|1)($|\s)/) {
+    if ($self->chan !~ /^#/ || $self->query =~ /(^|\s)-f($|\s)/) {
         return 1;
     } else {
         return 0;
@@ -91,7 +91,7 @@ sub _build_words {
     
     my $query = $self->query;
     $query =~ s/(^|\s)-a(ll)?($|\s)/ /;
-    $query =~ s/(^|\s)-(jesuisunspammeur|1)($|\s)/ /;
+    $query =~ s/(^|\s)-f($|\s)/ /;
 
     return [$query =~ /(?:^| )([^#\s]+)/g];
 }
-- 
GitLab