diff --git a/PlayBot/sessions/irc.pm b/PlayBot/sessions/irc.pm index c0f9b53035f863fd17317c18990e7f47c61b78e7..1df7d1fdb48978b9a439c45c6ba602855f5abd3a 100644 --- a/PlayBot/sessions/irc.pm +++ b/PlayBot/sessions/irc.pm @@ -256,6 +256,29 @@ sub on_invite { push @channels, $chan; } +sub external_parse { + my ( $user, $chan, $msg ) = shift; + + my $content = `./PlayBot-cli "$user" "$chan" "$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 +287,25 @@ sub on_speak { my ( $nick, $mask ) = split( /!/, $user ); my %content; - # 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 ); + eval { + %content = external_parse($user, lc $chan->[0], $msg); + $irc->yield( + privmsg => $chan => PlayBot::utils::print::print($content) ); } - else { - @args = ( $kernel, $user, lc $chan->[0], $msg ); + 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;