A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

help.py 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. # Generates help information.
  3. from irc.base_command import BaseCommand
  4. from irc.data import Data
  5. from irc import command_handler
  6. class Help(BaseCommand):
  7. def get_hook(self):
  8. return "msg"
  9. def get_help(self, command):
  10. return "Generates help information."
  11. def check(self, data):
  12. if data.is_command and data.command == "help":
  13. return True
  14. return False
  15. def process(self, data):
  16. if not data.args:
  17. self.do_general_help(data)
  18. else:
  19. self.do_command_help(data)
  20. def do_general_help(self, data):
  21. self.connection.reply(data, "I am a bot! You can get help for any command by typing '!help <command>'.")
  22. def do_command_help(self, data):
  23. command = data.args[0]
  24. commands = command_handler.get_commands()
  25. dummy = Data() # dummy message to test which command classes pick up this command
  26. dummy.command = command
  27. dummy.is_command = True
  28. for cmnd in commands:
  29. if cmnd.check(dummy):
  30. help = cmnd.get_help(command)
  31. break
  32. try:
  33. self.connection.reply(data, "info for command \x0303%s\x0301: \"%s\"" % (command, help))
  34. except UnboundLocalError:
  35. self.connection.reply(data, "sorry, no help for \x0303%s\x0301." % command)