Changeset 6df381b


Ignore:
Timestamp:
Nov 9, 2006, 11:40:50 PM (17 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
a55abb3
Parents:
960395d
git-author:
Nelson Elhage <nelhage@mit.edu> (11/09/06 23:40:36)
git-committer:
Nelson Elhage <nelhage@mit.edu> (11/09/06 23:40:50)
Message:
Refactoring jmuc somewhat. Also, @ARGV refers to @::ARGV by default
(see perlmod), so changing to use that, since it looks nicer.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/jabber.pl

    r960395d r6df381b  
    188188    my ($server, $port) = getServerFromJID($jid);
    189189
    190     $connections->{$jidStr}->{client} = Net::Jabber::Client->new();
     190    $connections->{$jidStr}->{client} = Net::Jabber::Client->new(debuglevel => owl::getvar('debug') eq 'on' ? 1 : 0,
     191                                                                 debugfile  => 'jabber.log');
    191192    my $client = \$connections->{$jidStr}->{client};
    192193    $connections->{$jidStr}->{roster} = $connections->{$jidStr}->{client}->Roster();
     
    413414sub cmd_jmuc
    414415{
    415     if (!connected())
    416     {
    417         owl::error("You are not logged in to Jabber.");
    418         return;
    419     }
     416        if (!connected())
     417                {
     418                        owl::error("You are not logged in to Jabber.");
     419                        return;
     420                }
    420421   
    421     my $ocmd = shift;
    422     my $cmd = shift;   
    423     if (!$cmd)
    424     {
    425         #XXX TODO: Write general usage for jmuc command.
    426         return;
    427     }
    428 
    429     if ($cmd eq 'join')
    430     {
    431         local @::ARGV = @_;
     422        my $ocmd = shift;
     423        my $cmd = shift;   
     424        if (!$cmd)
     425        {
     426                #XXX TODO: Write general usage for jmuc command.
     427                return;
     428        }
     429
     430        my %jmuc_commands = (
     431                join => \&jmuc_join,
     432                part => \&jmuc_part,
     433                invite => \&jmuc_invite
     434               );
     435        my $func = $jmuc_commands{$cmd};
     436        if(!$func) {
     437                owl::error("jmuc: Unknown command: $cmd");
     438        } else {
     439                return $func->(@_);
     440        }
     441}
     442
     443sub jmuc_join {
     444        local @ARGV = @_;
    432445        my $password;
    433446        my $jid;
     
    436449
    437450        my $muc;
    438         if (scalar @::ARGV != 1)
     451        if (scalar @ARGV != 1)
    439452        {
    440453            owl::error('Usage: jmuc join {muc} [-p password] [-a account]');
     
    443456        else
    444457        {
    445             $muc = @::ARGV[0];
     458            $muc = @ARGV[0];
    446459        }
    447460
     
    477490        $presence->AddX($x);
    478491        $connections->{$jid}->{client}->Send($presence);
    479     }
    480     elsif ($cmd eq 'part')
    481     {
     492}
     493
     494sub jmuc_part {
    482495        my $muc;
    483496        my $jid;
     
    498511        else
    499512        {
    500             local @::ARGV = @_;
     513            local @ARGV = @_;
    501514            GetOptions('account=s' => \$jid);
    502             if (scalar @::ARGV != 1)
     515            if (scalar @ARGV != 1)
    503516            {
    504517                owl::error('Usage: jmuc part {muc} [-a account]');
     
    507520            else
    508521            {
    509                 $muc = @::ARGV[0];
     522                $muc = @ARGV[0];
    510523            }
    511524            if (!$jid)
     
    529542        $connections->{$jid}->{client}->PresenceSend(to => $muc, type => 'unavailable');
    530543        queue_admin_msg("$jid has left $muc.");
    531     }
    532     elsif ($cmd eq 'invite')
    533     {
     544}
     545
     546sub jmuc_invite
     547{
    534548        my $jid;
    535549        my $invite_jid;
     
    555569        else
    556570        {
    557             local @::ARGV = @_;
     571            local @ARGV = @_;
    558572            GetOptions('account=s' => \$jid);
    559             if (scalar @::ARGV != 2)
     573            if (scalar @ARGV != 2)
    560574            {
    561575                owl::error('Usage: jmuc invite {jid} [muc] [-a account]');
     
    564578            else
    565579            {
    566                 ($muc, $invite_jid) = @::ARGV;
     580                ($muc, $invite_jid) = @ARGV;
    567581            }
    568582            if (!$jid)
     
    594608        $connections->{$jid}->{client}->Send($message);
    595609        queue_admin_msg("$jid has invited $invite_jid to $muc.");
    596     }
    597     else
    598     {
    599         owl::error('jmuc: unrecognized command.');
    600     }
    601     return "";
    602 }
     610}
     611
    603612
    604613################################################################################
Note: See TracChangeset for help on using the changeset viewer.