source: perl/modules/Twitter/lib/BarnOwl/Module/Twitter/Completion.pm

release-1.7release-1.8release-1.9
Last change on this file was 47a5e46, checked in by Nelson Elhage <nelhage@mit.edu>, 11 years ago
Merge Twitter under perl/modules
  • Property mode set to 100644
File size: 1.5 KB
Line 
1use strict;
2use warnings;
3
4package BarnOwl::Module::Twitter::Completion;
5
6my %users;
7
8sub complete_account {
9    my @nicks = grep {defined} map {$_->nickname} @BarnOwl::Module::Twitter::twitter_handles;
10}
11
12sub complete_user {
13    my $service = shift;
14    if(!$service) {
15        return map {keys %$_} values %users;
16    }
17    return keys %{$users{$service} || {}};
18}
19
20sub on_message {
21    my $m = shift;
22    return unless $m->type eq 'Twitter';
23
24    $users{$m->service}{$m->recipient} = 1;
25    $users{$m->service}{$m->sender} = 1;
26}
27
28sub complete_twitter {
29    my $ctx = shift;
30    return unless $ctx->word == 1;
31    return complete_account();
32}
33
34sub complete_twitter_user_account {
35    my $ctx = shift;
36    if ($ctx->word == 1) {
37        my $nick = $ctx->words->[2];
38        if ($nick) {
39            my  @completions = eval {
40                complete_user(BarnOwl::Module::Twitter::find_account($nick)->{cfg}{service});
41            };
42            return @completions if (!$@);
43        }
44        return complete_user();
45    } elsif ($ctx->word == 2) {
46        return complete_account();
47    }
48}
49
50BarnOwl::Completion::register_completer('twitter' => \&complete_twitter);
51BarnOwl::Completion::register_completer('twitter-direct' => \&complete_twitter_user_account);
52BarnOwl::Completion::register_completer('twitter-atreply' => \&complete_twitter_user_account);
53BarnOwl::Completion::register_completer('twitter-unfollow' => \&complete_twitter_user_account);
54
55$BarnOwl::Hooks::newMessage->add("BarnOwl::Module::Twitter::Completion::on_message");
56
571;
Note: See TracBrowser for help on using the repository browser.