summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-11-28 05:00:45 -0600
committerJesse Luehrs <doy@tozt.net>2009-11-28 05:00:45 -0600
commit0855b8d28197bb7f92594526fe5f3277d34f9e6d (patch)
tree1d172b8862d73065d69490e05dd2f254db4cdf85
parentb783f95169d9ee4ddb32ef07ba6546a341a948ed (diff)
downloadcrawlbot-0855b8d28197bb7f92594526fe5f3277d34f9e6d.tar.gz
crawlbot-0855b8d28197bb7f92594526fe5f3277d34f9e6d.zip
add code for checking the wiki for added pages
-rw-r--r--lib/Crawl/Bot.pm13
-rw-r--r--lib/Crawl/Bot/Wiki.pm63
2 files changed, 76 insertions, 0 deletions
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;