Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 23cef9f42fdaa2b5c036a4c4641f2acefd7bfed7
  • develop par défaut protégée
  • implement-discord-markdown-update
  • matrix-attachments-order-fix
  • fix-oversized-file-transfer
  • matrix-attachment-order-fix
  • matrix-answer-modified-fix
  • cherry-pick-moise
8 résultats

Dockerfile

Blame
  • Bifurcation depuis ARISE / matrix-appservice-discord
    Le projet source a une visibilité limitée.
    facebook.pm 1,22 Kio
    package PlayBot::sites::facebook;
    
    use strict;
    use warnings;
    
    use LWP::UserAgent;
    use JSON;
    use FindBin;
    
    my $conf;
    my $endpoint = "https://graph.facebook.com/v2.5/";
    
    BEGIN {
        chdir "$FindBin::Bin/";
        local $/;
        open CONF, '<', 'playbot.conf';
        my $json = <CONF>;
        $conf = decode_json($json);
    }
    
    sub regex
    {
        return qr#(?:^|[^!])https?://(?:www.|)facebook.com/(?:video.php\?v=|.*/videos/)([a-zA-Z0-9_-]+)#;
    }
    
    sub get {
        shift;
    	my $id = shift;
    	
        my $ua = LWP::UserAgent->new(
            timeout     => 30,
            env_proxy   => 1,
        );
    	my $response = $ua->get($endpoint
            .$id
    		.'?access_token='.$conf->{'facebook_access_token'}
    		.'&fields=title,from,permalink_url,length');
    	die($response->status_line) unless ($response->is_success);
    
    	my $content = decode_json($response->decoded_content);
    
        die "Fuck Facebook." if (exists $content->{'error'} );
        
        my %infos;
    
        $infos{'title'} = $content->{'title'};
    	if (!exists $content->{'title'}) {
    		$infos{'title'} = 'Untitled';
    	}
        $infos{'duration'} = $content->{'length'};
    	$infos{'site'} = 'facebook';
        $infos{'url'} = 'https://www.facebook.com'.$content->{'permalink_url'};
        $infos{'author'} = $content->{'from'}->{'name'};
    
    	return %infos;
    }
    
    1;