Additional IRC commands and bot tasks for EarwigBot https://en.wikipedia.org/wiki/User:EarwigBot
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

113 行
4.2 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2013 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)
  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. status = self.get_status(page)
  68. user = page.get_creator()
  69. user_name = user.name
  70. user_url = user.get_talkpage().url.encode("utf8")
  71. msg1 = "AfC submission report for \x0302{0}\x0F ({1}):"
  72. msg2 = "Status: \x0303{0}\x0F"
  73. msg3 = "Submitted by \x0302{0}\x0F ({1})"
  74. if status == "accepted":
  75. msg3 = "Reviewed by \x0302{0}\x0F ({1})"
  76. self.reply(self.data, msg1.format(page.title.encode("utf8"), url))
  77. self.say(self.data.chan, msg2.format(status))
  78. self.say(self.data.chan, msg3.format(user_name, user_url))
  79. def get_status(self, page):
  80. if page.is_redirect:
  81. target = page.get_redirect_target()
  82. if self.site.get_page(target).namespace == wiki.NS_MAIN:
  83. return "accepted"
  84. return "redirect"
  85. statuses = self.statistics.get_statuses(page.get())
  86. if "R" in statuses:
  87. return "being reviewed"
  88. elif "H" in statuses:
  89. return "pending draft"
  90. elif "P" in statuses:
  91. return "pending submission"
  92. elif "T" in statuses:
  93. return "unsubmitted draft"
  94. elif "D" in statuses:
  95. return "declined"
  96. return "unkown"