diff --git a/bot.php b/bot.php index 7245d9f..5edc65b 100755 --- a/bot.php +++ b/bot.php @@ -1,129 +1,131 @@ #!/usr/bin/php . // autoload boz-mw include 'boz-mw/autoload.php'; // load configuration include 'config.php'; // groups on Meta $META_GROUPS = [ 'S' => 'steward', ]; // groups on Italian Wikipedia $WIT_GROUPS = [ 'B' => 'bureaucrat', 'CU' => 'checkuser', 'A' => 'sysop', 'AI' => 'interface-admin', ]; // legend $LEGEND = [ 'B' => "burocrate", 'CU' => "check user", 'A' => "amministratore", 'AI' => "amministratore dell'interfaccia", ]; // all groups $GROUPS = array_merge( $META_GROUPS, $WIT_GROUPS ); // user list $users = []; // counter indexed by group name $counts = []; foreach( $GROUPS as $group ) { $counts[ $group ] = 0; } // choosen wikis $wit = \wm\WikipediaIt::instance(); $lists = [ 'allusers', 'globalallusers', ]; // fetch all the sysops, checkusers, etc. from Italian wikipedia // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Ballusers $results = $wit->createQuery( [ 'action' => 'query', 'list' => $lists, // allusers 'auprop' => 'groups', 'augroup' => array_values( $WIT_GROUPS ), 'aulimit' => 400, // globalallusers 'aguprop' => 'groups', 'agugroup' => array_values( $META_GROUPS ), 'agulimit' => 200, ] ); // query continuation foreach( $results->getGenerator() as $result ) { foreach( $lists as $list ) { foreach( $result->query->{ $list } as $user ) { $name = $user->name; if( ! isset( $users[ $name ] ) ) { $users[ $name ] = []; } if( isset( $user->groups ) ) { foreach( $user->groups as $group ) { $legend = array_search( $group, $GROUPS, true ); if( $legend ) { $users[ $name ][] = $legend; $counts[ $group ]++; } } } } } } // stats message $stats = []; foreach( $counts as $group => $count ) { $stats[] = "$group: $count"; } $stats = implode( ", ", $stats ); try { $wit->login(); $wit->edit( [ 'title' => MARKADMINS_PAGE, 'summary' => "Bot: aggiornamento elenco utenti: $stats", 'text' => json_encode( [ 'legend' => $LEGEND, 'users' => $users ] ), 'contentformat' => 'application/json', 'bot' => 1, ] ); } catch( Exception $e ) { \cli\Log::error( sprintf( "something bad happened: %s", $e->getMessage() ) ); + + exit( 1 ); } \cli\Log::info( $stats );