Additional IRC commands and bot tasks for EarwigBot 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.

afc_report.py 4.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2012 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 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)
  43. title = title.replace("http://en.wikipedia.org/wiki/", "")
  44. title = title.replace("http://enwp.org/", "").strip()
  45. # Given '!report Foo', first try [[Foo]]:
  46. page = self.get_page(title)
  47. if page:
  48. return self.report(page)
  49. # Then try [[Wikipedia:Articles for creation/Foo]]:
  50. newtitle = "/".join(("Wikipedia:Articles for creation", title))
  51. page = self.get_page(newtitle)
  52. if page:
  53. return self.report(page)
  54. # Then try [[Wikipedia talk:Articles for creation/Foo]]:
  55. newtitle = "/".join(("Wikipedia talk:Articles for creation", title))
  56. page = self.get_page(newtitle)
  57. if page:
  58. return self.report(page)
  59. self.reply(data, "Submission \x0302{0}\x0F not found.".format(title))
  60. def get_page(self, title):
  61. page = self.site.get_page(title, follow_redirects=False)
  62. if page.exists == page.PAGE_EXISTS:
  63. return page
  64. def report(self, page):
  65. url = page.url.encode("utf8")
  66. url = url.replace("en.wikipedia.org/wiki", "enwp.org")
  67. short = self.statistics.get_short_title(page.title)
  68. status = self.get_status(page)
  69. user = page.get_creator()
  70. user_name = user.name
  71. user_url = user.get_talkpage().url.encode("utf8")
  72. msg1 = "AfC submission report for \x0302{0}\x0F ({1}):"
  73. msg2 = "Status: \x0303{0}\x0F"
  74. msg3 = "Submitted by \x0302{0}\x0F ({1})"
  75. if status == "accepted":
  76. msg3 = "Reviewed by \x0302{0}\x0F ({1})"
  77. self.reply(self.data, msg1.format(short, url))
  78. self.say(self.data.chan, msg2.format(status))
  79. self.say(self.data.chan, msg3.format(user_name, user_url))
  80. def get_status(self, page):
  81. if page.is_redirect:
  82. target = page.get_redirect_target()
  83. if self.site.get_page(target).namespace == wiki.NS_MAIN:
  84. return "accepted"
  85. return "redirect"
  86. statuses = self.statistics.get_statuses(page.get())
  87. if "R" in statuses:
  88. return "being reviewed"
  89. elif "H" in statuses:
  90. return "pending draft"
  91. elif "P" in statuses:
  92. return "pending submission"
  93. elif "T" in statuses:
  94. return "unsubmitted draft"
  95. elif "D" in statuses:
  96. return "declined"
  97. return "unkown"