From 9b4f2420638fb5d059c302adc74fc47f837d7135 Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@gmail.com> Date: Mon, 19 Aug 2013 08:15:51 +0200 Subject: [PATCH] "!get some tags" uses now the random order from sql --- lib/commands/get.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/commands/get.pm b/lib/commands/get.pm index 7ebfa8c..e226615 100644 --- a/lib/commands/get.pm +++ b/lib/commands/get.pm @@ -29,7 +29,9 @@ sub exec { natural join playbot_tags where tag in ('.$params.') group by id - having count(*) >= ?'); + having count(*) >= ? + order by rand() + limit 1'); $sth->execute(@tags, scalar @tags); } else { @@ -40,19 +42,18 @@ sub exec { where pt.tag in ('.$params.') and pc.chan = ? group by p.id - having count(*) >= ?'); + having count(*) >= ? + order by rand() + limit 1'); $sth->execute(@tags, $chan->[0], scalar @tags); } - $content = $sth->fetchall_arrayref; + $content = $sth->fetch; if (!@{$content}) { $irc->yield(privmsg => $chan => "Je n'ai rien dans ce registre."); return } - else { - $content = $content->[rand @{$content}]; - } } else { my $sth; -- GitLab