A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

71 řádky
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2012 by Ben Kurtovic <ben.kurtovic@verizon.net>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. from earwigbot.commands import Command
  23. __all__ = ["Quit"]
  24. class Quit(Command):
  25. """Quit, restart, or reload components from the bot. Only the owners can
  26. run this command."""
  27. name = "quit"
  28. commands = ["quit", "restart", "reload"]
  29. def process(self, data):
  30. if data.host not in self.config.irc["permissions"]["owners"]:
  31. self.reply(data, "you must be a bot owner to use this command.")
  32. return
  33. if data.command == "quit":
  34. self.do_quit(data)
  35. elif data.command == "restart":
  36. self.do_restart(data)
  37. else:
  38. self.do_reload(data)
  39. def do_quit(self, data):
  40. args = data.args
  41. if data.trigger == data.my_nick:
  42. reason = " ".join(args)
  43. else:
  44. if not args or args[0].lower() != data.my_nick:
  45. self.reply(data, "to confirm this action, the first argument must be my name.")
  46. return
  47. reason = " ".join(args[1:])
  48. if reason:
  49. self.bot.stop("Stopped by {0}: {1}".format(data.nick, reason))
  50. else:
  51. self.bot.stop("Stopped by {0}".format(data.nick))
  52. def do_restart(self, data):
  53. if data.args:
  54. msg = " ".join(data.args)
  55. self.bot.restart("Restarted by {0}: {1}".format(data.nick, msg))
  56. else:
  57. self.bot.restart("Restarted by {0}".format(data.nick))
  58. def do_reload(self, data):
  59. self.logger.info("{0} requested command/task reload".format(data.nick))
  60. self.bot.commands.load()
  61. self.bot.tasks.load()
  62. self.reply(data, "IRC commands and bot tasks reloaded.")