use strict;
use utf8;
+use base 'Mubot4FB::Common';
+
use Data::Dumper;
-use base 'TheSchwartz::Worker';
use Mubot4FB::Tweet;
-
-sub sighandler {
- warn "caught signal @_\n";
- no warnings 'redefine';
- *TheSchwartz::work_once = sub { exit };
+use Mubot4FB::DB::TweetMap;
+
+sub init {
+ my ($me) = @_;
+ $me->{mapdb} = Mubot4FB::DB::TweetMap->new($me->{cfg});
+ $me->{db} = Mubot4FB::DB->new($me->{cfg});
+ $me->{tw} = Mubot4FB::Tweet->new($me->{cfg});
+ return 1;
}
sub compose_text {
sub work {
my ($me, $job) = @_;
- $SIG{HUP} = $SIG{INT} = $SIG{TERM} = \&sighandler;
-
- if ($job ->arg->{_command} eq 'remove') {
+ if ($job->arg->{_command} eq 'remove') {
+ my $data = $me->{mapdb}->search_by_key_id({key_id => $job->{arg}->{fb_post_id}});
+ if ($data) {
+ my $status = $me->{tw}->remove($data->{tweet_id});
+ warn Dumper($status) if ($me->{cfg}->{debug});
+ $me->{mapdb}->delete_map_by_key_id({key_id => $job->{arg}->{fb_post_id}}) if ($status);
+ }
} else {
my $text = $me->compose_text($job->arg);
my $uri = $me->post_uri($job->{arg}->{post_id});
+
+ my $status = $me->{tw}->publish($text, $uri);
+ warn Dumper($status) if ($me->{cfg}->{debug});
+ $me->{mapdb}->add_map({key_id => $job->{arg}->{post_id},
+ tweet_id => $status->{id},
+ user_id => $status->{in_reply_to_status_id},
+ screen_name => $status->{in_reply_to_screen_name}}) if ($status);
}
$job->completed();
}
+
+1;