A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

55 rader
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # Generates help information.
  3. from irc.classes import BaseCommand, Data
  4. from irc import command_handler
  5. class Help(BaseCommand):
  6. def get_hooks(self):
  7. return ["msg"]
  8. def get_help(self, command):
  9. return "Generates help information."
  10. def check(self, data):
  11. if data.is_command and data.command == "help":
  12. return True
  13. return False
  14. def process(self, data):
  15. if not data.args:
  16. self.do_general_help(data)
  17. else:
  18. if data.args[0] == "list":
  19. self.do_list_help(data)
  20. else:
  21. self.do_command_help(data)
  22. def do_general_help(self, data):
  23. self.connection.reply(data, "I am a bot! You can get help for any command with '!help <command>', or a list of all loaded modules with '!help list'.")
  24. def do_list_help(self, data):
  25. commands = command_handler.get_commands()
  26. cmnds = map(lambda c: c.__class__.__name__, commands)
  27. pretty_cmnds = ', '.join(cmnds)
  28. self.connection.reply(data, "%s command classes loaded: %s." % (len(cmnds), pretty_cmnds))
  29. def do_command_help(self, data):
  30. command = data.args[0]
  31. commands = command_handler.get_commands()
  32. dummy = Data() # dummy message to test which command classes pick up this command
  33. dummy.command = command.lower() # lowercase command name
  34. dummy.is_command = True
  35. for cmnd in commands:
  36. if cmnd.check(dummy):
  37. help = cmnd.get_help(command)
  38. break
  39. try:
  40. self.connection.reply(data, "info for command \x0303%s\x0301: \"%s\"" % (command, help))
  41. except UnboundLocalError:
  42. self.connection.reply(data, "sorry, no help for \x0303%s\x0301." % command)