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
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -174,9 +174,14 @@ sub on_connect
# Discussion privée
sub on_query
{
my ($user,$msg) = @_[ARG0, ARG2];
my ($kernel, $user, $msg) = @_[KERNEL, ARG0, ARG2];
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) {
my $commande = ( $msg =~ m/^!([^ ]*)/ )[0];
......
......@@ -17,15 +17,30 @@ sub exec {
my @tags = ($msg =~ /#?([a-zA-Z0-9_-]+)/g);
my $content;
# if we are in a query, we search in all the channels
my $all = ($chan->[0] !~ /^#/) ? 1 : 0;
if (@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
where tag in ('.$params.')
and chan = ?
group by id
having count(*) >= ?');
$sth->execute(@tags, $chan->[0], scalar @tags);
}
$content = $sth->fetchall_arrayref;
......@@ -38,11 +53,22 @@ sub exec {
}
}
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 = ?
order by rand()
limit 1');
$sth->execute($chan->[0]);
}
$content = $sth->fetch;
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