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

Seperate sites.pm into reusable functions

parent 79d9ca3b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -16,14 +16,12 @@ our $regex; ...@@ -16,14 +16,12 @@ our $regex;
sub parse { sub parse {
my ($kernel, $user, $chan, $msg) = @_; my ($kernel, $user, $chan, $msg, $playlist) = @_;
my ($nick,$mask) = split(/!/,$user); my ($nick,$mask) = split(/!/,$user);
my $chan_conf = PlayBot::utils::db::chan->new($chan); my $chan_conf = PlayBot::utils::db::chan->new($chan);
my %content; my %content;
my $id;
my $dbh = PlayBot::utils::db::main_session();
my $matching_url; my $matching_url;
my @matching_tags; my @matching_tags;
...@@ -49,6 +47,21 @@ sub parse { ...@@ -49,6 +47,21 @@ sub parse {
# if we get a new content, we must save it # if we get a new content, we must save it
if (%content) { if (%content) {
@matching_tags = insert_content($kernel, $nick, $chan, \%content, $msg);
}
return (
$matching_url,
@matching_tags
);
}
sub insert_content
{
my ($kernel, $nick, $chan, $content, $msg) = @_;
my $dbh = PlayBot::utils::db::main_session();
my $id;
# we assume it's a new content # we assume it's a new content
my $new = 1; my $new = 1;
...@@ -61,11 +74,11 @@ sub parse { ...@@ -61,11 +74,11 @@ sub parse {
$log->error("Couldn't prepare querie; aborting") unless (defined $sth); $log->error("Couldn't prepare querie; aborting") unless (defined $sth);
$sth->execute( $sth->execute(
$content{'site'}, $content->{'site'},
$content{'url'}, $content->{'url'},
$content{'author'}, $content->{'author'},
$content{'title'}, $content->{'title'},
$content{'duration'} $content->{'duration'}
); );
}; };
if ($@) { if ($@) {
...@@ -82,10 +95,10 @@ sub parse { ...@@ -82,10 +95,10 @@ sub parse {
$log->error("Couldn't prepare querie; aborting") unless (defined $sth); $log->error("Couldn't prepare querie; aborting") unless (defined $sth);
$sth->execute( $sth->execute(
$content{'author'}, $content->{'author'},
$content{'title'}, $content->{'title'},
$content{'duration'}, $content->{'duration'},
$content{'url'}, $content->{'url'},
); );
} }
...@@ -93,7 +106,7 @@ sub parse { ...@@ -93,7 +106,7 @@ sub parse {
my $sth = $dbh->prepare('SELECT id FROM playbot WHERE url = ?'); my $sth = $dbh->prepare('SELECT id FROM playbot WHERE url = ?');
$log->error("Couldn't prepare querie; aborting") unless (defined $sth); $log->error("Couldn't prepare querie; aborting") unless (defined $sth);
$sth->execute($content{'url'}) $sth->execute($content->{'url'})
or $log->error("Couldn't finish transaction: " . $dbh->errstr); or $log->error("Couldn't finish transaction: " . $dbh->errstr);
$id = $sth->fetch->[0]; $id = $sth->fetch->[0];
...@@ -109,7 +122,7 @@ sub parse { ...@@ -109,7 +122,7 @@ sub parse {
$dbh->commit; $dbh->commit;
@matching_tags = PlayBot::commands::parser::tag($msg, $chan); my @matching_tags = PlayBot::commands::parser::tag($msg, $chan);
my @tags; my @tags;
# get tags # get tags
...@@ -128,24 +141,20 @@ sub parse { ...@@ -128,24 +141,20 @@ sub parse {
if ($new) { if ($new) {
# schedule download # schedule download
$kernel->post('downloader' => 'ddl' => $id, $content{url}); $kernel->post('downloader' => 'ddl' => $id, $content->{url});
$content{'id'} = '+'.$id; $content->{'id'} = '+'.$id;
} }
else { else {
$content{'id'} = $id; $content->{'id'} = $id;
} }
$content{'tags'} = \@tags; $content->{'tags'} = \@tags;
delete $content{'url'}; delete $content->{'url'};
# message sur irc # message sur irc
$irc->yield(privmsg => $chan => PlayBot::utils::print::print(\%content)); $irc->yield(privmsg => $chan => PlayBot::utils::print::print($content));
}
return ( return @matching_tags;
$matching_url,
@matching_tags
);
} }
1; 1;
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