OSDN Git Service

Merge branch 'master' into splitfb
authorISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
Sat, 20 Oct 2012 21:34:25 +0000 (06:34 +0900)
committerISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
Sat, 20 Oct 2012 21:34:25 +0000 (06:34 +0900)
Conflicts:
mubot4fb.pl

1  2 
mubot4fb.pl

diff --cc mubot4fb.pl
@@@ -44,50 -43,6 +44,51 @@@ sub init 
        return $me->{fbo} = Facebook::Graph->new(access_token => $page_access_token);
  }
  
-       my $req = HTTP::Request::Common::DELETE($me->post_uri($post_id));
 +sub publish {
 +      my ($me, $text, $uri) = @_;
 +
 +      return $me->{fbo}->add_post($me->{cfg}->{fb_page_id})
 +          ->set_message($text)
 +          ->set_link_uri($uri)
 +          ->publish()
 +          ->as_hashref();
 +}
 +
 +sub post_uri {
 +      my ($me, $post_id) = @_;
 +
 +      return $me->{cfg}->{fb_page_url} . 'posts/' . $post_id;
 +}
 +
 +sub remove {
 +      my ($me, $post_id) = @_;
 +
++      my $uri = $fb->query->find($post_id)->uri_as_string;
++      my $req = HTTP::Request::Common::DELETE($uri);
 +      $req->header('Content-Length', 0);
 +      my $resp;
 +      eval{$resp = LWP::UserAgent->new->request($req)};
 +      return !$@;
 +}
 +
 +1;
 +package Mubot4FB;
 +
 +use strict;
 +use utf8;
 +
 +use base 'Bot::BasicBot';
 +use Facebook::Graph;
 +use LWP::UserAgent;
 +use HTTP::Request::Common;
 +use DBI qw/:sql_types/;
 +use POSIX 'strftime';
 +
 +use Data::Dumper;
 +
 +my $mu_re = qr/^([^\s]+)\s+((?:https?|ftps?):\/\/[^\s]+)\s+(.+)$/i;
 +my $irc_type = 1;
 +
  sub db_init {
        my ($me) = @_;
        $me->{dbh} = DBI->connect('DBI:mysql:'.$me->{cfg}->{database}, $me->{cfg}->{db_user}, $me->{cfg}->{db_pass},{mysql_enable_utf8 => 1}) || die $DBI::errstr;