3 # Copyright (c) 2012 ISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
4 # This program is covered by the GNU General Public License 2
6 package Mubot4FB::TweetWorker;
11 use base 'Mubot4FB::Common';
16 use Mubot4FB::DB::TweetMap;
20 $me->{mapdb} = Mubot4FB::DB::TweetMap->new($me->{cfg});
21 $me->{db} = Mubot4FB::DB->new($me->{cfg});
22 $me->{tw} = Mubot4FB::Tweet->new($me->{cfg});
29 return $args->{submitter} . '曰く、'.$args->{prefix}.' '.$args->{comment};
35 if ($job->{arg}->{command} eq 'remove') {
36 my $data = $me->{mapdb}->search_by_key_id({key_id => $job->{arg}->{fb_post_id}});
39 my $status = $me->{tw}->remove($data->{tweet_id});
40 warn Dumper($status) if ($me->{cfg}->{debug});
41 $me->{mapdb}->delete_map_by_key_id({key_id => $job->{arg}->{fb_post_id}}) if ($status);
44 my $data = $me->{db}->search_by_fb_post_id({fb_post_id => $job->{arg}->{fb_post_id}});
47 my $text = $me->compose_text($data);
48 my $uri = $me->post_uri($job->{arg}->{post_id});
49 my $status = $me->{tw}->publish($text, $uri);
50 warn Dumper($status) if ($me->{cfg}->{debug});
51 $me->{mapdb}->add_map({key_id => $job->{arg}->{fb_post_id},
52 tweet_id => $status->{id},
53 user_id => $status->{user}->{id},
54 screen_name => $status->{user}->{screen_name}}) if ($status);