[vhffs-dev] [1029] Add modobot charset support when refusing objects

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


Revision: 1029
Author:   gradator
Date:     2007-10-25 21:24:31 +0000 (Thu, 25 Oct 2007)

Log Message:
-----------
Add modobot charset support when refusing objects

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


Modified: trunk/vhffs-irc/modobot.pl
===================================================================
--- trunk/vhffs-irc/modobot.pl	2007-10-25 21:11:18 UTC (rev 1028)
+++ trunk/vhffs-irc/modobot.pl	2007-10-25 21:24:31 UTC (rev 1029)
@@ -4,12 +4,13 @@
 # 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)
 
+use strict;
+use utf8;
 use POSIX qw(locale_h);
 use locale;
-use strict;
-use utf8;
 use warnings;
 use Locale::gettext;
+use Encode;
 
 use lib '/usr/share/vhffs/api';
 use Vhffs::User;
@@ -103,11 +104,31 @@
 			if( $object->moderate_accept < 0 )  {
 				irc_msg('Error while committing changes');
 			}
+			else {
+				irc_msg( 'Object '.$oid.' accepted' );
+			}
 		}
 		else  {
-			if( $object->moderate_refuse( $reason ) < 0 )  {
+			my $wfreason;
+			my $charset;
+			eval { $wfreason = decode_utf8( $reason , Encode::FB_CROAK ); };
+			if( $@ )  {
+				#decoding from utf8 failed, falling back to iso
+				$wfreason = decode('iso-8859-1', $reason);
+				$charset = 'ISO';
+			}
+			else  {
+				$charset = 'UTF-8';
+			}
+
+			irc_msg( $wfreason );
+
+			if( $object->moderate_refuse( $wfreason ) < 0 )  {
 				irc_msg('Error while committing changes');
 			}
+			else {
+				irc_msg( 'Object '.$oid.' refused ('.$charset.' detected)' );
+			}
 		}
 		delete ${%oldobjects}{$oid};
 	}
@@ -267,10 +288,7 @@
         if (is_modo ($nick) == 1)
 	{
 	    $texte =~ s/^${mynick}: accept //;
-            if (moderate( $texte , 1 ) == 0)
-            {
-                irc_msg("Object " . $texte . " accepted");
-            }
+            moderate( $texte , 1 );
 	}
     }
     elsif ($texte =~ m/^${mynick}: refuse [0-9]+ .*$/)
@@ -281,10 +299,7 @@
 	    my $raison = $texte;
 	    $raison =~ s/^${mynick}: refuse [0-9]+ //;
 	    $oid =~ s/^${mynick}: refuse ([0-9]+) .*$/$1/;
-            if (moderate( $oid , 0 , $raison) == 0)
-            {
-                irc_msg("Object " . $oid . " refused");
-            }
+            moderate( $oid , 0 , $raison);
 	}
     }
     elsif ($texte =~ m/^${mynick}: help$/)


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