3 package Bot
::BasicBot
::Pluggable
::Module
::WikinewsSpam
;
4 use Bot
::BasicBot
::Pluggable
::Module
;
5 use base
qw(Bot::BasicBot::Pluggable::Module);
11 use WWW
::Shorten
::TinyURL
;
12 use DateTime
::Format
::Strptime
;
13 use DateTime
::Format
::Duration
;
14 use DateTime
::Format
::Human
::Duration
;
17 # Settings. You can edit these.
18 my $s_chan = "#wikinews-spam";
19 my %check_period = ( # both in seconds
24 # DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
26 # Secondary variables.
27 my %check_next = ( # both in seconds
32 my $mw = MediaWiki
::API
->new();
33 $mw->{config
}->{api_url
} = 'https://en.wikinews.org/w/api.php';
34 my $strp = DateTime
::Format
::Strptime
->new(
35 pattern
=> '%Y-%m-%dT%H:%M:%SZ',
40 my $human_duration_parser = DateTime
::Format
::Human
::Duration
->new();
41 my $last_full_announce_ago = 0; # minutes
43 # Announce an article in channel
46 my $article_ref = shift;
49 my $info_ref = $mw->api ( {
53 pageids
=> $article_ref->{pageid
},
54 } ) or die $mw->{error
}->{code
} . ': ' . $mw->{error
}->{details
};
55 my $url = WWW
::Shorten
::TinyURL
::makeashorterlink
($info_ref->{query
}{pages
}{$article_ref->{pageid
}}{fullurl
});
56 $url =~ s/^http/https/;
58 # Human readable time ago
59 my $time_now = DateTime
->now;
60 my $time_published = $strp->parse_datetime($article_ref->{timestamp
});
61 my $time_ago = $human_duration_parser->format_duration_between($time_now,$time_published);
64 my $title = $article_ref->{title
};
66 my $message = "$url submitted for review *$time_ago* ago";
68 # Under review or not?
69 my $cat_info_ref = $mw->api ( {
73 clcategories
=> 'Category:Under review',
74 pageids
=> $article_ref->{pageid
},
75 } ) or die $mw->{error
}->{code
} . ': ' . $mw->{error
}->{details
};
76 if (exists $$cat_info_ref{query
}{pages
}{$article_ref->{pageid
}}{categories
}){
77 $message .= " - *under review*";
80 # Add title and say in channel
81 $message .= " - $title";
82 $self->say(channel
=> $s_chan, body
=> $message);
84 if (!($article_ref->{pageid
} ~~ @known_pageids)){
85 push @known_pageids, $article_ref->{pageid
};
91 my $articles_ref = $mw->list ( {
93 list
=> 'categorymembers',
94 cmtitle
=> 'Category:Review',
95 cmprop
=> 'ids|title|timestamp',
98 cmsort
=> 'timestamp',
99 } ) or die $mw->{error
}->{code
} . ': ' . $mw->{error
}->{details
};
100 return $articles_ref;
110 if ($check_next{'all'} == 0){
111 my $articles_ref = get_queue
();
112 my $message = (scalar $articles_ref == 0) ?
"Empty review queue" : "Review queue:";
113 @new_articles = @
{$articles_ref};
114 $self->say(channel
=> $s_chan,
120 if ($check_next{'new'} == 0){
121 my $articles_ref = get_queue
();
123 = grep {!($_->{pageid
} ~~ @known_pageids)} @
{$articles_ref};
126 for my $article (@new_articles) {$self->announce_page($article);}
128 #$self->say(channel=>$s_chan,body=>"First known pageid: $known_pageids[0]");
130 # Increment checked_last times
131 foreach(keys %check_next){
133 = $check_next{$_} <= 0
135 : $check_next{$_} - 5;
141 return "Wikinews Review queue spam module.";