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.

49 linhas
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. """Generates help information."""
  3. connection, data = None, None
  4. def get_alias(key):
  5. """connect command aliases with their file, e.g. so we know !voice corresponds to chanops.py"""
  6. aliases = {
  7. "voice": "chanops",
  8. "devoice": "chanops",
  9. "op": "chanops",
  10. "deop": "chanops",
  11. }
  12. return aliases[key]
  13. def call(c, d):
  14. global connection, data
  15. connection, data = c, d
  16. if not data.args:
  17. do_general_help()
  18. else:
  19. do_command_help()
  20. def do_general_help():
  21. connection.reply(data.chan, data.nick, "I am a bot! You can get help for any command by typing '!help <command>'.")
  22. def do_command_help():
  23. command = data.args[0]
  24. try:
  25. exec "from irc.commands import %s as this_command" % command
  26. except ImportError: # if we can't find it directly, this could be an alias for another command
  27. try:
  28. cmd = get_alias(command)
  29. except KeyError:
  30. connection.reply(data.chan, data.nick, "command \x0303%s\x0301 not found!" % command)
  31. return
  32. exec "from irc.commands import %s as this_command" % cmd
  33. info = this_command.__doc__
  34. if info:
  35. connection.reply(data.chan, data.nick, "info for command \x0303%s\x0301: \"%s\"" % (command, info))
  36. else:
  37. connection.reply(data.chan, data.nick, "sorry, no information for \x0303%s\x0301." % command)