A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

remind.py 1.7 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. """
  3. Set a message to be repeated to you in a certain amount of time.
  4. """
  5. import threading
  6. import time
  7. from irc.classes import BaseCommand
  8. class Remind(BaseCommand):
  9. def get_hooks(self):
  10. return ["msg"]
  11. def get_help(self, command):
  12. return "Set a message to be repeated to you in a certain amount of time."
  13. def check(self, data):
  14. if data.is_command and data.command in ["remind", "reminder"]:
  15. return True
  16. return False
  17. def process(self, data):
  18. if not data.args:
  19. self.connection.reply(data, "please specify a time (in seconds) and a message in the following format: !remind <time> <msg>.")
  20. return
  21. try:
  22. wait = int(data.args[0])
  23. except ValueError:
  24. self.connection.reply(data, "the time must be given as an integer, in seconds.")
  25. return
  26. message = ' '.join(data.args[1:])
  27. if not message:
  28. self.connection.reply(data, "what message do you want me to give you when time is up?")
  29. return
  30. end_time = time.strftime("%b %d %H:%M:%S", time.localtime(time.time() + wait))
  31. end_time_with_timezone = time.strftime("%b %d %H:%M:%S %Z", time.localtime(time.time() + wait))
  32. self.connection.reply(data, 'Set reminder for "{0}" in {1} seconds (ends {2}).'.format(message, wait, end_time_with_timezone))
  33. t_reminder = threading.Thread(target=self.reminder, args=(data, message, wait))
  34. t_reminder.name = "reminder " + end_time
  35. t_reminder.daemon = True
  36. t_reminder.start()
  37. def reminder(self, data, message, wait):
  38. time.sleep(wait)
  39. self.connection.reply(data, message)