A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

65 linhas
2.5 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 threading import Timer
  23. import time
  24. from earwigbot.commands import Command
  25. __all__ = ["Remind"]
  26. class Remind(Command):
  27. """Set a message to be repeated to you in a certain amount of time."""
  28. name = "remind"
  29. commands = ["remind", "reminder"]
  30. def process(self, data):
  31. if not data.args:
  32. msg = "please specify a time (in seconds) and a message in the following format: !remind <time> <msg>."
  33. self.reply(data, msg)
  34. return
  35. try:
  36. wait = int(data.args[0])
  37. except ValueError:
  38. msg = "the time must be given as an integer, in seconds."
  39. self.reply(data, msg)
  40. return
  41. message = ' '.join(data.args[1:])
  42. if not message:
  43. msg = "what message do you want me to give you when time is up?"
  44. self.reply(data, msg)
  45. return
  46. end = time.localtime(time.time() + wait)
  47. end_time = time.strftime("%b %d %H:%M:%S", end)
  48. end_time_with_timezone = time.strftime("%b %d %H:%M:%S %Z", end)
  49. msg = 'Set reminder for "{0}" in {1} seconds (ends {2}).'
  50. msg = msg.format(message, wait, end_time_with_timezone)
  51. self.reply(data, msg)
  52. t_reminder = Timer(wait, self.reply, args=(data, message))
  53. t_reminder.name = "reminder " + end_time
  54. t_reminder.daemon = True
  55. t_reminder.start()