From 87783dba136f189d74395dbccee532f12208f80d Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Tue, 18 Aug 2015 22:43:00 +0200
Subject: [PATCH] an option is needed to do a !get with only one word

---
 lib/commands/get.pm       |  8 ++++++++
 lib/commands/get/query.pm | 21 ++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/lib/commands/get.pm b/lib/commands/get.pm
index f16b47d..9bd2fe0 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 581e6aa..ed65715 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];
 }
-- 
GitLab