diff --git a/PlayBot.pl b/PlayBot.pl index d2c6129bac8f97a67197e7b8b8ceb9d0c999d6e4..a17d8a8e9ff152156bd2e6267d67474fc62088a6 100755 --- a/PlayBot.pl +++ b/PlayBot.pl @@ -266,61 +266,60 @@ sub on_speak my ($nick,$mask) = split(/!/,$user); my %content; - %content = sites::parser::parse($msg); + if (!commands::parser::exec(@args)) { + %content = sites::parser::parse($msg); - if ($@) { - $log->warning ($@); - return; - } - - if (%content) { - if ($debug) { - $log->debug($content{'url'}); - } - else { - # insertion de la vidéo dans la bdd - my $sth = $dbh->prepare_cached('INSERT INTO playbot (date, type, url, sender_irc, sender, title, chan) VALUES (NOW(),?,?,?,?,?,?)'); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute($content{'site'}, $content{'url'}, $nick, $content{'author'}, $content{'title'}, $chan->[0]) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - } - - # sélection de l'id de la vidéo insérée - my $id = $dbh->{mysql_insert_id}; - if (!$id) { - my $sth = $dbh->prepare_cached('SELECT id FROM playbot WHERE url = ?'); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute($content{'url'}) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - - $id = $sth->fetch->[0]; - } - $lastID = $id; - - - # insertion des éventuels tags - while ($msg =~ /#([a-zA-Z0-9_-]+)/g) { - if ($debug) { - $log->debug($1); - next; - } - - addTag ($lastID, $1); + if ($@) { + $log->warning ($@); + return; } - - # message sur irc - if (defined $content{'author'}) { - $irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}.' | '.$content{'author'}) ; - } - else { - $irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}) ; - } - } - else { - commands::parser::exec(@args); + if (%content) { + if ($debug) { + $log->debug($content{'url'}); + } + else { + # insertion de la vidéo dans la bdd + my $sth = $dbh->prepare_cached('INSERT INTO playbot (date, type, url, sender_irc, sender, title, chan) VALUES (NOW(),?,?,?,?,?,?)'); + $log->error("Couldn't prepare querie; aborting") unless (defined $sth); + + $sth->execute($content{'site'}, $content{'url'}, $nick, $content{'author'}, $content{'title'}, $chan->[0]) + or $log->error("Couldn't finish transaction: " . $dbh->errstr); + } + + # sélection de l'id de la vidéo insérée + my $id = $dbh->{mysql_insert_id}; + if (!$id) { + my $sth = $dbh->prepare_cached('SELECT id FROM playbot WHERE url = ?'); + $log->error("Couldn't prepare querie; aborting") unless (defined $sth); + + $sth->execute($content{'url'}) + or $log->error("Couldn't finish transaction: " . $dbh->errstr); + + $id = $sth->fetch->[0]; + } + $lastID = $id; + + + # insertion des éventuels tags + while ($msg =~ /#([a-zA-Z0-9_-]+)/g) { + if ($debug) { + $log->debug($1); + next; + } + + addTag ($lastID, $1); + } + + + # message sur irc + if (defined $content{'author'}) { + $irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}.' | '.$content{'author'}) ; + } + else { + $irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}) ; + } + } } } diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm index d18fa556847f0ccb02a691ce73e28509c41e253b..4194ff61ef5049928a01c74f8d6d69afed8c6db9 100644 --- a/lib/commands/parser.pm +++ b/lib/commands/parser.pm @@ -53,6 +53,11 @@ sub exec { $irc->yield(privmsg => $chan => '!later [<id>] [in <x>[s|m|h]] : vidéo rappelée par query (par défaut temps de 6h)'); $irc->yield(privmsg => $chan => 'Sans id précisée, la dernière vidéo postée est utilisée.'); } + else { + return 0; + } + + return 1; } 1;