# User:Eidobot
Eidobot is written by Eidolos. Please talk to him if you have any issues.

Source code
#!/usr/bin/perl

# Copyright (c) 2006 Shawn M Moore

# Permission is hereby granted, free of charge, to any person obtaining a copy 
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights 
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
# copies of the Software, and to permit persons to whom the Software is 
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in al
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

use strict;
use warnings;

use WWW::Mechanize;

# Eidobot 1.1
# Automates upload of new articles to NetHackWiki.

# It uploads every file it can in the directory called new_articles under the 
# current working directory.
# The filename corresponds exactly to the new article name.

# Change the name and pass variables to your bot's name/pass.

# If the summary variable is empty or undefined, it will instead use the first
# line of each article for its summary, removing it from the article body.

# TODO: More configuration options, error-checking.

our $name    = 'name';
our $pass    = 'pass';
our $summary = 'Automated article upload';
our $minor   = 1; # mark every edit as minor

our $sleep   = 30; # seconds to sleep after each new article

opendir(NEW_ARTICLES, 'new_articles') or die "Unable to open new_articles directory: $!";

our $mech = WWW::Mechanize-&gt;new(agent =&gt; "Eidobot 1.0");

# LOGIN
$mech-&gt;get("http://nethackwiki.com/index.php?title=Special:Userlogin");
$mech-&gt;submit_form
(
  form_name =&gt; 'userlogin',
  fields    =&gt; 
               {
                 wpName     =&gt; $name, 
                 wpPassword =&gt; $pass,
               },
);

# SUBMIT LOOP
foreach my $article (sort readdir(NEW_ARTICLES))
{
  next if -d $article;

  my $contents = do {local (@ARGV, $/) = "new_articles/$article"; &lt;&gt;};

  $article =~ s/ /_/g;

  if ($mech-&gt;get("http://nethackwiki.com/index.php?title=$article&amp;action=edit")-&gt;content()
      !~ /To create the page, start typing in the box below/)
  {
    warn "Existing article at $article. Skipping!";
    next;
  }

  $contents =~ s{ ^ (.*) $ \n }{}xm
    and local $summary = $1 
      if !defined($summary) || $summary eq '';

  print "Submitting new article \"$article\" (length " . length($contents) . ").\n";

  $mech-&gt;submit_form
  (
    form_name =&gt; 'editform',
    fields    =&gt;
                 {
                   wpTextbox1  =&gt; $contents,
                   wpSummary   =&gt; $summary,
                   wpMinoredit =&gt; $minor,
                 },
  );

  sleep($sleep) if defined($sleep) &amp;&amp; $sleep &gt; 0;
}