A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ctcp.py 1.5 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. import platform
  3. import time
  4. from classes import BaseCommand
  5. import config
  6. class Command(BaseCommand):
  7. """Not an actual command, this module is used to respond to the CTCP
  8. commands PING, TIME, and VERSION."""
  9. name = "ctcp"
  10. hooks = ["msg_private"]
  11. def check(self, data):
  12. if data.is_command and data.command == "ctcp":
  13. return True
  14. commands = ["PING", "TIME", "VERSION"]
  15. msg = data.line[3]
  16. if msg[:2] == ":\x01" and msg[2:].rstrip("\x01") in commands:
  17. return True
  18. return False
  19. def process(self, data):
  20. if data.is_command:
  21. return
  22. target = data.nick
  23. command = data.line[3][1:].strip("\x01")
  24. if command == "PING":
  25. msg = " ".join(data.line[4:])
  26. if msg:
  27. self.connection.notice(target, "\x01PING {0}\x01".format(msg))
  28. else:
  29. self.connection.notice(target, "\x01PING\x01")
  30. elif command == "TIME":
  31. ts = time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime())
  32. self.connection.notice(target, "\x01TIME {0}\x01".format(ts))
  33. elif command == "VERSION":
  34. default = "EarwigBot - 0.1-dev - Python/$1 https://github.com/earwig/earwigbot"
  35. vers = config.metadata.get("ircVersion", default)
  36. vers = vers.replace("$1", platform.python_version())
  37. self.connection.notice(target, "\x01VERSION {0}\x01".format(vers))