A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

44 Zeilen
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. from classes import BaseCommand, Data
  3. import commands
  4. class Command(BaseCommand):
  5. """Displays help information."""
  6. name = "help"
  7. def process(self, data):
  8. self.cmnds = commands.get_all()
  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 = msg.format(len(self.cmnds.keys()), ', '.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(1)
  24. dummy.command = command.lower()
  25. dummy.is_command = True
  26. for cmnd in self.cmnds.values():
  27. if cmnd.check(dummy):
  28. doc = cmnd.__doc__
  29. if doc:
  30. msg = "info for command \x0303{0}\x0301: \"{1}\""
  31. self.connection.reply(data, msg.format(command, doc))
  32. return
  33. break
  34. msg = "sorry, no help for \x0303{0}\x0301.".format(command)
  35. self.connection.reply(data, msg)