Additional IRC commands and bot tasks for EarwigBot https://en.wikipedia.org/wiki/User:EarwigBot
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

afc_report.py 3.8 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  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 earwigbot import wiki
  23. from earwigbot.commands import Command
  24. class AFCReport(Command):
  25. """Get information about an AFC submission by name."""
  26. name = "report"
  27. def process(self, data):
  28. self.site = self.bot.wiki.get_site()
  29. self.data = data
  30. try:
  31. self.statistics = self.bot.tasks.get("afc_statistics")
  32. except KeyError:
  33. e = "Cannot run command: requires afc_statistics task (from earwigbot_plugins)"
  34. self.logger.error(e)
  35. msg = "command requires afc_statistics task (from earwigbot_plugins)"
  36. self.reply(data, msg)
  37. return
  38. if not data.args:
  39. msg = "What submission do you want me to give information about?"
  40. self.reply(data, msg)
  41. return
  42. title = " ".join(data.args).replace("http://en.wikipedia.org/wiki/",
  43. "").replace("http://enwp.org/", "").strip()
  44. titles = [
  45. title, "Draft:" + title,
  46. "Wikipedia:Articles for creation/" + title,
  47. "Wikipedia talk:Articles for creation/" + title
  48. ]
  49. for attempt in titles:
  50. page = self.site.get_page(attempt, follow_redirects=False)
  51. if page.exists == page.PAGE_EXISTS:
  52. return self.report(page)
  53. self.reply(data, "Submission \x0302{0}\x0F not found.".format(title))
  54. def report(self, page):
  55. url = page.url.encode("utf8")
  56. url = url.replace("en.wikipedia.org/wiki", "enwp.org")
  57. status = self.get_status(page)
  58. user = page.get_creator()
  59. user_name = user.name
  60. user_url = user.get_talkpage().url.encode("utf8")
  61. msg1 = "AfC submission report for \x0302{0}\x0F ({1}):"
  62. msg2 = "Status: \x0303{0}\x0F"
  63. msg3 = "Submitted by \x0302{0}\x0F ({1})"
  64. if status == "accepted":
  65. msg3 = "Reviewed by \x0302{0}\x0F ({1})"
  66. self.reply(self.data, msg1.format(page.title.encode("utf8"), url))
  67. self.say(self.data.chan, msg2.format(status))
  68. self.say(self.data.chan, msg3.format(user_name, user_url))
  69. def get_status(self, page):
  70. if page.is_redirect:
  71. target = page.get_redirect_target()
  72. if self.site.get_page(target).namespace == wiki.NS_MAIN:
  73. return "accepted"
  74. return "redirect"
  75. statuses = self.statistics.get_statuses(page.get())
  76. if "R" in statuses:
  77. return "being reviewed"
  78. elif "H" in statuses:
  79. return "pending draft"
  80. elif "P" in statuses:
  81. return "pending submission"
  82. elif "T" in statuses:
  83. return "unsubmitted draft"
  84. elif "D" in statuses:
  85. return "declined"
  86. return "unkown"