From 0855b8d28197bb7f92594526fe5f3277d34f9e6d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 28 Nov 2009 05:00:45 -0600 Subject: add code for checking the wiki for added pages --- lib/Crawl/Bot.pm | 13 +++++++++++ lib/Crawl/Bot/Wiki.pm | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 lib/Crawl/Bot/Wiki.pm (limited to 'lib') diff --git a/lib/Crawl/Bot.pm b/lib/Crawl/Bot.pm index 3b2fd70..47738fb 100644 --- a/lib/Crawl/Bot.pm +++ b/lib/Crawl/Bot.pm @@ -37,10 +37,22 @@ has mantis => ( }, ); +has wiki => ( + is => 'ro', + isa => 'Crawl::Bot::Wiki', + lazy => 1, + default => sub { + my $self = shift; + require Crawl::Bot::Wiki; + Crawl::Bot::Wiki->new(bot => $self); + }, +); + sub BUILD { my $self = shift; File::Path::mkpath($self->data_dir); $self->mantis; + $self->wiki; } before say => sub { @@ -52,6 +64,7 @@ before say => sub { sub tick { my $self = shift; $self->mantis->tick; + $self->wiki->tick; return $self->update_time; } diff --git a/lib/Crawl/Bot/Wiki.pm b/lib/Crawl/Bot/Wiki.pm new file mode 100644 index 0000000..dea004b --- /dev/null +++ b/lib/Crawl/Bot/Wiki.pm @@ -0,0 +1,63 @@ +package Crawl::Bot::Wiki; +use Moose; + +use XML::RPC; + +has bot => ( + is => 'ro', + isa => 'Crawl::Bot', + required => 1, + weak_ref => 1, + handles => [qw(say channels)], +); + +has xmlrpc_location => ( + is => 'ro', + isa => 'Str', + lazy => 1, + default => 'http://crawl.develz.org/wiki/lib/exe/xmlrpc.php', +); + +has wiki_base => ( + is => 'ro', + isa => 'Str', + lazy => 1, + default => 'http://crawl.develz.org/wiki/doku.php?id=', +); + +has last_checked => ( + is => 'rw', + isa => 'Int', +); + +sub tick { + my $self = shift; + my $last_checked = $self->last_checked; + $self->last_checked(time); + return unless $last_checked; + + my $xmlrpc = XML::RPC->new($self->xmlrpc_location); + warn "Getting recent wiki changes..."; + my $changes = $xmlrpc->call('wiki.getRecentChanges', $last_checked); + for my $change (@$changes) { + warn "Page $change->{name} changed"; + my $history = $xmlrpc->call('wiki.getPageVersions', $change->{name}, 0); + next if @$history; + warn "Page $change->{name} is new!"; + my $name = $change->{name}; + my $page = $xmlrpc->call('wiki.getPage', $change->{name}); + if ($page =~ /(===?=?=?=?) (.*) \1/) { + $name = $2; + } + $self->say( + channel => $_, + body => "$change->{author} created page $name at " + . $self->wiki_base . "$change->{name}", + ) for $self->channels; + } +} + +__PACKAGE__->meta->make_immutable; +no Moose; + +1; -- cgit v1.2.3-54-g00ecf