A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 rivejä
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  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. class Quit(Command):
  24. """Quit, restart, or reload components from the bot. Only the owners can
  25. run this command."""
  26. name = "quit"
  27. commands = ["quit", "restart", "reload"]
  28. def process(self, data):
  29. if not self.config.irc["permissions"].is_owner(data):
  30. self.reply(data, "You must be a bot owner to use this command.")
  31. return
  32. if data.command == "quit":
  33. self.do_quit(data)
  34. elif data.command == "restart":
  35. self.do_restart(data)
  36. else:
  37. self.do_reload(data)
  38. def do_quit(self, data):
  39. args = data.args
  40. if data.trigger == data.my_nick:
  41. reason = " ".join(args)
  42. else:
  43. if not args or args[0].lower() != data.my_nick:
  44. self.reply(data, "To confirm this action, the first argument must be my name.")
  45. return
  46. reason = " ".join(args[1:])
  47. if reason:
  48. self.bot.stop("Stopped by {0}: {1}".format(data.nick, reason))
  49. else:
  50. self.bot.stop("Stopped by {0}".format(data.nick))
  51. def do_restart(self, data):
  52. if data.args:
  53. msg = " ".join(data.args)
  54. self.bot.restart("Restarted by {0}: {1}".format(data.nick, msg))
  55. else:
  56. self.bot.restart("Restarted by {0}".format(data.nick))
  57. def do_reload(self, data):
  58. self.logger.info("{0} requested command/task reload".format(data.nick))
  59. self.bot.commands.load()
  60. self.bot.tasks.load()
  61. self.reply(data, "IRC commands and bot tasks reloaded.")