[vhffs-dev] [svn] commit: r222 - /trunk/vhffs-irc/modobot.pl

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


Author: florent
Date: Mon Aug 21 21:39:31 2006
New Revision: 222

Log:
Modification du bot irc :
 - ajout de la fonction "desc"
 - ajout de coupure de phrases après 300 lettres, avec "word wrap".


Modified:
    trunk/vhffs-irc/modobot.pl

Modified: trunk/vhffs-irc/modobot.pl
==============================================================================
--- trunk/vhffs-irc/modobot.pl (original)
+++ trunk/vhffs-irc/modobot.pl Mon Aug 21 21:39:31 2006
@@ -9,6 +9,7 @@
 use strict;
 use warnings;
 use Locale::gettext;
+use Data::Dumper;
 
 use Vhffs::User;
 use Vhffs::Group;
@@ -19,6 +20,7 @@
 use Vhffs::Note;
 
 use Net::IRC;
+use Text::Wrapper;
 
 use constant
 {
@@ -84,11 +86,11 @@
 	    map { last GR if (($_->get_oid eq $temp->get_oid) && ($_->get_groupname eq $temp->get_groupname)); } @oldgroup;
             if( $vhffs->get_config->use_notation == 1 )
             {
-                $bot->privmsg($chan, deletenl ("Groupe :      " . $temp->get_oid . "   " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")   " . $temp->get_groupname . "   " . Vhffs::Functions::stripslashes($temp->get_description)));
+                irc_msg ("Groupe :      " . $temp->get_oid . "   " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")   " . $temp->get_groupname . "   " . Vhffs::Functions::stripslashes($temp->get_description));
             }
             else
             {
-                $bot->privmsg($chan, deletenl ("Groupe :      " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_groupname . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
+                irc_msg ("Groupe :      " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_groupname . "    " . Vhffs::Functions::stripslashes($temp->get_description));
             }
         }
         @oldgroup = @{$groups};
@@ -112,11 +114,11 @@
 
                 if( $vhffs->get_config->use_notation == 1 )
                 {
-                    $bot->privmsg($chan, deletenl ("Web :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_servername . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
-                else
-                {
-                    $bot->privmsg($chan, deletenl ("Web :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_servername . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
+                    irc_msg ("Web :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_servername . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+                }
+                else
+                {
+                    irc_msg ("Web :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_servername . "    " . Vhffs::Functions::stripslashes($temp->get_description));
                 }
             }
             @oldweb = @{$webs};
@@ -140,11 +142,11 @@
 	        map { last DN if (($_->get_oid eq $temp->get_oid) && ($_->get_domain eq $temp->get_domain)); } @olddns;
                 if( $vhffs->get_config->use_notation == 1 )
                 {
-                    $bot->privmsg($chan, deletenl ("DNS :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_domain . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
-                else
-                {
-                    $bot->privmsg($chan, deletenl ("DNS :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_domain . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
+                    irc_msg ("DNS :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_domain . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+		}
+                else
+                {
+                    irc_msg ("DNS :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_domain . "    " . Vhffs::Functions::stripslashes($temp->get_description));
                 }
 
             }
@@ -169,11 +171,11 @@
 	        map { last CV if (($_->get_oid eq $temp->get_oid) && ($_->get_cvsroot eq $temp->get_cvsroot)); } @oldcvs;
                 if( $vhffs->get_config->use_notation == 1 )
                 {
-                    $bot->privmsg($chan, deletenl ("CVS :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_cvsroot . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
-                else
-                {
-                    $bot->privmsg($chan, deletenl ("CVS :          " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_cvsroot . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
+                    irc_msg ("CVS :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_cvsroot . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+                }
+                else
+                {
+                    irc_msg ("CVS :          " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_cvsroot . "    " . Vhffs::Functions::stripslashes($temp->get_description));
                 }
             }
             @oldcvs = @{$repos};
@@ -197,11 +199,11 @@
                 map { last ML if (($_->get_oid eq $temp->get_oid) && ($_->get_localpart eq $temp->get_localpart)); } @oldmailing;
                 if( $vhffs->get_config->use_notation == 1 )
                 {
-                    $bot->privmsg($chan, deletenl ("Mailing list : " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_localpart . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
-                else
-                {
-                    $bot->privmsg($chan, deletenl ("Mailing list : " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_localpart . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
+                    irc_msg ("Mailing list : " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_localpart . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+                }
+                else
+                {
+                    irc_msg ("Mailing list : " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_localpart . "    " . Vhffs::Functions::stripslashes($temp->get_description));
                 }
             }
             @oldmailing = @{$mls};
@@ -225,12 +227,12 @@
                 map { last SV if (($_->get_oid eq $temp->get_oid) && ($_->get_reponame eq $temp->get_reponame)); } @oldsvn;
                 if( $vhffs->get_config->use_notation == 1 )
                 {
-                    $bot->privmsg($chan, deletenl ("SVN :          " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_reponame . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
-                else
-                {
-                    $bot->privmsg($chan, deletenl ("SVN :          " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_reponame . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
+                    irc_msg ("SVN :          " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_reponame . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+                }
+                else
+                {
+                    irc_msg ("SVN :          " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_reponame . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+		}
             }
         @oldsvn = @{$repos};
         }
@@ -253,11 +255,11 @@
                 map { last MA if (($_->get_oid eq $temp->get_oid) && ($_->get_domain eq $temp->get_domain)); } @oldmail;
                 if( $vhffs->get_config->use_notation == 1 )
                 {
-                    $bot->privmsg($chan, deletenl ("Mail :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_domain . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
-                else
-                {
-                    $bot->privmsg($chan, deletenl ("Mail :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_domain . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
+                    irc_msg ("Mail :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_domain . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+                }
+                else
+                {
+                    irc_msg ("Mail :         " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_domain . "    " . Vhffs::Functions::stripslashes($temp->get_description));
                 }
             }
             @oldmail = @{$mails};
@@ -281,11 +283,11 @@
                 map { last MY if (($_->get_oid eq $temp->get_oid) && ($_->get_dbname eq $temp->get_dbname)); } @oldmysql;
                 if( $vhffs->get_config->use_notation == 1 )
                 {
-                    $bot->privmsg($chan, deletenl ("MySql :        " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_dbname . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
-                else
-                {
-                    $bot->privmsg($chan, deletenl ("MySql :        " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_dbname . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
+                    irc_msg ("MySql :        " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_dbname . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+                }
+                else
+                {
+                    irc_msg ("MySql :        " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_dbname . "    " . Vhffs::Functions::stripslashes($temp->get_description));
                 }
             }
             @oldmysql = @{$dbs};
@@ -309,11 +311,11 @@
                 map { last PO if (($_->get_oid eq $temp->get_oid) && ($_->get_dbname eq $temp->get_dbname)); } @oldpostgres;
                 if( $vhffs->get_config->use_notation == 1 )
                 {
-                    $bot->privmsg($chan, deletenl ("Postgres :     " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_dbname . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
-                }
-                else
-                {
-                    $bot->privmsg($chan, deletenl ("Postgres :     " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_dbname . "    " . Vhffs::Functions::stripslashes($temp->get_description)));
+                    irc_msg ("Postgres :     " . $temp->get_oid . "    " . $temp->get_user->get_username . "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ")    " . $temp->get_group->get_groupname . "    " . $temp->get_dbname . "    " . Vhffs::Functions::stripslashes($temp->get_description));
+                }
+                else
+                {
+                    irc_msg ("Postgres :     " . $temp->get_oid . "    " . $temp->get_user->get_username . "    " . $temp->get_group->get_groupname . "    " . $temp->get_dbname . "    " . Vhffs::Functions::stripslashes($temp->get_description));
                 }
             }
 	    @oldpostgres = @{$dbs};
@@ -341,17 +343,17 @@
 
     if( ! defined $object )
     {
-        $bot->privmsg($chan, "Error: Object is null");
+        irc_msg ("Error : Object is null");
         return ( -1 );
     }
     elsif( $object->fetch < 0 )
     {
-        $bot->privmsg($chan, "Error: Cannot fetch object");
+        irc_msg ("Error : Cannot fetch object");
         return ( -1 );
     }
     elsif( $object->get_status != Vhffs::Constants::WAITING_FOR_VALIDATION )
     {
-        $bot->privmsg($chan, "Error: Object is not waiting for validation");
+        irc_msg ("Error : Object is not waiting for validation");
         return ( -2 );
     }
     else
@@ -398,7 +400,7 @@
 
         if( $object->commit < 0 )
         {
-            $bot->privmsg($chan, "Error while commiting changes");
+            irc_msg ("Error while commiting changes");
             return ( -3 );
         }
 
@@ -437,7 +439,7 @@
     my $self=shift;
     $bot=$self;
     $self->join($chan);
-    $self->privmsg($chan, "--> Pacman started");
+    irc_msg ("--> Pacman started");
 } # on_connect
 
 sub is_modo
@@ -455,6 +457,32 @@
     return 0;
 } # is_modo
 
+sub get_desc
+{
+    my $name = shift;
+    my $group;
+    if ((! defined ($group= new Vhffs::Group( $vhffs , $name , '401' ) ) ) || ( $group->fetch < 0 ))
+    {
+        irc_msg ($chan, "$name : No such group");
+    }
+    else
+    {
+        irc_msg ("$name : " . Vhffs::Functions::stripslashes ($group->get_description));
+    }
+}
+
+sub irc_msg
+{
+    my $text = shift;
+    $text = deletenl ($text);
+    my $wrapper = Text::Wrapper->new(columns => 300);
+    my @text = split (/\n/, $wrapper->wrap($text));
+    for $a (@text)
+    {
+        $bot->privmsg($chan, $a);
+    }
+}
+
 sub on_public {
     my ($self, $event)=@_;
     my ($nick, $mynick)=($event->nick, $self->nick);
@@ -467,7 +495,7 @@
 	    $texte =~ s/^${mynick}: accept //;
             if (moderate( $texte , 1 ) == 0)
             {
-                $bot->privmsg($chan, "Object " . $texte . " accepted");
+                irc_msg("Object " . $texte . " accepted");
             }
 	}
     }
@@ -481,17 +509,18 @@
 	    $oid =~ s/^${mynick}: refuse ([0-9]+) .*$/$1/;
             if (moderate( $oid , 0 , $raison) == 0)
             {
-                $bot->privmsg($chan, "Object " . $oid . " refused");
+                irc_msg("Object " . $oid . " refused");
             }
 	}
     }
     elsif ($texte =~ m/^${mynick}: help$/)
     {
-        $bot->privmsg($chan, "Commands :");
-        $bot->privmsg($chan, "help - show this help");
-        $bot->privmsg($chan, "accept <oid> - accept object with id <oid>");
-        $bot->privmsg($chan, "refuse <oid> <reason> - refuse object with id <oid> for reason <reason>");
-	$bot->privmsg($chan, "list - force listing of all objects waiting for moderation");
+        irc_msg("Commands :");
+        irc_msg("help - show this help");
+        irc_msg("accept <oid> - accept object with id <oid>");
+        irc_msg("refuse <oid> <reason> - refuse object with id <oid> for reason <reason>");
+	irc_msg("list - force listing of all objects waiting for moderation");
+	irc_msg("desc <group> - give the description of <group>");
     }
     elsif ($texte =~ m/^${mynick}: list$/)
     {
@@ -506,13 +535,25 @@
         @oldpostgres = ();
 		list_moderation();
     }
+    elsif ($texte =~ m/^${mynick}: desc [a-z0-9]+$/)
+    {
+        my $groupid = $texte;
+	$groupid =~ s/^${mynick}: desc //;
+        get_desc ($groupid);
+    }
 } # on_public
+
+sub on_kick {
+    my $self=shift;
+    $self->join($chan);
+} # on_kick
 
 $conn->add_handler        ('cping',    \&on_ping);
 $conn->add_handler        ('crping',   \&on_ping_reply);
 $conn->add_global_handler ('376',      \&on_connect);
 $conn->add_handler        ('cversion', \&on_cversion);
 $conn->add_handler        ('public',   \&on_public);
+$conn->add_handler        ('kick',     \&on_kick);
 
 sub CatchAlrm
 {




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