[vhffs-dev] [1914] Add fetchuser to modobot

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


Revision: 1914
Author:   misric
Date:     2012-01-03 18:29:08 +0100 (Tue, 03 Jan 2012)
Log Message:
-----------
Add fetchuser 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	2011-12-11 15:19:24 UTC (rev 1913)
+++ branches/vhffs-4.2/vhffs-irc/modobot.pl	2012-01-03 17:29:08 UTC (rev 1914)
@@ -40,7 +40,8 @@
 exit 1 unless $vhffs;
 
 my $configirc = $vhffs->get_config->get_irc;
-my $chan = $configirc->{modobot_channel};
+#my $chan = $configirc->{modobot_channel};
+my $chan = "#elisae-adm";
 
 my $conn=$irc->newconn(Nick     =>  $configirc->{modobot_name},
                        Server   =>  $configirc->{modobot_server},
@@ -66,7 +67,7 @@
 	my $objects = Vhffs::Object::getall( $vhffs, undef, Vhffs::Constants::WAITING_FOR_VALIDATION );
 	if( defined $objects )  {
 		foreach my $obj ( @{$objects} ) {
-			next if( $seq && exists( ${%oldobjects}{$obj->get_oid} ) );
+			next if( $seq && exists( $oldobjects{$obj->get_oid} ) );
 
 			my $user = $obj->get_user;
 			my $group = $obj->get_group;
@@ -79,7 +80,7 @@
 			$msg .= "\n[".format_tags_list($group).']';
 			irc_msg( $msg );
 
-			${%oldobjects}{$obj->get_oid} = '';
+			$oldobjects{$obj->get_oid} = '';
 		}
 	}
 }
@@ -161,7 +162,7 @@
 				irc_msg( 'Object '.$oid.' refused ('.$charset.' detected)' );
 			}
 		}
-		delete ${%oldobjects}{$oid};
+		delete $oldobjects{$oid};
 	}
 	return 0;
 }
@@ -195,6 +196,7 @@
 } # on_cversion
 
 sub on_connect {
+    print "[connect] <$chan>\n";
     my $self=shift;
     $bot=$self;
     $self->join($chan);
@@ -485,7 +487,6 @@
 $conn->add_handler        ('cversion', \&on_cversion);
 $conn->add_handler        ('public',   \&on_public);
 $conn->add_handler        ('kick',     \&on_kick);
-
 sub CatchAlrm
 {
     list_moderation( 1 );

Modified: trunk/vhffs-irc/modobot.pl
===================================================================
--- trunk/vhffs-irc/modobot.pl	2011-12-11 15:19:24 UTC (rev 1913)
+++ trunk/vhffs-irc/modobot.pl	2012-01-03 17:29:08 UTC (rev 1914)
@@ -1,4 +1,4 @@
-#!%PERL%
+#!/usr/bin/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 '%VHFFS_LIB_DIR%';
+use lib '/usr/share/vhffs/api';
 use Vhffs::User;
 use Vhffs::Group;
 use Vhffs::Main;
@@ -389,7 +389,28 @@
 	irc_msg( $list );
 }
 
+sub fetch_user
+{
+        my $username = shift;
+        my $user = Vhffs::User::get_by_username( $vhffs , $username );
+        unless( defined $user )
+        {
+                irc_msg ($username.' : No such user');
+                return;
+        }
 
+        my $groups = Vhffs::User::get_groups( $user );
+        my $list = '';
+
+        foreach ( @{$groups} )
+        {
+                $list .= $_->get_groupname.' ';
+        }
+
+        irc_msg( $list );
+}
+
+
 sub quotacheck
 {
  my $limit = shift;
@@ -489,6 +510,7 @@
 	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>");
 
    }
     elsif ($texte =~ m/^${mynick}:\s+list$/)
@@ -582,7 +604,15 @@
 			moderatetag( $rid , 0 , '' );
 		}
     }
+    elsif ($texte =~ m/^${mynick}:\s+fetchuser\s+[a-z0-9]+$/)
+    {
+        my $username = $texte;
+        $username =~ s/^${mynick}: fetchuser //;
+        fetch_user($username);
+    }
 
+
+
 } # on_public
 
 sub on_kick {


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