Jump to content

User:ST47/ACE

From Wikipedia, the free encyclopedia

  1. !/usr/bin/perl

use STWP; use POE; use POE::Component::IRC;

my %killlist = ( 'baduser' => ('badpage',), 'verybaduser' => ('*',), );

$editor=STWP->new('Bot/WP/EN/ST47/Unapproved/ArbComEnforcer'); my $nickname = "ARBWatch"; my $ircname = "ARBWatch";

my $settings = { 'irc.wikimedia.org' => {port => 6667, channels => [ '#en.wikipedia'], }, };

foreach $server (keys %{$settings}) { POE::Component::IRC->spawn( alias=>$server, nick=>$nickname, ircname=>$ircname, ) || die "Could not create IRC: $!"; }

POE::Session->create( package_states => [ 'main'=> [ "_default", "_start", "irc_001", "irc_public", "irc_registered"], ], heap=>{config => $settings}, );

 $poe_kernel->run();
 exit 0;
 sub _start {

($kernel,$session) = @_[KERNEL,SESSION];

# We get the session ID of the component from the object # and register and connect to the specified server. $kernel->signal( $kernel, 'POCOIRC_REGISTER', $session->ID(), 'all' ); undef;

 }
 sub irc_registered {
   my ($kernel,$heap,$sender,$irc_object) = 

@_[KERNEL,HEAP,SENDER,ARG0];

   my $alias = $irc_object->session_alias();
   my %conn_hash = (
       server => $alias,
       port   => $heap->{config}->{ $alias }->{port},
   );
   # In any irc_* events SENDER will be the PoCo-IRC session
   $kernel->post( $sender, 'connect', \%conn_hash ); 
   undef;
 }

sub irc_001 { ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER];

# Get the component's object at any time by accessing the heap of # the SENDER my $poco_object = $sender->get_heap(); print "Connected to ", $poco_object->server_name(), "\n";

   my $alias = $poco_object->session_alias();
   my @channels = @{ $heap->{config}->{ $alias }->{channels} };

# In any irc_* events SENDER will be the PoCo-IRC session $kernel->post( $sender => join => $_ ) for @channels; undef; }

 sub _default {

my ($event, $args) = @_[ARG0 .. $#_]; my @output = ( "$event: " );

foreach my $arg ( @$args ) { if ( ref($arg) eq 'ARRAY' ) { push( @output, "[" . join(" ,", @$arg ) . "]" ); } else { push ( @output, "'$arg'" ); } } print STDOUT join ' ', @output, "\n"; return 0;

 }

sub irc_public { ($kernel,$sender,$who,$where,$what) = @_[KERNEL,SENDER,ARG0,ARG1,ARG2]; my $nick = ( split /!/, $who )[0]; my $channel = $where->[0];


       $what=~s/\cC\d{1,2}(,\d{1,2})?|[\cC\cB\cI\cU\cR\cO]//g;
       if ($what=~m/\[\[(.+?)\]\]\s?.+?M?.+?\s*?(http:.+?)\s?\*\s?(.+?)\s?\*\s?\(([^)]+)\)\s?(.+)?/){
               my $page=$1;
               my $diff=$2;
               my $user=$3;
               if (join(' ', @killlist{$user})=~/$page/i) {
                       my $text = $editor->get_text('Wikipedia:Administrator's Noticeboard/Incidents');
                       my $count=count(@killlist{$user});
                       if ($count--) {my $s = 's'}
                       $text .= "==Banned user $user edited $page==\nThe user $user, who is banned by ArbCom from editing $count page$s, has edited $page ([$diff]). ~~" . "~~\n";
                       $editor->edit('Wikipedia:Administrator's Noticeboard/Incidents', $text, 'Banned user editing!');
               }
               if (join(' ', @killlist{$user})=~/\*/) {
                       my $text = $editor->get_text('Wikipedia:Administrator's Noticeboard/Incidents');
                       my $count=count(@killlist{$user});
                       $text .= "==Banned user $user edited $page==\nThe user $user, who is banned by ArbCom from editing, has edited $page ([$diff]). ~~" . "~~\n";
                       $editor->edit('Wikipedia:Administrator's Noticeboard/Incidents', $text, 'Banned user editing!');
               }

undef; }

Devtools
Waiting for requests