Skip to content
Extraits de code Groupes Projets
Valider 765e21bf rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

!get: can search in title/sender

!get #tag: search tag #tag
!get word: search word "word" in the title and the sender
Can be combined : !get mitis #hardstyle
parent 35914d11
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -18,10 +18,22 @@ sub exec {
my $all = 0;
$all = 1 if ($chan->[0] !~ /^#/ || $msg =~ s/-all//);
my @tags = ($msg =~ /#?([a-zA-Z0-9_-]+)/g);
my @tags = ($msg =~ /#([a-zA-Z0-9_-]+)/g);
my $content;
my $req;
my $sth;
my @words;
while ($msg =~ /(^| )([a-zA-Z0-9_-]+)/g) {
unshift @words, '%'.$2.'%';
}
my $words_sql;
foreach (@words) {
$words_sql .= ' and ' if ($words_sql);
$words_sql .= "concat(sender, ' ', title) like ?";
}
if (@tags) {
if (looks_like_number($tags[0])) {
$sth = $dbh->prepare('select id, sender, title, url
......@@ -33,28 +45,34 @@ sub exec {
my $params = join ', ' => ('?') x @tags;
if ($all) {
$sth = $dbh->prepare('select id, sender, title, url
$req = 'select id, sender, title, url
from playbot
natural join playbot_tags
where tag in ('.$params.')
group by id
where tag in ('.$params.')';
$req .= ' and '.$words_sql if ($words_sql);
$req .= ' group by id
having count(*) >= ?
order by rand()
limit 1');
$sth->execute(@tags, scalar @tags);
limit 1';
$sth = $dbh->prepare($req);
$sth->execute(@tags, @words, scalar @tags);
}
else {
$sth = $dbh->prepare('select p.id, p.sender, p.title, p.url
$req = 'select p.id, p.sender, p.title, p.url
from playbot p
natural join playbot_tags pt
join playbot_chan pc on p.id = pc.content
where pt.tag in ('.$params.')
and pc.chan = ?
where pt.tag in ('.$params.')';
$req .= ' and '.$words_sql if ($words_sql);
$req .= ' and pc.chan = ?
group by p.id
having count(*) >= ?
order by rand()
limit 1');
$sth->execute(@tags, $chan->[0], scalar @tags);
limit 1';
$sth = $dbh->prepare($req);
$sth->execute(@tags, @words, $chan->[0], scalar @tags);
}
}
......@@ -67,25 +85,35 @@ sub exec {
}
else {
if ($all) {
$sth = $dbh->prepare('select id, sender, title, url from playbot
order by rand()
limit 1');
$sth->execute;
$req = 'select id, sender, title, url from playbot';
$req .= ' where '.$words_sql if ($words_sql);
$req .= ' order by rand() limit 1';
$sth = $dbh->prepare($req);
$sth->execute (@words);
}
else {
$sth = $dbh->prepare('select p.id, p.sender, p.title, p.url
$req = 'select p.id, p.sender, p.title, p.url
from playbot p
join playbot_chan pc on p.id = pc.content
where pc.chan = ?
order by rand()
limit 1');
$sth->execute($chan->[0]);
where pc.chan = ?';
$req .= ' and '.$words_sql if ($words_sql);
$req .= ' order by rand()
limit 1';
$sth = $dbh->prepare($req);
$sth->execute($chan->[0], @words);
}
$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
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter