Changeset 416a7e5 for perl


Ignore:
Timestamp:
Aug 8, 2013, 3:14:44 PM (8 years ago)
Author:
Edward Z. Yang <ezyang@mit.edu>
Children:
b9766ea
Parents:
ecd4edf
git-author:
Alex Dehnert <adehnert@mit.edu> (10/02/11 15:38:25)
git-committer:
Edward Z. Yang <ezyang@mit.edu> (08/08/13 15:14:44)
Message:
Add command to get a buddy's status

This could be used by a user directly, though it's probably more likely
to be used by a module author of some sort.
File:
1 edited

Legend:

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

    r8258ea5 r416a7e5  
    171171our $showOffline = 0;
    172172
     173sub blist_getBuddyStatus {
     174    my $jid = shift;
     175    my $buddy = shift;
     176    my $roster = $conn->getRosterFromJID($jid);
     177    my %jq  = $roster->query($buddy);
     178    my $res = $roster->resource($buddy);
     179    if ($res) {
     180        my %rq = $roster->resourceQuery( $buddy, $res );
     181        return $rq{show} ? $rq{show} : 'online';
     182    } else {
     183        return "unknown";
     184    }
     185}
     186
    173187sub blist_listBuddy {
    174188    my $roster = shift;
     
    303317            summary => "Show your Jabber roster.",
    304318            usage   => "jlist"
     319        }
     320    );
     321    BarnOwl::new_command(
     322        jabber_get_buddy_status => \&cmd_jabber_get_buddy_status,
     323        {
     324            summary => "Get the status of a given buddy.",
     325            usage   => "jabber_get_buddy_status [-a account] buddy"
    305326        }
    306327    );
     
    859880}
    860881
     882sub cmd_jabber_get_buddy_status {
     883    my $cmd = shift;
     884    local @ARGV = @_;
     885    my $getopt = Getopt::Long::Parser->new;
     886    my ($jid, $buddy);
     887
     888    $getopt->configure('no_getopt_compat');
     889    $getopt->getoptions(
     890        'account=s' => \$jid,
     891    );
     892    $jid ||= defaultJID();
     893    if ($jid) {
     894        $jid = resolveConnectedJID($jid);
     895        return unless $jid;
     896    }
     897    else {
     898        die("You must specify an account with -a <jid>\n");
     899    }
     900    $buddy = shift @ARGV;
     901    if(!$buddy) {
     902        die("You must specify a JID to get the status of.\n");
     903    }
     904    my $buddy_jid = resolveDestJID($buddy, $jid);
     905    return blist_getBuddyStatus($jid, $buddy_jid);
     906}
     907
    861908
    862909sub jroster_sub {
     
    14911538}
    14921539
     1540sub complete_jabber_get_buddy_status {
     1541    my $ctx = shift;
     1542    return complete_flags($ctx,
     1543                          [qw()],
     1544                          {
     1545                              "-a" => \&complete_account,
     1546                          },
     1547                          \&complete_user_or_muc
     1548        );
     1549}
     1550
    14931551BarnOwl::Completion::register_completer(jwrite => sub { BarnOwl::Module::Jabber::complete_jwrite(@_) });
    14941552BarnOwl::Completion::register_completer(jabberlogout => sub { BarnOwl::Module::Jabber::complete_jabberlogout(@_) });
     1553BarnOwl::Completion::register_completer(jabber_get_buddy_status => sub { BarnOwl::Module::Jabber::complete_jabber_get_buddy_status(@_) });
    14951554
    149615551;
Note: See TracChangeset for help on using the changeset viewer.