[vhffs-dev] [1588] Added accepttag and refusetag commands to moderate tag requests. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1588
Author: guillaumito
Date: 2010-04-07 22:42:44 +0200 (Wed, 07 Apr 2010)
Log Message:
-----------
Added accepttag and refusetag commands to moderate tag requests.
Modified Paths:
--------------
trunk/vhffs-irc/modobot.pl
Modified: trunk/vhffs-irc/modobot.pl
===================================================================
--- trunk/vhffs-irc/modobot.pl 2010-04-07 20:42:04 UTC (rev 1587)
+++ trunk/vhffs-irc/modobot.pl 2010-04-07 20:42:44 UTC (rev 1588)
@@ -21,6 +21,7 @@
use Vhffs::ObjectFactory;
use Vhffs::Tag;
use Vhffs::Tag::Request;
+use Vhffs::Tag::Category;
use Net::IRC;
use Net::DNS;
@@ -185,8 +186,81 @@
return 0;
}
+sub moderatetag
+{
+ my $rid = shift;
+ my $status = shift; # 0 = refuse , 1 = accept
+ my $reason = shift;
+ my $request = Vhffs::Tag::Request::get_by_request_id( $vhffs, $rid );
+ my $wfreason;
+ my $charset;
+ eval { $wfreason = Encode::decode_utf8( $reason , Encode::FB_CROAK ); };
+ if( $@ ) {
+ #decoding from utf8 failed, falling back to iso
+ $wfreason = Encode::decode('iso-8859-1', $reason);
+ $charset = 'ISO';
+ }
+ else {
+ $charset = 'UTF-8';
+ }
+
+ unless( defined $request )
+ {
+ irc_msg ('Error : Cannot fetch request');
+ return ( -1 );
+ }
+ else
+ {
+ if( $status == 1 )
+ {
+ my $user = Vhffs::User::get_by_uid($vhffs, Vhffs::Main::current_user_uid);
+
+ my $category = Vhffs::Tag::Category::get_by_label($vhffs, $request->{category_label});
+ unless( defined $category )
+ {
+ irc_msg('Error : Cannot fetch category');
+ return -1;
+ }
+
+ my $tag = Vhffs::Tag::create($vhffs, $request->{tag_label}, $wfreason, $user, $category);
+
+ unless(defined $tag) {
+ irc_msg('Error : Unable to create tag');
+ return -1;
+ }
+
+ # Adds the tag to the object for which it has
+ # been requested.
+
+ my $object = $request->get_tagged();
+ if(defined $object) {
+ my $ruser = $request->get_requester();
+ $ruser = $user unless(defined $ruser);
+ $object->add_tag($tag, $user);
+ }
+
+ $request->delete();
+ irc_msg( 'Request '.$rid.' accepted ('.$charset.' detected)' );
+ }
+ else
+ {
+
+ if( $request->delete < 0 ) {
+ irc_msg('Error while committing changes');
+ }
+ else {
+ irc_msg( 'Request '.$rid.' deleted' );
+ }
+ }
+ delete $oldrequests{$rid};
+ }
+ return 0;
+}
+
+
+
sub on_ping {
my ($self, $event) = @_;
my $nick = $event->nick;
@@ -412,6 +486,8 @@
irc_msg("getquota <group> - give quota for <group>");
irc_msg("setquota <group> <newquota> - change quota for <group> to <newquota>");
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>");
}
elsif ($texte =~ m/^${mynick}:\s+list$/)
@@ -488,6 +564,23 @@
else { irc_msg("query failed for $whois : ".$resolv->errorstring); }
}
+ elsif ($texte =~ m/^${mynick}:\s+accepttag\s+[0-9]+.*$/)
+ {
+ if (is_modo ($user) == 1)
+ {
+ my ( $rid , $reason ) = ( $texte =~ /^${mynick}:\s+accepttag\s+([0-9]+)(?:\s+)?(.+)?$/ );
+ Vhffs::Main::current_user_uid( $user->get_uid );
+ moderatetag( $rid , 1 , $reason );
+ }
+ }
+ elsif ($texte =~ m/^${mynick}:\s+refusetag\s+[0-9]+\s*$/)
+ {
+ if (is_modo ($user) == 1) {
+ my $rid = $texte;
+ $rid =~ s/^${mynick}:\s+refusetag\s+([0-9]+)\s*$/$1/;
+ moderatetag( $rid , 0 , '' );
+ }
+ }
} # on_public