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.

42 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. class BaseCommand(object):
  3. """A base class for commands on IRC.
  4. This docstring is reported to the user when they use !help <command>.
  5. """
  6. # This is the command's name, as reported to the user when they use !help:
  7. name = "base_command"
  8. # Hooks are "msg", "msg_private", "msg_public", and "join". "msg" is the
  9. # default behavior; if you wish to override that, change the value in your
  10. # command subclass:
  11. hooks = ["msg"]
  12. def __init__(self, connection):
  13. self.connection = connection
  14. def check(self, data):
  15. """Returns whether this command should be called in response to 'data'.
  16. Given a Data() instance, return True if we should respond to this
  17. activity, or False if we should ignore it or it doesn't apply to us.
  18. Most commands return True if data.command == self.name, otherwise they
  19. return False. This is the default behavior of check(); you need only
  20. override it if you wish to change that.
  21. """
  22. if data.is_command and data.command == self.name:
  23. return True
  24. return False
  25. def process(self, data):
  26. """Main entry point for doing a command.
  27. Handle an activity (usually a message) on IRC. At this point, thanks
  28. to self.check() which is called automatically by command_handler, we
  29. know this is something we should respond to, so (usually) a
  30. 'if data.command != "command_name": return' is unnecessary.
  31. """
  32. pass