A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

63 Zeilen
2.5 KiB

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