EarwigBot is a Python robot that edits Wikipedia and interacts with people over IRC.
See README.rst for an overview, or the docs/ directory for details. This documentation is also available online.
EarwigBot: Main Bot Class
The Bot class is the core of EarwigBot, essentially responsible for starting the various bot components and making sure they are all happy.
EarwigBot has three components that can run independently of each other: an IRC front-end, an IRC watcher, and a wiki scheduler.
The Bot object is accessible from within commands and tasks as self.bot. This is the primary way to access data from other components of the bot. For example, our BotConfig object is accessable from bot.config, tasks can be started with bot.tasks.start(), and sites can be loaded from the wiki toolset with bot.wiki.get_site().
Whether or not the bot is currently running.
This may return False even if the bot is still technically active, but in the process of shutting down.
Reload config, commands, tasks, and safely restart IRC components.
This is thread-safe, and it will gracefully stop IRC components before reloading anything. Note that you can safely reload commands or tasks without restarting the bot with bot.commands.load() or bot.tasks.load(). These should not interfere with running components or tasks.
If given, msg will be used as our quit message.
EarwigBot: Exceptions
This module contains all exceptions used by EarwigBot:
EarwigBotError
+-- NoConfigError
+-- IRCError
| +-- BrokenSocketError
+-- WikiToolsetError
+-- SiteNotFoundError
+-- ServiceError
| +-- APIError
| +-- SQLError
+-- NoServiceError
+-- LoginError
+-- PermissionsError
+-- NamespaceNotFoundError
+-- PageNotFoundError
+-- InvalidPageError
+-- RedirectError
+-- UserNotFoundError
+-- EditError
| +-- EditConflictError
| +-- NoContentError
| +-- ContentTooBigError
| +-- SpamDetectedError
| +-- FilteredError
+-- CopyvioCheckError
+-- UnknownSearchEngineError
+-- UnsupportedSearchEngineError
+-- SearchQueryError
+-- ParserExclusionError
Bases: earwigbot.exceptions.ServiceError
Couldn’t connect to a site’s API.
Perhaps the server doesn’t exist, our URL is wrong or incomplete, or there are temporary problems on their end.
Raised by Site.api_query.
Bases: earwigbot.exceptions.IRCError
A socket has broken, because it is not sending data.
Raised by IRCConnection._get.
Bases: earwigbot.exceptions.EditError
The edit we tried to push exceeded the article size limit.
Raised by Page.edit and Page.add_section.
Bases: earwigbot.exceptions.WikiToolsetError
An error occured when checking a page for copyright violations.
This is a base class for multiple exceptions; usually one of those will be raised instead of this.
Raised by Page.copyvio_check and Page.copyvio_compare.
Bases: exceptions.Exception
Base exception class for errors in EarwigBot.
Bases: earwigbot.exceptions.EditError
We gotten an edit conflict or a (rarer) delete/recreate conflict.
Raised by Page.edit and Page.add_section.
Bases: earwigbot.exceptions.WikiToolsetError
An error occured while editing.
This is used as a base class for all editing errors; this one specifically is used only when a generic error occurs that we don’t know about.
Raised by Page.edit and Page.add_section.
Bases: earwigbot.exceptions.EditError
The edit filter refused our edit.
Raised by Page.edit and Page.add_section.
Bases: earwigbot.exceptions.EarwigBotError
Base exception class for errors in IRC-relation sections of the bot.
Bases: earwigbot.exceptions.WikiToolsetError
Attempted to get information about a page whose title is invalid.
Raised by Page.
Bases: earwigbot.exceptions.WikiToolsetError
An error occured while trying to login.
Perhaps the username/password is incorrect.
Raised by Site._login.
Bases: earwigbot.exceptions.WikiToolsetError
A requested namespace name or namespace ID does not exist.
Raised by Site.namespace_id_to_name and Site.namespace_name_to_id.
Bases: earwigbot.exceptions.EarwigBotError
The bot cannot be run without a config file.
This occurs if no config file exists, and the user said they did not want one to be created.
Bases: earwigbot.exceptions.EditError
We tried to create a page or new section with no content.
Raised by Page.edit and Page.add_section.
Bases: earwigbot.exceptions.WikiToolsetError
No service is functioning to handle a specific task.
Raised by Site.delegate.
Bases: earwigbot.exceptions.WikiToolsetError
Attempted to get information about a page that does not exist.
Raised by Page.
Bases: earwigbot.exceptions.CopyvioCheckError
A content parser detected that the given source should be excluded.
Raised internally by Page.copyvio_check; should not be exposed in client code.
Bases: earwigbot.exceptions.WikiToolsetError
A permissions error ocurred.
We tried to do something we don’t have permission to, like trying to delete a page as a non-admin, or trying to edit a page without login information and AssertEdit enabled. This will also be raised if we have been blocked from editing.
Raised by Page.edit, Page.add_section, and other API methods depending on settings.
Bases: earwigbot.exceptions.WikiToolsetError
A redirect-only method was called on a malformed or non-redirect page.
Raised by Page.get_redirect_target.
Bases: earwigbot.exceptions.ServiceError
Some error involving SQL querying occurred.
Raised by Site.sql_query.
Bases: earwigbot.exceptions.CopyvioCheckError
Some error ocurred while doing a search query.
Raised by Page.copyvio_check.
Bases: earwigbot.exceptions.WikiToolsetError
Base exception class for an error within a service (the API or SQL).
This is caught by Site.delegate to indicate a service is non-functional so another, less-preferred one can be tried.
Bases: earwigbot.exceptions.WikiToolsetError
A particular site could not be found in the sites database.
Raised by SitesDB.
Bases: earwigbot.exceptions.EditError
The spam filter refused our edit.
Raised by Page.edit and Page.add_section.
Bases: earwigbot.exceptions.CopyvioCheckError
Attempted to do a copyvio check with an unknown search engine.
Search engines are specified in config.yml as config.wiki["search"]["engine"].
Raised by Page.copyvio_check.
Bases: earwigbot.exceptions.CopyvioCheckError
Attmpted to do a copyvio check using an unavailable engine.
This might occur if, for example, an engine requires oauth2 but the package couldn’t be imported.
Raised by Page.copyvio_check.
Bases: earwigbot.exceptions.WikiToolsetError
Attempted to get certain information about a user that does not exist.
Raised by User.
Bases: earwigbot.exceptions.EarwigBotError
Base exception class for errors in the Wiki Toolset.
Implements a hierarchy of importing classes as defined in PEP 302 to load modules in a safe yet lazy manner, so that they can be referred to by name but are not actually loaded until they are used (i.e. their attributes are read or modified).
Bases: object
EarwigBot: Resource Manager
Resources are essentially objects dynamically loaded by the bot, both packaged with it (built-in resources) and created by users (plugins, aka custom resources). Currently, the only two types of resources are IRC commands and bot tasks. These are both loaded from two locations: the earwigbot.commands and earwigbot.tasks packages, and the commands/ and tasks/ directories within the bot’s working directory.
This class handles the low-level tasks of (re)loading resources via load(), retrieving specific resources via get(), and iterating over all resources via __iter__().
Bases: earwigbot.managers._ResourceManager
Manages (i.e., loads, reloads, and calls) IRC commands.
Bases: earwigbot.managers._ResourceManager
Manages (i.e., loads, reloads, schedules, and runs) wiki bot tasks.
Start a given task in a new daemon thread, and return the thread.
kwargs are passed to task.run(). If the task is not found, None will be returned and an error will be logged.
usage: earwigbot [-h] [-v] [-d | -q] [-t NAME] [PATH] ...
This is EarwigBot’s command-line utility, enabling you to easily start the bot or run specific tasks.