A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. EarwigBot
  2. =========
  3. EarwigBot_ is a Python_ robot that edits Wikipedia_ and interacts with people
  4. over IRC_. This file provides a basic overview of how to install and setup the
  5. bot; more detailed information is located in the ``docs/`` directory (available
  6. online at PyPI_).
  7. History
  8. -------
  9. Development began, based on the `Pywikipedia framework`_, in early 2009.
  10. Approval for its fist task, a `copyright violation detector`_, was carried out
  11. in May, and the bot has been running consistently ever since (with the
  12. exception of Jan/Feb 2011). It currently handles `several ongoing tasks`_
  13. ranging from statistics generation to category cleanup, and on-demand tasks
  14. such as WikiProject template tagging. Since it started running, the bot has
  15. made over 50,000 edits.
  16. A project to rewrite it from scratch began in early April 2011, thus moving
  17. away from the Pywikipedia framework and allowing for less overall code, better
  18. integration between bot parts, and easier maintenance.
  19. Installation
  20. ------------
  21. This package contains the core ``earwigbot``, abstracted enough that it should
  22. be usable and customizable by anyone running a bot on a MediaWiki site. Since
  23. it is component-based, the IRC components can be disabled if desired. IRC
  24. commands and bot tasks specific to `my instance of EarwigBot`_ that I don't
  25. feel the average user will need are available from the repository
  26. `earwigbot-plugins`_.
  27. It's recommended to run the bot's unit tests before installing. Run ``python
  28. setup.py test`` from the project's root directory. Note that some
  29. tests require an internet connection, and others may take a while to run.
  30. Coverage is currently rather incomplete.
  31. Latest release (v0.1)
  32. ~~~~~~~~~~~~~~~~~~~~~
  33. EarwigBot is available from the `Python Package Index`_, so you can install the
  34. latest release with ``pip install earwigbot`` (`get pip`_).
  35. If you get an error while pip is installing dependencies, you may be missing
  36. some header files. For example, on Ubuntu, see `this StackOverflow post`_.
  37. You can also install it from source [1]_ directly::
  38. curl -Lo earwigbot.tgz https://github.com/earwig/earwigbot/tarball/v0.1
  39. tar -xf earwigbot.tgz
  40. cd earwig-earwigbot-*
  41. python setup.py install
  42. cd ..
  43. rm -r earwigbot.tgz earwig-earwigbot-*
  44. Development version
  45. ~~~~~~~~~~~~~~~~~~~
  46. You can install the development version of the bot from ``git`` by using
  47. setuptools's ``develop`` command [1]_, probably on the ``develop`` branch which
  48. contains (usually) working code. ``master`` contains the latest release.
  49. EarwigBot uses `git flow`_, so you're free to browse by tags or by new features
  50. (``feature/*`` branches)::
  51. git clone git://github.com/earwig/earwigbot.git earwigbot
  52. cd earwigbot
  53. python setup.py develop
  54. Setup
  55. -----
  56. The bot stores its data in a "working directory", including its config file and
  57. databases. This is also the location where you will place custom IRC commands
  58. and bot tasks, which will be explained later. It doesn't matter where this
  59. directory is, as long as the bot can write to it.
  60. Start the bot with ``earwigbot path/to/working/dir``, or just ``earwigbot`` if
  61. the working directory is the current directory. It will notice that no
  62. ``config.yml`` file exists and take you through the setup process.
  63. There is currently no way to edit the ``config.yml`` file from within the bot
  64. after it has been created, but YAML is a very straightforward format, so you
  65. should be able to make any necessary changes yourself. Check out the
  66. `explanation of YAML`_ on Wikipedia for help.
  67. After setup, the bot will start. This means it will connect to the IRC servers
  68. it has been configured for, schedule bot tasks to run at specific times, and
  69. then wait for instructions (as commands on IRC). For a list of commands, say
  70. "``!help``" (commands are messages prefixed with an exclamation mark).
  71. You can stop the bot at any time with Control+C, same as you stop a normal
  72. Python program, and it will try to exit safely. You can also use the
  73. "``!quit``" command on IRC.
  74. Customizing
  75. -----------
  76. The bot's working directory contains a ``commands`` subdirectory and a
  77. ``tasks`` subdirectory. Custom IRC commands can be placed in the former,
  78. whereas custom wiki bot tasks go into the latter. Developing custom modules is
  79. explained below, and in more detail through the bot's documentation on PyPI_
  80. (or in the ``docs/`` dir).
  81. Note that custom commands will override built-in commands and tasks with the
  82. same name.
  83. ``Bot`` and ``BotConfig``
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~
  85. `earwigbot.bot.Bot`_ is EarwigBot's main class. You don't have to instantiate
  86. this yourself, but it's good to be familiar with its attributes and methods,
  87. because it is the main way to communicate with other parts of the bot. A
  88. ``Bot`` object is accessible as an attribute of commands and tasks (i.e.,
  89. ``self.bot``).
  90. `earwigbot.config.BotConfig`_ stores configuration information for the bot. Its
  91. docstring explains what each attribute is used for, but essentially each "node"
  92. (one of ``config.components``, ``wiki``, ``irc``, ``commands``, ``tasks``, and
  93. ``metadata``) maps to a section of the bot's ``config.yml`` file. For example,
  94. if ``config.yml`` includes something like::
  95. irc:
  96. frontend:
  97. nick: MyAwesomeBot
  98. channels:
  99. - "##earwigbot"
  100. - "#channel"
  101. - "#other-channel"
  102. ...then ``config.irc["frontend"]["nick"]`` will be ``"MyAwesomeBot"`` and
  103. ``config.irc["frontend"]["channels"]`` will be ``["##earwigbot", "#channel",
  104. "#other-channel"]``.
  105. Custom IRC commands
  106. ~~~~~~~~~~~~~~~~~~~
  107. Custom commands are subclasses of `earwigbot.commands.Command`_ that override
  108. ``Command``'s ``process()`` (and optionally ``check()``, ``setup()``, or
  109. ``unload()``) methods.
  110. The bot has a wide selection of built-in commands and plugins to act as sample
  111. code and/or to give ideas. Start with test_, and then check out chanops_ and
  112. afc_status_ for some more complicated scripts.
  113. Custom bot tasks
  114. ~~~~~~~~~~~~~~~~
  115. Custom tasks are subclasses of `earwigbot.tasks.Task`_ that override ``Task``'s
  116. ``run()`` (and optionally ``setup()`` or ``unload()``) methods.
  117. See the built-in wikiproject_tagger_ task for a relatively straightforward
  118. task, or the afc_statistics_ plugin for a more complicated one.
  119. The Wiki Toolset
  120. ----------------
  121. EarwigBot's answer to the `Pywikipedia framework`_ is the Wiki Toolset
  122. (``earwigbot.wiki``), which you will mainly access through ``bot.wiki``.
  123. ``bot.wiki`` provides three methods for the management of Sites -
  124. ``get_site()``, ``add_site()``, and ``remove_site()``. Sites are objects that
  125. simply represent a MediaWiki site. A single instance of EarwigBot (i.e. a
  126. single *working directory*) is expected to relate to a single site or group of
  127. sites using the same login info (like all WMF wikis with CentralAuth).
  128. Load your default site (the one that you picked during setup) with
  129. ``site = bot.wiki.get_site()``.
  130. Not all aspects of the toolset are covered in the docs. Explore `its code and
  131. docstrings`_ to learn how to use it in a more hands-on fashion. For reference,
  132. ``bot.wiki`` is an instance of ``earwigbot.wiki.SitesDB`` tied to the
  133. ``sites.db`` file in the bot's working directory.
  134. Footnotes
  135. ---------
  136. - Questions, comments, or suggestions about the documentation? `Let me know`_
  137. so I can improve it for other people.
  138. .. [1] ``python setup.py install``/``develop`` may require root, or use the
  139. ``--user`` switch to install for the current user only.
  140. .. _EarwigBot: http://en.wikipedia.org/wiki/User:EarwigBot
  141. .. _Python: http://python.org/
  142. .. _Wikipedia: http://en.wikipedia.org/
  143. .. _IRC: http://en.wikipedia.org/wiki/Internet_Relay_Chat
  144. .. _PyPI: http://packages.python.org/earwigbot
  145. .. _Pywikipedia framework: http://pywikipediabot.sourceforge.net/
  146. .. _copyright violation detector: http://en.wikipedia.org/wiki/Wikipedia:Bots/Requests_for_approval/EarwigBot_1
  147. .. _several ongoing tasks: http://en.wikipedia.org/wiki/User:EarwigBot#Tasks
  148. .. _my instance of EarwigBot: http://en.wikipedia.org/wiki/User:EarwigBot
  149. .. _earwigbot-plugins: https://github.com/earwig/earwigbot-plugins
  150. .. _Python Package Index: https://pypi.python.org/pypi/earwigbot
  151. .. _get pip: http://pypi.python.org/pypi/pip
  152. .. _this StackOverflow post: http://stackoverflow.com/questions/6504810/how-to-install-lxml-on-ubuntu/6504860#6504860
  153. .. _git flow: http://nvie.com/posts/a-successful-git-branching-model/
  154. .. _explanation of YAML: http://en.wikipedia.org/wiki/YAML
  155. .. _earwigbot.bot.Bot: https://github.com/earwig/earwigbot/blob/develop/earwigbot/bot.py
  156. .. _earwigbot.config.BotConfig: https://github.com/earwig/earwigbot/blob/develop/earwigbot/config.py
  157. .. _earwigbot.commands.Command: https://github.com/earwig/earwigbot/blob/develop/earwigbot/commands/__init__.py
  158. .. _test: https://github.com/earwig/earwigbot/blob/develop/earwigbot/commands/test.py
  159. .. _chanops: https://github.com/earwig/earwigbot/blob/develop/earwigbot/commands/chanops.py
  160. .. _afc_status: https://github.com/earwig/earwigbot-plugins/blob/develop/commands/afc_status.py
  161. .. _earwigbot.tasks.Task: https://github.com/earwig/earwigbot/blob/develop/earwigbot/tasks/__init__.py
  162. .. _wikiproject_tagger: https://github.com/earwig/earwigbot/blob/develop/earwigbot/tasks/wikiproject_tagger.py
  163. .. _afc_statistics: https://github.com/earwig/earwigbot-plugins/blob/develop/tasks/afc_statistics.py
  164. .. _its code and docstrings: https://github.com/earwig/earwigbot/tree/develop/earwigbot/wiki
  165. .. _Let me know: ben.kurtovic@gmail.com