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.

87 rivejä
2.8 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2012 Ben Kurtovic <ben.kurtovic@verizon.net>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. from os import path
  23. import sqlite3 as sqlite
  24. from threading import Lock
  25. from earwigbot.commands import Command
  26. class Notes(Command):
  27. """A mini IRC-based wiki for storing notes, tips, and reminders."""
  28. name = "notes"
  29. commands = ["notes", "note", "about"]
  30. version = 2
  31. def setup(self):
  32. self._dbfile = path.join(self.config.root_dir, "notes.db")
  33. self._db_access_lock = Lock()
  34. def process(self, data):
  35. commands = {
  36. "list": self.do_list,
  37. "read": self.do_read,
  38. "edit": self.do_edit,
  39. "rename": self.do_rename,
  40. "delete": self.do_delete,
  41. "info": self.do_info,
  42. }
  43. if not data.args:
  44. msg = "The Earwig Mini-Wiki: running v{0}. Subcommands are: {1}. You can get help on any with '!{2} help subcommand'."
  45. cmnds = ", ".join((commands))
  46. self.reply(data, msg.format(self.version, cmnds, data.command))
  47. return
  48. command = data.args[0].lower()
  49. if command in commands:
  50. commands[command](data)
  51. else:
  52. self.reply("Unknown subcommand: \x0303{0}\x0F.".format(command))
  53. def create_db(self, conn):
  54. """Initialize the notes database with its necessary tables."""
  55. script = """
  56. CREATE TABLE pages (page_id, page_title);
  57. CREATE TABLE users (user_id, user_name);
  58. CREATE TABLE revisions (rev_id, rev_page, rev_user, rev_content);
  59. """
  60. conn.executescript(script)
  61. def do_list(self):
  62. pass
  63. def do_read(self):
  64. pass
  65. def edit(self):
  66. pass
  67. def rename(self):
  68. pass
  69. def delete(self):
  70. pass
  71. def info(self):
  72. pass