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

All the commands works now in query

parent 7d360bcd
Branches
Étiquettes
Aucune requête de fusion associée trouvée
...@@ -174,9 +174,14 @@ sub on_connect ...@@ -174,9 +174,14 @@ sub on_connect
# Discussion privée # Discussion privée
sub on_query sub on_query
{ {
my ($user,$msg) = @_[ARG0, ARG2]; my ($kernel, $user, $msg) = @_[KERNEL, ARG0, ARG2];
my ($nick) = split (/!/,$user); my ($nick) = split (/!/,$user);
print $msg."\n";
my @fake_chan = ($nick);
my @args = ($kernel, $user, \@fake_chan, $msg);
my $fake_chan = \@fake_chan;
return if (commands::parser::exec(@args));
if ($msg =~ m/^!/ && $nick eq $admin) { if ($msg =~ m/^!/ && $nick eq $admin) {
my $commande = ( $msg =~ m/^!([^ ]*)/ )[0]; my $commande = ( $msg =~ m/^!([^ ]*)/ )[0];
......
...@@ -17,15 +17,30 @@ sub exec { ...@@ -17,15 +17,30 @@ sub exec {
my @tags = ($msg =~ /#?([a-zA-Z0-9_-]+)/g); my @tags = ($msg =~ /#?([a-zA-Z0-9_-]+)/g);
my $content; my $content;
# if we are in a query, we search in all the channels
my $all = ($chan->[0] !~ /^#/) ? 1 : 0;
if (@tags) { if (@tags) {
my $params = join ', ' => ('?') x @tags; my $params = join ', ' => ('?') x @tags;
my $sth = $dbh->prepare('select id, sender, title, url from playbot my $sth;
if ($all) {
$sth = $dbh->prepare('select id, sender, title, url from playbot
natural join playbot_tags
where tag in ('.$params.')
group by id
having count(*) >= ?');
$sth->execute(@tags, scalar @tags);
}
else {
$sth = $dbh->prepare('select id, sender, title, url from playbot
natural join playbot_tags natural join playbot_tags
where tag in ('.$params.') where tag in ('.$params.')
and chan = ? and chan = ?
group by id group by id
having count(*) >= ?'); having count(*) >= ?');
$sth->execute(@tags, $chan->[0], scalar @tags); $sth->execute(@tags, $chan->[0], scalar @tags);
}
$content = $sth->fetchall_arrayref; $content = $sth->fetchall_arrayref;
...@@ -38,11 +53,22 @@ sub exec { ...@@ -38,11 +53,22 @@ sub exec {
} }
} }
else { else {
my $sth = $dbh->prepare('select id, sender, title, url from playbot my $sth;
if ($all) {
$sth = $dbh->prepare('select id, sender, title, url from playbot
order by rand()
limit 1');
$sth->execute;
}
else {
$sth = $dbh->prepare('select id, sender, title, url from playbot
where chan = ? where chan = ?
order by rand() order by rand()
limit 1'); limit 1');
$sth->execute($chan->[0]); $sth->execute($chan->[0]);
}
$content = $sth->fetch; $content = $sth->fetch;
if (!$content) { if (!$content) {
......
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