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

trying to do a less shit with the db

parent a20d1bb2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -144,7 +144,6 @@ sub setConf
{
commands::parser::setConf($irc, $dbh, $log, \%lastID);
$sites::parser::dbh = $dbh;
$sites::parser::irc = $irc;
$sites::parser::log = $log;
}
......@@ -288,15 +287,7 @@ sub on_speak
# first we test if it's a command
if (!commands::parser::exec(@args)) {
# if not, maybe there is an url we can parse
my $id = sites::parser::parse(@args);
# if there is a new content, there is a new id to save
if ($id) {
$lastID{$chan->[0]} = $id;
# we insert the potiential tags
commands::parser::tag($msg, $chan);
}
sites::parser::parse(@args);
}
}
......
......@@ -8,10 +8,11 @@ use zippy;
use dailymotion;
use lib "$FindBin::Bin/lib/";
use utils::db;
use utils::print;
use commands::parser;
our $irc;
our $dbh;
our $log;
sub parse {
......@@ -20,6 +21,7 @@ sub parse {
my %content;
my $id;
my $dbh = utils::db::main_session();
# parsing
if ($msg =~ m#(?:^|[^!])https?://(?:www.youtube.com/watch\?[a-zA-Z0-9_=&-]*v=|youtu.be/)([a-zA-Z0-9_-]+)#) {
......@@ -73,11 +75,14 @@ sub parse {
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
}
my @tags;
# sélection de l'id de la vidéo insérée
$id = $sth->{mysql_insertid};
if (!$id) {
# la vido avait déjà été insérée
# L'état de la bdd est stable (puisqu'on a en fait rien fait),
# on peut commiter.
$dbh->commit;
my $sth = $dbh->prepare_cached('SELECT id FROM playbot WHERE url = ?');
$log->error("Couldn't prepare querie; aborting") unless (defined $sth);
......@@ -87,6 +92,21 @@ sub parse {
$id = $sth->fetch->[0];
}
# insertion du chan
my $sth = $dbh->prepare_cached('
INSERT INTO playbot_chan (content, chan, sender_irc)
VALUES (?,?,?)');
$log->error("Couldn't prepare querie; aborting") unless (defined $sth);
$sth->execute($id, $chan->[0], $nick)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
# in all cases, we commit now
$dbh->commit;
commands::parser::tag($msg, $chan);
my @tags;
# get tags
$sth = $dbh->prepare("select tag
from playbot_tags
......@@ -99,15 +119,7 @@ sub parse {
$tag =~ s/([a-zA-Z0-9_-]+)/#$1/;
push @tags, $tag;
}
# insertion du chan
my $sth = $dbh->prepare_cached('
INSERT INTO playbot_chan (content, chan, sender_irc)
VALUES (?,?,?)');
$log->error("Couldn't prepare querie; aborting") unless (defined $sth);
$sth->execute($id, $chan->[0], $nick)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
$dbh->commit;
# message sur irc
$content{'id'} = $id;
......
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