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 { ...@@ -18,10 +18,22 @@ sub exec {
my $all = 0; my $all = 0;
$all = 1 if ($chan->[0] !~ /^#/ || $msg =~ s/-all//); $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 $content;
my $req;
my $sth; 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 (@tags) {
if (looks_like_number($tags[0])) { if (looks_like_number($tags[0])) {
$sth = $dbh->prepare('select id, sender, title, url $sth = $dbh->prepare('select id, sender, title, url
...@@ -33,28 +45,34 @@ sub exec { ...@@ -33,28 +45,34 @@ sub exec {
my $params = join ', ' => ('?') x @tags; my $params = join ', ' => ('?') x @tags;
if ($all) { if ($all) {
$sth = $dbh->prepare('select id, sender, title, url $req = 'select id, sender, title, url
from playbot from playbot
natural join playbot_tags natural join playbot_tags
where tag in ('.$params.') where tag in ('.$params.')';
group by id $req .= ' and '.$words_sql if ($words_sql);
$req .= ' group by id
having count(*) >= ? having count(*) >= ?
order by rand() order by rand()
limit 1'); limit 1';
$sth->execute(@tags, scalar @tags);
$sth = $dbh->prepare($req);
$sth->execute(@tags, @words, scalar @tags);
} }
else { 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 from playbot p
natural join playbot_tags pt natural join playbot_tags pt
join playbot_chan pc on p.id = pc.content join playbot_chan pc on p.id = pc.content
where pt.tag in ('.$params.') where pt.tag in ('.$params.')';
and pc.chan = ? $req .= ' and '.$words_sql if ($words_sql);
$req .= ' and pc.chan = ?
group by p.id group by p.id
having count(*) >= ? having count(*) >= ?
order by rand() order by rand()
limit 1'); limit 1';
$sth->execute(@tags, $chan->[0], scalar @tags);
$sth = $dbh->prepare($req);
$sth->execute(@tags, @words, $chan->[0], scalar @tags);
} }
} }
...@@ -67,25 +85,35 @@ sub exec { ...@@ -67,25 +85,35 @@ sub exec {
} }
else { else {
if ($all) { if ($all) {
$sth = $dbh->prepare('select id, sender, title, url from playbot $req = 'select id, sender, title, url from playbot';
order by rand() $req .= ' where '.$words_sql if ($words_sql);
limit 1'); $req .= ' order by rand() limit 1';
$sth->execute;
$sth = $dbh->prepare($req);
$sth->execute (@words);
} }
else { 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 from playbot p
join playbot_chan pc on p.id = pc.content join playbot_chan pc on p.id = pc.content
where pc.chan = ? where pc.chan = ?';
order by rand() $req .= ' and '.$words_sql if ($words_sql);
limit 1'); $req .= ' order by rand()
$sth->execute($chan->[0]); limit 1';
$sth = $dbh->prepare($req);
$sth->execute($chan->[0], @words);
} }
$content = $sth->fetch; $content = $sth->fetch;
if (!$content) { 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."); $irc->yield(privmsg => $chan => "Poste d'abord du contenu, n00b.");
}
return 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