A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

69 satır
2.5 KiB

  1. # Copyright (C) 2009-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. # SOFTWARE.
  20. import platform
  21. import time
  22. from earwigbot import __version__
  23. from earwigbot.commands import Command
  24. class CTCP(Command):
  25. """Not an actual command; this module implements responses to the CTCP
  26. requests PING, TIME, and VERSION."""
  27. name = "ctcp"
  28. hooks = ["msg_private"]
  29. def check(self, data):
  30. if data.is_command and data.command == "ctcp":
  31. return True
  32. commands = ["PING", "TIME", "VERSION"]
  33. msg = data.line[3]
  34. if msg[:2] == ":\x01" and msg[2:].rstrip("\x01") in commands:
  35. return True
  36. return False
  37. def process(self, data):
  38. if data.is_command:
  39. return
  40. target = data.nick
  41. command = data.line[3][1:].strip("\x01")
  42. if command == "PING":
  43. msg = " ".join(data.line[4:])
  44. if msg:
  45. self.notice(target, f"\x01PING {msg}\x01")
  46. else:
  47. self.notice(target, "\x01PING\x01")
  48. elif command == "TIME":
  49. ts = time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime())
  50. self.notice(target, f"\x01TIME {ts}\x01")
  51. elif command == "VERSION":
  52. default = "EarwigBot - $1 - Python/$2 https://github.com/earwig/earwigbot"
  53. vers = self.config.irc.get("version", default)
  54. vers = vers.replace("$1", __version__)
  55. vers = vers.replace("$2", platform.python_version())
  56. self.notice(target, f"\x01VERSION {vers}\x01")