Index: perl/modules/jabber.pl
===================================================================
--- perl/modules/jabber.pl	(revision 6df381bf053dab803b59e4204a4827dace2b9e97)
+++ perl/modules/jabber.pl	(revision 9f183ff9cb87932ca130a39424a4d37e77ee85d6)
@@ -1,3 +1,6 @@
 package owl_jabber;
+use warnings;
+use strict;
+
 use Authen::SASL qw(Perl);
 use Net::Jabber;
@@ -38,4 +41,5 @@
     }
 }
+
 push @::onStartSubs, sub { owl_jabber::onStart(@_) };
 
@@ -221,5 +225,5 @@
     if($result[0] ne 'ok') 
     {
-	if ($result[1] = "401")
+	if ($result[1] == 401)
 	{
 	    $vars{jlogin_jid} = $jidStr;
@@ -316,5 +320,5 @@
 	else
 	{
-	    if ($_[1] = '-a') #All accounts.
+	    if ($_[1] eq '-a') #All accounts.
 	    {
 		foreach my $jid (keys %$connections)
@@ -364,5 +368,5 @@
     my @args = @_;
     shift;
-    local @::ARGV = @_;
+    local @ARGV = @_;
     my $gc;
     GetOptions('thread=s' => \$jwrite_thread,
@@ -372,5 +376,5 @@
     $jwrite_type = 'groupchat' if $gc;
 
-    if (scalar @::ARGV != 1)
+    if (scalar @ARGV != 1)
     {
         owl::error("Usage: jwrite JID [-g] [-t thread] [-s 'subject'] [-a account]");
@@ -379,5 +383,5 @@
     else
     {
-	$jwrite_to = @::ARGV[0];
+	    $jwrite_to = shift @ARGV;
     }
 
@@ -410,14 +414,7 @@
 }
 
-#XXX Todo: Split off sub-commands into their own subroutines.
-# It'll make them more managable.
 sub cmd_jmuc
 {
-	if (!connected())
-		{
-			owl::error("You are not logged in to Jabber.");
-			return;
-		}
-    
+	die "You are not logged in to Jabber" unless connected();
 	my $ocmd = shift;
 	my $cmd = shift;    
@@ -429,51 +426,47 @@
 
 	my %jmuc_commands = (
-		join => \&jmuc_join,
-		part => \&jmuc_part,
-		invite => \&jmuc_invite
+		join   => \&jmuc_join,
+		part   => \&jmuc_part,
+		invite => \&jmuc_invite,
+		configure => \&jmuc_configure
 	       );
 	my $func = $jmuc_commands{$cmd};
 	if(!$func) {
 		owl::error("jmuc: Unknown command: $cmd");
-	} else {
-		return $func->(@_);
+		return;
+	}
+
+	{
+		local @ARGV = @_;
+		my $jid;
+		my $muc;
+		my $m = owl::getcurmsg();
+		if ($m->is_jabber && $m->{jtype} eq 'groupchat')
+		{
+			$muc = $m->{room};
+			$jid = $m->{to};
+		}
+
+		my $getopt = Getopt::Long::Parser->new;
+		$getopt->configure('pass_through');
+		$getopt->getoptions('account=s' => \$jid);
+		$jid ||= defaultJID();
+		if($jid) {
+			$jid = resolveJID($jid);
+			return unless $jid;
+		} else {
+			owl::error('You must specify an account with -a {jid}');
+		}
+		return $func->($jid, $muc, @ARGV);
 	}
 }
 
 sub jmuc_join {
-	local @ARGV = @_;
+	my ($jid, $muc, @args) = @_;
+	local @ARGV = @args;
 	my $password;
-	my $jid;
-	GetOptions('password=s' => \$password,
-		   'account=s' => \$jid);
-
-	my $muc;
-	if (scalar @ARGV != 1)
-	{
-	    owl::error('Usage: jmuc join {muc} [-p password] [-a account]');
-	    return;
-	}
-	else
-	{
-	    $muc = @ARGV[0];
-	}
-
-	if (!$jid)
-	{
-	    if (connected() == 1)
-	    {
-		$jid = (keys %$connections)[0];
-	    }
-	    else
-	    {
-		owl::error("Please specify an account with -a {jid}");
-		return;
-	    }
-	}
-	else
-	{
-	    $jid = resolveJID($jid);
-	    return unless $jid;
-	}
+	GetOptions('password=s' => \$password);
+
+	$muc = shift @ARGV or die("Usage: jmuc join {muc} [-p password] [-a account]");
 
 	my $x = new XML::Stream::Node('x');
@@ -481,7 +474,7 @@
 	$x->add_child('history')->put_attrib(maxchars => '0');
 	
-	if ($jmuc_password)
-	{
-	    $x->add_child('password')->add_cdata($jmuc_password);
+	if ($password)
+	{
+	    $x->add_child('password')->add_cdata($password);
 	}
 
@@ -493,51 +486,9 @@
 
 sub jmuc_part {
-	my $muc;
-	my $jid;
-	if (!$_[0])
-	{
-	    my $m = owl::getcurmsg();
-	    if ($m->is_jabber && $m->{jtype} eq 'groupchat')
-	    {
-		$muc = $m->{room};
-		$jid = $m->{to};
-	    }
-	    else
-	    {
-		owl::error('Usage: jmuc part {muc} [-a account]');
-	        return;
-	    }
-	}
-	else
-	{
-	    local @ARGV = @_;
-	    GetOptions('account=s' => \$jid);
-	    if (scalar @ARGV != 1)
-	    {
-		owl::error('Usage: jmuc part {muc} [-a account]');
-		return;
-	    }
-	    else
-	    {
-		$muc = @ARGV[0];
-	    }
-	    if (!$jid)
-	    {
-		if (connected() == 1)
-		{
-		    $jid = (keys %$connections)[0];
-		}
-		else
-		{
-		    owl::error("Please specify an account with -a {jid}");
-		    return;
-		}
-	    }
-	    else
-	    {
-		$jid = resolveJID($jid);
-		return unless $jid;
-	    }
-	}
+	my ($jid, $muc, @args) = @_;
+
+	$muc = shift @args if scalar @args;
+	die("Usage: jmuc part {muc} [-a account]") unless $muc;
+
 	$connections->{$jid}->{client}->PresenceSend(to => $muc, type => 'unavailable');
 	queue_admin_msg("$jid has left $muc.");
@@ -546,56 +497,10 @@
 sub jmuc_invite
 {
-	my $jid;
-	my $invite_jid;
-	my $muc;
-
-	owl::error('Usage: jmuc invite {jid} [muc] [-a account]') if (!$_[0]);
-	$invite_jid = $_[0];
-	
-	if (!@_[1])
-	{  	
-	    my $m = owl::getcurmsg();
-	    if ($m->is_jabber && $m->{jtype} eq 'groupchat')
-	    {
-		$muc = $m->{room};
-		$jid = $m->{to};
-	    }
-	    else
-	    {
-		owl::error('Usage: jmuc invite {jid} [muc] [-a account]');
-	        return;
-	    }
-	}
-	else
-	{
-	    local @ARGV = @_;
-	    GetOptions('account=s' => \$jid);
-	    if (scalar @ARGV != 2)
-	    {
-		owl::error('Usage: jmuc invite {jid} [muc] [-a account]');
-		return;
-	    }
-	    else
-	    {
-		($muc, $invite_jid) = @ARGV;
-	    }
-	    if (!$jid)
-	    {
-		if (connected() == 1)
-		{
-		    $jid = (keys %$connections)[0];
-		}
-		else
-		{
-		    owl::error("Please specify an account with -a {jid}");
-		    return;
-		}
-	    }
-	    else
-	    {
-		$jid = resolveJID($jid);
-		return unless $jid;
-	    }
-	}
+	my ($jid, $muc, @args) = @_;
+
+	my $invite_jid = shift @args;
+	$muc = shift @args if scalar @args;
+
+	die('Usage: jmuc invite {jid} [muc] [-a account]') unless $muc && $invite_jid;
 	
 	my $x = new XML::Stream::Node('x');
@@ -608,4 +513,24 @@
 	$connections->{$jid}->{client}->Send($message);
 	queue_admin_msg("$jid has invited $invite_jid to $muc.");
+}
+
+Net::Jabber::Namespaces::add_ns(
+	ns  => "http://jabber.org/protocol/muc#owner",
+	tag => 'query',
+       );
+
+sub jmuc_configure {
+	my ($jid, $muc, @args) = @_;
+	$muc = shift @args if scalar @args;
+	die("Usage: jmuc configure [muc]") unless $muc;
+	my $iq = Net::Jabber::IQ->new();
+	$iq->SetTo($muc);
+	$iq->SetType('set');
+	my $query = $iq->NewQuery("http://jabber.org/protocol/muc#owner");
+	my $x = $query->NewChild("jabber:x:data");
+	$x->SetType('submit');
+
+	$connections->{$jid}->{client}->Send($iq);
+	queue_admin_msg("Accepted default instant configuration for $muc");
 }
 
@@ -776,5 +701,5 @@
 sub boldify($)
 {
-    $str = shift;
+    my $str = shift;
 
     return '@b('.$str.')' if ( $str !~ /\)/ );
@@ -807,4 +732,9 @@
 {
     return scalar keys %$connections;
+}
+
+sub defaultJID {
+	return (keys %$connections)[0]	if (connected() == 1);
+	return;
 }
 
