A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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)