From ef404560ccfb5f77ec12045a4e6a5f028079cb52 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Fri, 5 Dec 2014 11:05:19 +0100
Subject: [PATCH] refactor fetch in !get

---
 lib/commands/get.pm | 34 ++++++++++------------------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/lib/commands/get.pm b/lib/commands/get.pm
index 1c45e8e..6b26a0e 100644
--- a/lib/commands/get.pm
+++ b/lib/commands/get.pm
@@ -41,13 +41,6 @@ sub exec {
             from playbot
             where id = ?');
         $sth->execute($words[0]);
-
-        $content = $sth->fetch;
-
-        if (!$content) {
-            $irc->yield(privmsg => $chan => "Je n'ai rien dans ce registre.");
-            return
-        }
     }
     elsif (@tags) {
         my $params = join ', ' => ('?') x @tags;
@@ -80,13 +73,6 @@ sub exec {
             $sth = $dbh->prepare($req);
             $sth->execute(@tags, @words_param, $chan->[0], scalar @tags);
         }
-
-        $content = $sth->fetch;
-
-        if (!$content) {
-            $irc->yield(privmsg => $chan => "Je n'ai rien dans ce registre.");
-            return
-        }
     }
     else {
         if ($all) {
@@ -110,18 +96,18 @@ sub exec {
             $sth = $dbh->prepare($req);
             $sth->execute($chan->[0], @words_param);
         }
+    }
+
+    $content = $sth->fetch;
 
-        $content = $sth->fetch;
-        
-        if (!$content) {
-            if (@words) {
-                $irc->yield(privmsg => $chan => "Je n'ai rien dans ce registre.");
-            }
-            else {
-                $irc->yield(privmsg => $chan => "Poste d'abord du contenu, n00b.");
-            }
-            return
+    if (!$content) {
+        if (@words or @tags) {
+            $irc->yield(privmsg => $chan => "Je n'ai rien dans ce registre.");
+        }
+        else {
+            $irc->yield(privmsg => $chan => "Poste d'abord du contenu, n00b.");
         }
+        return
     }
 
     # this is specific to the mysql driver
-- 
GitLab