Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found

Cible

Sélectionner le projet cible
  • morignot2011/playbot.old
  • defrance2011/playbot
2 résultats
Afficher les modifications
Validations sur la source (5)
......@@ -256,6 +256,30 @@ sub on_invite {
push @channels, $chan;
}
sub external_parse {
my ( $user, $chan, $msg ) = @_;
$msg =~ tr/'"/_/;
my $content = `./PlayBot-cli '$chan' '$user' '$msg'`;
if ( $? >> 8 != 0 ) {
die "Error";
}
my ( $id, $external_id, $url, $title, $author, $duration ) =
split( /\n/, $content );
return (
id => $id,
author => $author,
external_id => $external_id,
duration => $duration,
playlist => 0,
site => 'soundcloud',
title => $title,
url => $url,
);
}
# Quand un user parle
sub on_speak {
my ( $kernel, $user, $chan, $msg ) = @_[ KERNEL, ARG0, ARG1, ARG2 ];
......@@ -264,18 +288,25 @@ sub on_speak {
my ( $nick, $mask ) = split( /!/, $user );
my %content;
# first we check for url
my @processed_str = PlayBot::sites::parse(@args);
# and we check for command
my $cmd = ( split /\s/, $msg )[0];
if ( $cmd eq "!fav" ) {
@args = ( $kernel, $user, lc $chan->[0], $cmd );
}
else {
@args = ( $kernel, $user, lc $chan->[0], $msg );
eval {
%content = external_parse($nick, lc $chan->[0], $msg);
$irc->yield(
privmsg => $chan => PlayBot::utils::print::print(\%content) );
};
if ($@) {
# first we check for url
PlayBot::sites::parse(@args);
# and we check for command
my $cmd = ( split /\s/, $msg )[0];
if ( $cmd eq "!fav" ) {
@args = ( $kernel, $user, lc $chan->[0], $cmd );
}
else {
@args = ( $kernel, $user, lc $chan->[0], $msg );
}
PlayBot::commands::parser::exec(@args);
}
PlayBot::commands::parser::exec(@args);
}
1;
......@@ -22,28 +22,6 @@ our $log;
our $regex;
our $playbot_api_key;
sub external_parse {
my $url = shift;
my $content = `./PlayBot.go "$url"`;
if ( $? >> 8 != 0 ) {
die "Error";
}
my ( $matched_url, $external_id, $url, $title, $author, $duration ) =
split( /\n/, $content );
return (
author => $author,
external_id => $external_id,
duration => $duration,
matched_url => $matched_url,
playlist => 0,
site => 'soundcloud',
title => $title,
url => $url,
);
}
sub parse {
my ( $kernel, $user, $chan, $msg, $playlist ) = @_;
......@@ -56,39 +34,33 @@ sub parse {
my $matching_url;
my @matching_tags;
eval { %content = external_parse($msg) };
if ($@) {
# parsing
foreach my $site ( __PACKAGE__->sites ) {
if ( not grep { $site eq "PlayBot::sites::$_" } @{ $chan_conf->sites } ) {
next;
}
my @args;
if ( @args = ( $msg =~ $site->regex ) ) {
eval { %content = $site->get(@args) };
$matching_url = $&;
$content{playlist} = 0;
last;
}
elsif ( $site->can('regex_playlist')
and @args = ( $msg =~ $site->regex_playlist ) )
{
eval { %content = $site->get_playlist(@args) };
$matching_url = $&;
$content{playlist} = 1;
last;
}
# parsing
foreach my $site ( __PACKAGE__->sites ) {
if ( not grep { $site eq "PlayBot::sites::$_" } @{ $chan_conf->sites } ) {
next;
}
# something goes wrong ?
if ($@) {
$log->warning($@);
return;
my @args;
if ( @args = ( $msg =~ $site->regex ) ) {
eval { %content = $site->get(@args) };
$matching_url = $&;
$content{playlist} = 0;
last;
}
elsif ( $site->can('regex_playlist')
and @args = ( $msg =~ $site->regex_playlist ) )
{
eval { %content = $site->get_playlist(@args) };
$matching_url = $&;
$content{playlist} = 1;
last;
}
} else {
$matching_url = $content{matched_url};
delete $content{matched_url};
}
# something goes wrong ?
if ($@) {
$log->warning($@);
return;
}
my $id;
......