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

45 行
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. from classes import BaseCommand, Data
  3. import commands
  4. class Command(BaseCommand):
  5. """Generates help information."""
  6. name = "help"
  7. def process(self, data):
  8. self.cmnds = commands.get_all().keys()
  9. if not data.args:
  10. self.do_main_help(data)
  11. else:
  12. self.do_command_help(data)
  13. def do_main_help(self, data):
  14. """Give the user a general help message with a list of all commands."""
  15. msg = "I am a bot! I have {0} commands loaded: {1}. You can get help for any command with '!help <command>'."
  16. msg.format(len(self.cmnds), ', '.join(self.cmnds))
  17. self.connection.reply(data, msg)
  18. def do_command_help(self, data):
  19. """Give the user help for a specific command."""
  20. command = data.args[0]
  21. # Create a dummy message to test which commands pick up the user's
  22. # input:
  23. dummy = Data()
  24. dummy.command = command.lower()
  25. dummy.is_command = True
  26. for cmnd in self.cmnds:
  27. if cmnd.check(dummy):
  28. doc = cmnd.__doc__
  29. if doc:
  30. msg = "info for command \x0303{0}\x0301: \"{1}\""
  31. msg.format(command, doc)
  32. self.connection.reply(data, msg)
  33. return
  34. break
  35. msg = "sorry, no help for \x0303{0}\x0301.".format(command)
  36. self.connection.reply(data, msg)