summaryrefslogtreecommitdiffstats
path: root/lib/Crawl/Bot/Plugin/Wiki.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Crawl/Bot/Plugin/Wiki.pm')
-rw-r--r--lib/Crawl/Bot/Plugin/Wiki.pm52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/Crawl/Bot/Plugin/Wiki.pm b/lib/Crawl/Bot/Plugin/Wiki.pm
new file mode 100644
index 0000000..9e08159
--- /dev/null
+++ b/lib/Crawl/Bot/Plugin/Wiki.pm
@@ -0,0 +1,52 @@
+package Crawl::Bot::Plugin::Wiki;
+use Moose;
+
+use XML::RPC;
+
+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_all("$change->{author} created page $name at "
+ . $self->wiki_base . "$change->{name}");
+ }
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;