Additional IRC commands and bot tasks for EarwigBot https://en.wikipedia.org/wiki/User:EarwigBot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.6 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 AfCSubmissions(Command):
  23. """Link the user directly to some pending AfC submissions."""
  24. name = "submissions"
  25. commands = ["submissions", "subs"]
  26. def setup(self):
  27. try:
  28. self.ignore_list = self.config.commands[self.name]["ignoreList"]
  29. except KeyError:
  30. try:
  31. ignores = self.config.tasks["afc_statistics"]["ignoreList"]
  32. self.ignore_list = ignores
  33. except KeyError:
  34. self.ignore_list = []
  35. def process(self, data):
  36. if data.args:
  37. try:
  38. number = int(data.args[0])
  39. except ValueError:
  40. self.reply(data, "Argument must be a number.")
  41. return
  42. if number > 5:
  43. msg = "Cannot get more than five submissions at a time."
  44. self.reply(data, msg)
  45. return
  46. else:
  47. number = 3
  48. site = self.bot.wiki.get_site()
  49. category = site.get_category("Pending AfC submissions")
  50. members = category.get_members(limit=50)
  51. urls = []
  52. for member in members:
  53. if member.title in self.ignore_list:
  54. continue
  55. if member.namespace == wiki.NS_CATEGORY:
  56. continue
  57. urls.append(member.url.encode("utf8"))
  58. pages = ", ".join(urls[:number])
  59. self.reply(data, f"{number} pending AfC subs: {pages}")