Advertisement
Guest User

Untitled

a guest
Aug 9th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.53 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use utf8;
  5. use MediaWiki::API;
  6. use Irssi;
  7. use WikiCommon;
  8.  
  9. our $VERSION = "20091123";
  10. our %IRSSI   = (
  11.         authors     => 'pl:User:Beau',
  12.         contact     => 'beau@adres.pl',
  13.         name        => 'wiki-admins',
  14.         description => 'Utility for wikipedians\' channel',
  15.         license     => 'GPL',
  16.         url         => 'http://tools.wikimedia.pl/~masti',
  17. );
  18.  
  19. my %wiki_channels;
  20.  
  21. $wiki_channels{'#mst'} = {
  22.         'url' => 'https://pl.wikipedia.org/w/api.php',    #
  23. };
  24.  
  25. $wiki_channels{'#wikipedia-pl'} = {
  26.         'url' => 'https://pl.wikipedia.org/w/api.php',    #
  27. };
  28.  
  29. $wiki_channels{'#wiktionary-pl'} = {
  30.         'url' => 'https://pl.wiktionary.org/w/api.php',    #
  31. };
  32.  
  33. $wiki_channels{'#wikisource-pl'} = {
  34.         'url' => 'https://pl.wikisource.org/w/api.php',    #
  35. };
  36.  
  37. $wiki_channels{'#wikibooks-pl'} = {
  38.         'url' => 'https://pl.wikibooks.org/w/api.php',    #
  39. };
  40.  
  41. foreach my $settings ( values %wiki_channels ) {
  42.         $settings->{admins}         = {};
  43.         $settings->{admins_fetched} = 0;
  44. }
  45.  
  46. # -------------------------------------------------------------------
  47.  
  48. sub rcadmins($) {
  49.         my $data = shift;
  50.  
  51.         # my $api = MediaWiki::API->new( 'url' => $data->{url}, );
  52.         my $api = MediaWiki::API->new();
  53.         $api->{config}->{api_url} = $data->{url};
  54.  
  55.         if ( time() - $data->{admins_fetched} > 3600 ) {
  56.                 my $response = $api->list({
  57.                         'action'  => 'query',
  58.                         'list'    => 'allusers',
  59.                         'augroup' => 'sysop',
  60.                         'aulimit' => 'max',
  61.                 });
  62.                 my @list = values %{ $response->{query}->{allusers} };
  63.                 $data->{admins} = { map { $_->{name} => 1 } @list };
  64.         }
  65.  
  66.         my $response = $api->query(
  67.                 'action'  => 'query',
  68.                 'list'    => 'recentchanges',
  69.                 'rcprop'  => 'user',
  70.                 'rclimit' => 100,
  71.                 'rcshow'  => '!bot',
  72.         );
  73.  
  74.         my %nicks;
  75.         foreach my $item ( values %{ $response->{query}->{recentchanges} } ) {
  76.                 my $nick = $item->{user};
  77.                 next unless exists $data->{admins}->{$nick};
  78.                 $nicks{$nick}++;
  79.         }
  80.         return sort keys %nicks;
  81. }
  82.  
  83. sub message {
  84.         my ( $server, $args, $sender, $address ) = @_;
  85.         my ( $target, $msg ) = $args =~ /^(\S+) :(.+)$/;
  86.  
  87.         my $settings = $wiki_channels{$target};
  88.         return
  89.           unless defined $settings;
  90.  
  91.         my $channel = $server->channel_find($target);
  92.         return unless $channel;
  93.  
  94.         return unless isActive($server, $channel);
  95.  
  96.         if ( $msg =~ /^!help$/ ) {
  97.                 $server->command("notice $sender !admini - wyświetla listę aktywnych administratorów");
  98.                 return;
  99.         }
  100.  
  101.         return
  102.           unless $msg =~ /^!admin[yi]$/i;
  103.  
  104.         eval {
  105.                 my $list = join( ', ', rcadmins($settings) );
  106.                 if ( $list ne '' ) {
  107.                         $server->command("msg $target $sender: admini na OZ (100 ostatnich edycji): $list");
  108.                 }
  109.                 else {
  110.                         $server->command("msg $target $sender: Uuups! Chyba nie ma adminów na OZ!");
  111.                 }
  112.         };
  113.         if ($@) {
  114.                 $server->command("msg $target $sender: wystąpił błąd: $@");
  115.         }
  116. }
  117.  
  118. Irssi::signal_add_last( "event privmsg", "message" );
  119.  
  120. # perltidy -et=8 -l=0 -i=8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement