A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

33 行
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. class BaseCommand(object):
  3. """A base class for commands on IRC."""
  4. def __init__(self, connection):
  5. self.connection = connection
  6. def get_hooks(self):
  7. """Hooks are: 'msg', 'msg_private', 'msg_public', and 'join'. Return
  8. the hooks you want this command to be called on."""
  9. return []
  10. def get_help(self, command):
  11. """Return help information for the command, used by !help. return None
  12. for no help. If a given class handles multiple commands, the command
  13. variable can be used to return different help for each one."""
  14. return None
  15. def check(self, data):
  16. """Given a Data() object, return True if we should respond to this
  17. activity, or False if we should ignore it/it doesn't apply to us. Most
  18. commands return True if data.command == 'command_name', otherwise
  19. they return False."""
  20. return False
  21. def process(self, data):
  22. """Handle an activity (usually a message) on IRC. At this point, thanks
  23. to self.check() which is called automatically by command_handler, we
  24. know this is something we should respond to, so (usually) a
  25. 'if data.command != "command_name": return' is unnecessary."""
  26. pass