Une erreur est survenue de notre côté
Sélectionner une révision Git
-
Jonathan CROUZET a rédigéJonathan CROUZET a rédigé
get.pm 5,14 Kio
package commands::get;
use strict;
use warnings;
use lib "$FindBin::Bin/lib/";
use utils::print;
use utils::db;
use commands::get::query;
our $irc;
our $log;
my %last_req;
my $dbh;
my $sth;
sub exec {
my ($kernel, $nick, $chan, $msg) = @_;
my $query = commands::get::query->new(
chan => $chan->[0],
query => ($msg) ? $msg : ''
);
my $content;
my $req;
my $rows;
if (not defined $last_req{$query->chan} or not ($query ~~ $last_req{$query->chan})) {
# we close a previous session if needed
if ($dbh) {
$sth->finish if $sth->{'Active'};
$dbh->commit;
$dbh->disconnect;
}
$dbh = utils::db::get_new_session;
my @words_param;
foreach (@{$query->words}) {
unshift @words_param, '%'.$_.'%';
}
my $words_sql;
foreach (@{$query->words}) {
$words_sql .= ' and ' if ($words_sql);
$words_sql .= "concat(sender, ' ', title) like ?";
}
if ($query->id >= 0) {
$sth = $dbh->prepare('select id, sender, title, url, duration
from playbot
where id = ?');
$sth->execute($query->id);
}
elsif (@{$query->tags}) {
my @where;
foreach my $tag (@{$query->tags}) {
unshift @where, 'p.id in (select pt.id from playbot_tags pt where pt.tag = ?)';
}
my $where = join ' and ' => @where;
if ($query->is_global) {
$req = 'select id, sender, title, url, duration
from playbot
where '.$where;