[vhffs-dev] [1916] Merge fetchuser and fetchgroup to fetch on modobot

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1916
Author:   misric
Date:     2012-01-04 00:19:41 +0100 (Wed, 04 Jan 2012)
Log Message:
-----------
Merge fetchuser and fetchgroup to fetch on modobot

Modified Paths:
--------------
    trunk/vhffs-irc/modobot.pl

Modified: trunk/vhffs-irc/modobot.pl
===================================================================
--- trunk/vhffs-irc/modobot.pl	2012-01-03 18:18:50 UTC (rev 1915)
+++ trunk/vhffs-irc/modobot.pl	2012-01-03 23:19:41 UTC (rev 1916)
@@ -390,16 +390,30 @@
 	irc_msg( $list );
 }
 
-sub fetch_user
+sub fetch
 {
-        my $username = shift;
-        my $user = Vhffs::User::get_by_username( $vhffs , $username );
+        my $name = shift;
+        my $user = Vhffs::User::get_by_username( $vhffs , $name );
         unless( defined $user )
         {
-                irc_msg ($username.' : No such user');
-                return;
-        }
+               my $group = Vhffs::Group::get_by_groupname( $vhffs , $name );
+               unless( defined $group )
+               {
+               		irc_msg ($name.' : No such user or group');
+                        return;
+		}
 
+	        my $objects = Vhffs::Group::getall_objects( $group );
+	        my $list = '';
+
+	        foreach my $obj ( @{$objects} )
+        	{
+               		my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $obj->{object_id} );
+               		$list .= '[ '.Vhffs::Functions::type_string_from_type_id( $object->{type} ).' ] '.$object->get_label.' ';
+        	}
+	        irc_msg( $list );
+		return;
+        }
         my $groups = Vhffs::User::get_groups( $user );
         my $list = '';
 
@@ -411,30 +425,6 @@
         irc_msg( $list );
 }
 
-sub fetch_group
-{
-        my $groupname = shift;
-        my $group = Vhffs::Group::get_by_groupname( $vhffs , $groupname );
-        unless( defined $group )
-        {
-                irc_msg ($groupname.' : No such group');
-                return;
-        }
-
-        my $objects = Vhffs::Group::getall_objects( $group );
-        my $list = '';
-
-        foreach my $obj ( @{$objects} )
-        {
-               my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $obj->{object_id} );
-               $list .= '[ '.Vhffs::Functions::type_string_from_type_id( $object->{type} ).' ] '.$object->get_label.' ';
-        }
-
-        irc_msg( $list );
-}
-
-
-
 sub quotacheck
 {
  my $limit = shift;
@@ -534,10 +524,8 @@
 	irc_msg("whois <domain> - give NS for <domain>");
         irc_msg("accepttag <rid> <description> - accept tag request with id <rid> with description <description>");
         irc_msg("refusetag <rid> - refuse tag request with id <rid>");
-        irc_msg("fetchuser <username> - get groups from username <username>");
-        irc_msg("fetchgroup <group> - get objects from group <group>");
+        irc_msg("fetch <user|group> - fetch user | group with  <user|group>");
 
-
    }
     elsif ($texte =~ m/^${mynick}:\s+list$/)
     {
@@ -630,22 +618,14 @@
 			moderatetag( $rid , 0 , '' );
 		}
     }
-    elsif ($texte =~ m/^${mynick}:\s+fetchuser\s+[a-z0-9]+$/)
+    elsif ($texte =~ m/^${mynick}:\s+fetch\s+[a-z0-9]+$/)
     {
-        my $username = $texte;
-        $username =~ s/^${mynick}: fetchuser //;
-        fetch_user($username);
+        my $name = $texte;
+        $name =~ s/^${mynick}: fetch //;
+        fetch($name);
     }
-    elsif ($texte =~ m/^${mynick}:\s+fetchgroup\s+[a-z0-9]+$/)
-    {
-        my $groupname = $texte;
-        $groupname =~ s/^${mynick}: fetchgroup //;
-        fetch_group($groupname);
-    }
 
 
-
-
 } # on_public
 
 sub on_kick {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/