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.

47 Zeilen
1.3 KiB

  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 triggers
  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 = triggers.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)