Changeset 74c7a14


Ignore:
Timestamp:
Sep 19, 2011, 1:31:36 PM (10 years ago)
Author:
Edward Z. Yang <ezyang@mit.edu>
Children:
a2d682b
Parents:
1260a65
git-author:
Edward Z. Yang <ezyang@mit.edu> (07/30/11 23:27:31)
git-committer:
Edward Z. Yang <ezyang@mit.edu> (09/19/11 13:31:36)
Message:
Wordwrap, write the config, style wibbles.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Location:
perl/modules/Facebook/lib/BarnOwl/Module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/Facebook/lib/BarnOwl/Module/Facebook.pm

    r69066f6 r74c7a14  
    6161#BarnOwl::new_command('facebook-message' => \&cmd_facebook_direct, {
    6262#    summary     => 'Send a Facebook message',
    63 #    usage       => 'twitter-direct USER',
    64 #    description => 'Send a private Facebook Message to USER.'
     63#    usage       => 'facebook-message USER',
     64#    description => 'Send a private Facebook message to USER.'
    6565#});
    6666
     
    9393    BarnOwl::start_edit_win(
    9494        defined $user ? "Write something to $user..." : "What's on your mind?",
    95         sub{ $facebook_handle->facebook($user, shift) }
     95        sub { $facebook_handle->facebook($user, shift) }
    9696    );
    9797}
     
    132132sub check_ready {
    133133    if (!$facebook_handle->{logged_in}) {
    134         BarnOwl::message("Need to login to Facebook first with ':facebook-auth'.");
     134        BarnOwl::message("You need to login to Facebook first with ':facebook-auth'.");
    135135        return 0;
    136136    }
     
    139139
    140140BarnOwl::filter(qw{facebook type ^facebook$});
     141BarnOwl::bindkey(qw(recv f command facebook));
    141142
    142143sub complete_user { return keys %{$facebook_handle->{friends}}; }
  • perl/modules/Facebook/lib/BarnOwl/Module/Facebook/Handle.pm

    r0b372aa r74c7a14  
    2626        my @words = split(' ', lc($sentence));
    2727        return () unless @words;
    28         return (reduce{ length($a) > length($b) ? $a : $b } @words,);
     28        return (reduce { length($a) > length($b) ? $a : $b } @words);
    2929    };
    3030} else {
     
    7171
    7272    my $self = {
    73         'cfg'  => $cfg,
     73        'cfg' => $cfg,
    7474        'facebook' => undef,
    7575
     
    238238    return unless $self->{logged_in};
    239239
    240     # XXX Oh no! This blocks the user interface.  Not good.
    241     # Ideally, we should have some worker thread for polling facebook.
    242     # But BarnOwl is probably not thread-safe >_<
    243 
    244240    my $old_topics = $self->{topics};
    245241    $self->{topics} = {};
     
    289285            }
    290286
     287            # XXX The intent is to get the 'Comment' link, which also
     288            # serves as a canonical link to the post.  The {name}
     289            # field should equal 'Comment'.  But we don't check
     290            # this, we assume that the first element is the right one.
    291291            my $link = $post->{actions}[0]{link};
    292292
     
    294294            my $created_time = str2time($post->{created_time});
    295295            if ($created_time >= $self->{last_poll}) {
    296                 # XXX indexing is fragile
    297296                my $msg = BarnOwl::Message->new(
    298297                    type      => 'Facebook',
     
    302301                    name_id   => $name_id,
    303302                    direction => 'in',
    304                     body      => $self->format_body($post),
     303                    body      => wordwrap($self->format_body($post)),
    305304                    post_id   => $post_id,
    306305                    topic     => $topic,
    307306                    time      => asctime(localtime $created_time),
    308                     # XXX The intent is to get the 'Comment' link, which also
    309                     # serves as a canonical link to the post.  The {name}
    310                     # field should equal 'Comment'.
    311307                    permalink => $link,
    312308                   );
     
    331327                        name_id   => $name_id,
    332328                        direction => 'in',
    333                         body      => $comment->{message},
     329                        body      => wordwrap($comment->{message}),
    334330                        post_id   => $post_id,
    335331                        topic     => $topic,
     
    348344        $self->{last_poll} = $new_last_poll;
    349345    });
     346}
     347
     348sub wordwrap {
     349    my $text = shift;
     350    return BarnOwl::wordwrap($text, BarnOwl::getvar('edit:maxwrapcols'));
    350351}
    351352
     
    431432    $self->facebook_do_auth(sub {
    432433        my $raw_cfg = to_json($self->{cfg});
    433         BarnOwl::admin_message('Facebook', "Add this as the contents of your ~/.owl/facebook file:\n$raw_cfg");
     434        my $cfg_file;
     435        unless (open($cfg_file, ">", BarnOwl::get_config_dir() . "/facebook")) {
     436          BarnOwl::admin_message('Facebook', "Add this as the contents of your ~/.owl/facebook file:\n$raw_cfg");
     437          return;
     438        }
     439        print $cfg_file $raw_cfg;
     440        close $cfg_file;
     441        BarnOwl::admin_message('Facebook', "Saved your login credentials to ~/.owl/facebook.");
    434442    });
    435443    return;
Note: See TracChangeset for help on using the changeset viewer.