A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

base_command.py 1.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. """Constructor for new commands.
  14. This is called once when the command is loaded (from
  15. commands._load_command()). `connection` is a Connection object,
  16. allowing us to do self.connection.say(), self.connection.send(), etc,
  17. from within a method.
  18. """
  19. self.connection = connection
  20. def check(self, data):
  21. """Returns whether this command should be called in response to 'data'.
  22. Given a Data() instance, return True if we should respond to this
  23. activity, or False if we should ignore it or it doesn't apply to us.
  24. Most commands return True if data.command == self.name, otherwise they
  25. return False. This is the default behavior of check(); you need only
  26. override it if you wish to change that.
  27. """
  28. if data.is_command and data.command == self.name:
  29. return True
  30. return False
  31. def process(self, data):
  32. """Main entry point for doing a command.
  33. Handle an activity (usually a message) on IRC. At this point, thanks
  34. to self.check() which is called automatically by the command handler,
  35. we know this is something we should respond to, so (usually) something
  36. like 'if data.command != "command_name": return' is unnecessary.
  37. """
  38. pass