User:AnomieBOT/source/tasks/SourceUploader.pm

. Thanks.");       }

$res=$api->rawpage("Template:Editnotices/Group/User:$bot/shutoff"); if($res->{'code'} eq 'shutoff'){ $api->warn("Task disabled: ".$res->{'content'}."\n"); return 300; }       $res->{'code'}='success' if($res->{'code'} eq 'httperror' && $res->{'httpcode'}==404); if($res->{'code'} ne 'success'){ $api->warn("Could not load Template:Editnotices/Group/User:$bot/shutoff: ".$res->{'error'}."\n"); return 60; }       $res=$res->{'content'}//''; $res=~s/\s*$//; my $txt=""; unless($res=~/(?:^|\n)\Q$txt\E(?:$|\n)/){ $api->whine("Please fix Template:Editnotices/Group/User:$bot/shutoff", "To display the proper editnotice on shutoff pages for the AnomieBOT bot User:$bot, please ensure that Template:Editnotices/Group/User:$bot/shutoff contains the following text:\n $txt \nThanks."); }

$self->{'check_shutoff_notice'}=[@checkshutoffnotice]; }

return 0; }

sub upload_page { my $self=shift; my $api=shift; my $page=shift; my $text=shift;

my $tok=$api->edittoken($page); if($tok->{'code'} eq 'shutoff'){ $api->warn("Task disabled: ".$tok->{'content'}."\n"); return 300; }   return 60 if($tok->{'code'} ne 'success'); my $bot=$api->user; $text=~s/\x02BOT\x03/$bot/go; $text=~s/\s+$//o; $tok->{'revisions'}[0]{'slots'}{'main'}{'*'}=~s/\s+$//o if !exists($tok->{'missing'}); if(exists($tok->{'missing'}) ||      $tok->{'revisions'}[0]{'slots'}{'main'}{'contentmodel'} ne 'wikitext' ||       $tok->{'revisions'}[0]{'slots'}{'main'}{'*'} ne $text){ my $r=$api->edit($tok, $text, $self->{'summary'}, 0, 1, contentmodel => 'wikitext' ); if($r->{'code'} ne 'success'){ $api->warn("Write error for $page: ".$r->{'error'}."\n"); return 60; } else { $api->log("Updated $page"); }   } else { $api->debug(2, "No update needed for $page\n"); }   return 0; }

sub redirect_talk { my $api=shift; my $page=shift;

my $tpage=$page; $tpage=~s/^User:/User talk:/; my $txt=$tpage; $txt=~s!^(User talk:[^/]+)/.*!$1!; my $r={$api->resolve_redirects($txt)}; if(exists($r->{''})){ $api->warn("Error fetching redirects for $page: ".$r->{''}{'error'}."\n"); return 60; }   $txt=$r->{$txt}; $txt="#REDIRECT $txt\n\nThis page is unwatched. Please direct comments to $txt."; my $tok=$api->edittoken($tpage, EditRedir=>1, NoExclusion=>1); if($tok->{'code'} eq 'shutoff'){ $api->warn("Task disabled: ".$tok->{'content'}."\n"); return 300; }   return 60 if($tok->{'code'} ne 'success'); if(($tok->{'revisions'}[0]{'slots'}{'main'}{'*'} // '') ne $txt){ my $r=$api->edit($tok, $txt, 'Redirect useless unwatched talk page to someplace useful.', 1, 1); if($r->{'code'} ne 'success'){ $api->warn("Write error for $tpage: ".$r->{'error'}."\n"); return 60; } else { $api->log("Created $tpage"); }   }    return undef; }

sub determine_task_section { my $file = shift; my %metadata = @_;

my $t=$file; $t=~s{^.*/}{}; $t=~s/\.pm$//; return '99 Invalid metadata (no "Bot")' unless exists($metadata{'bot'}); return '99 Invalid metadata (no/bad "Task")' unless(exists($metadata{'task'}) && $metadata{'task'} eq $t); return '99 Invalid metadata (no "BRFA")' unless exists($metadata{'brfa'}); return '99 Invalid metadata (no "Status")' unless exists($metadata{'status'}); return '99 Invalid metadata (no/bad "Created")' unless(exists($metadata{'created'}) && $metadata{'created'}=~/^\d{4}-\d\d-\d\d$/); if(exists($metadata{'+brfa'})){ return '99 Invalid metadata (no "+Status")' unless exists($metadata{'+status'}); return '99 Invalid metadata (mismatched +BRFA/+Status)' if scalar(@{$metadata{'+status'}}) != scalar(@{$metadata{'+brfa'}}); }   if(exists($metadata{'ondemand'})){ return '99 Invalid metadata (bad "OnDemand")' unless($metadata{'ondemand'} eq 'true' || $metadata{'ondemand'} eq 'false'); }   if(exists($metadata{'shutoff'})){ return '99 Invalid metadata (bad "Shutoff")' unless($metadata{'shutoff'} eq 'true' || $metadata{'shutoff'} eq 'false'); }   if(exists($metadata{'exclusion'})){ return '99 Invalid metadata (bad "Exclusion")' unless($metadata{'exclusion'} eq 'true' || $metadata{'exclusion'} eq 'false'); }   my $status=$metadata{'status'};

AnomieBOT::API::load($file); my $task='tasks::'.$metadata{'task'}; return '99 Invalid metadata (missing "approved" method)' unless $task->can('approved');

my $botnum=$task->approved;

if($metadata{'brfa'} eq 'N/A'){ return "01 Current" if($botnum>0 && $status=~/^Begun \d{4}-\d{2}-\d{2}$/); return "02 On demand" if(exists($metadata{'ondemand'}) && $metadata{'ondemand'} eq 'true'); }   if($status=~/^Approved \d{4}-\d{2}-\d{2}$/){ return "01 Current" if $botnum>0; return "02 On demand" if(exists($metadata{'ondemand'}) && $metadata{'ondemand'} eq 'true'); return '99 Invalid metadata ("Status: Approved" but not running or OnDemand)'; }   return "03 In trial" if($status=~/^In trial/ && $botnum>0); return '99 Invalid metadata (Running with a non-running Status)' if $botnum>0; return "04 In development" if($status eq 'Coding' || $status eq 'On hold'); return "06 Past" if $status=~/^(?:Completed|Inactive) \d{4}-\d{2}-\d{2}$/; return '99 Invalid metadata (bad "BRFA")' if($metadata{'brfa'} eq 'N/A'); return "05 Awaiting approval" if($status eq 'BRFA'); return "07 Withdrawn" if $status eq 'Withdrawn'; return "08 Rejected" if $status=~/^Rejected \d{4}-\d{2}-\d{2}$/; return '99 Invalid metadata (no match for Status)'; }

1;