[vhffs-dev] [1915] Add fetchgroup to modobot

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


Revision: 1915
Author:   misric
Date:     2012-01-03 19:18:50 +0100 (Tue, 03 Jan 2012)
Log Message:
-----------
Add fetchgroup to modobot

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

Modified: branches/vhffs-4.2/vhffs-irc/modobot.pl
===================================================================
--- branches/vhffs-4.2/vhffs-irc/modobot.pl	2012-01-03 17:29:08 UTC (rev 1914)
+++ branches/vhffs-4.2/vhffs-irc/modobot.pl	2012-01-03 18:18:50 UTC (rev 1915)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!%PERL%
 
 # modobot is an IRC bot which allow you to validate
 # VHFFS objects through IRC
@@ -12,7 +12,7 @@
 use Locale::gettext;
 use Encode;
 
-use lib '/usr/share/vhffs/api';
+use lib '%VHFFS_LIB_DIR%';
 use Vhffs::User;
 use Vhffs::Group;
 use Vhffs::Main;
@@ -40,8 +40,7 @@
 exit 1 unless $vhffs;
 
 my $configirc = $vhffs->get_config->get_irc;
-#my $chan = $configirc->{modobot_channel};
-my $chan = "#elisae-adm";
+my $chan = $configirc->{modobot_channel};
 
 my $conn=$irc->newconn(Nick     =>  $configirc->{modobot_name},
                        Server   =>  $configirc->{modobot_server},
@@ -79,8 +78,8 @@
 			$msg .= ' ['.$user->get_lang.']   '.$group->get_groupname.'   '.$object->get_label.'   '.$obj->get_description;
 			$msg .= "\n[".format_tags_list($group).']';
 			irc_msg( $msg );
-
-			$oldobjects{$obj->get_oid} = '';
+			
+			${%oldobjects}{$obj->get_oid} = '';
 		}
 	}
 }
@@ -162,7 +161,7 @@
 				irc_msg( 'Object '.$oid.' refused ('.$charset.' detected)' );
 			}
 		}
-		delete $oldobjects{$oid};
+		delete ${%oldobjects}{$oid};
 	}
 	return 0;
 }
@@ -196,7 +195,6 @@
 } # on_cversion
 
 sub on_connect {
-    print "[connect] <$chan>\n";
     my $self=shift;
     $bot=$self;
     $self->join($chan);

Modified: trunk/vhffs-irc/modobot.pl
===================================================================
--- trunk/vhffs-irc/modobot.pl	2012-01-03 17:29:08 UTC (rev 1914)
+++ trunk/vhffs-irc/modobot.pl	2012-01-03 18:18:50 UTC (rev 1915)
@@ -1,5 +1,6 @@
-#!/usr/bin/perl
+#!%PERL%
 
+
 # modobot is an IRC bot which allow you to validate
 # VHFFS objects through IRC
 # Written by Florent Bayle and Sylvain Rochet (this is very important to add my name here, to become famous very soon)
@@ -12,7 +13,7 @@
 use Locale::gettext;
 use Encode;
 
-use lib '/usr/share/vhffs/api';
+use lib '%VHFFS_LIB_DIR%';
 use Vhffs::User;
 use Vhffs::Group;
 use Vhffs::Main;
@@ -410,7 +411,30 @@
         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;
@@ -511,7 +535,9 @@
         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>");
 
+
    }
     elsif ($texte =~ m/^${mynick}:\s+list$/)
     {
@@ -610,9 +636,16 @@
         $username =~ s/^${mynick}: fetchuser //;
         fetch_user($username);
     }
+    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/