Additional IRC commands and bot tasks for EarwigBot https://en.wikipedia.org/wiki/User:EarwigBot
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

104 рядки
3.9 KiB

  1. # Copyright (C) 2009-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. # SOFTWARE.
  20. from earwigbot import wiki
  21. from earwigbot.commands import Command
  22. class AfCReport(Command):
  23. """Get information about an AfC submission by name."""
  24. name = "report"
  25. def process(self, data):
  26. self.site = self.bot.wiki.get_site()
  27. self.data = data
  28. try:
  29. self.statistics = self.bot.tasks.get("afc_statistics")
  30. except KeyError:
  31. e = "Cannot run command: requires afc_statistics task (from earwigbot_plugins)"
  32. self.logger.error(e)
  33. msg = "command requires afc_statistics task (from earwigbot_plugins)"
  34. self.reply(data, msg)
  35. return
  36. if not data.args:
  37. msg = "What submission do you want me to give information about?"
  38. self.reply(data, msg)
  39. return
  40. title = (
  41. " ".join(data.args)
  42. .replace("http://en.wikipedia.org/wiki/", "")
  43. .replace("http://enwp.org/", "")
  44. .strip()
  45. )
  46. titles = [
  47. title,
  48. "Draft:" + title,
  49. "Wikipedia:Articles for creation/" + title,
  50. "Wikipedia talk:Articles for creation/" + title,
  51. ]
  52. for attempt in titles:
  53. page = self.site.get_page(attempt, follow_redirects=False)
  54. if page.exists == page.PAGE_EXISTS:
  55. return self.report(page)
  56. self.reply(data, f"Submission \x0302{title}\x0f not found.")
  57. def report(self, page):
  58. url = page.url.encode("utf8")
  59. url = url.replace("en.wikipedia.org/wiki", "enwp.org")
  60. status = self.get_status(page)
  61. user = page.get_creator()
  62. user_name = user.name
  63. user_url = user.get_talkpage().url.encode("utf8")
  64. msg1 = "AfC submission report for \x0302{0}\x0f ({1}):"
  65. msg2 = "Status: \x0303{0}\x0f"
  66. msg3 = "Submitted by \x0302{0}\x0f ({1})"
  67. if status == "accepted":
  68. msg3 = "Reviewed by \x0302{0}\x0f ({1})"
  69. self.reply(self.data, msg1.format(page.title.encode("utf8"), url))
  70. self.say(self.data.chan, msg2.format(status))
  71. self.say(self.data.chan, msg3.format(user_name, user_url))
  72. def get_status(self, page):
  73. if page.is_redirect:
  74. target = page.get_redirect_target()
  75. if self.site.get_page(target).namespace == wiki.NS_MAIN:
  76. return "accepted"
  77. return "redirect"
  78. statuses = self.statistics.get_statuses(page.get())
  79. if "R" in statuses:
  80. return "being reviewed"
  81. elif "H" in statuses:
  82. return "pending draft"
  83. elif "P" in statuses:
  84. return "pending submission"
  85. elif "T" in statuses:
  86. return "unsubmitted draft"
  87. elif "D" in statuses:
  88. return "declined"
  89. return "unkown"