Additional IRC commands and bot tasks for EarwigBot https://en.wikipedia.org/wiki/User:EarwigBot
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

60 linhas
2.5 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2013 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.commands import Command
  23. class AFCSubmissions(Command):
  24. """Link the user directly to some pending AFC submissions."""
  25. name = "submissions"
  26. commands = ["submissions", "subs"]
  27. def setup(self):
  28. try:
  29. self.ignore_list = self.config.commands[self.name]["ignoreList"]
  30. except KeyError:
  31. try:
  32. ignores = self.config.tasks["afc_statistics"]["ignoreList"]
  33. self.ignore_list = ignores
  34. except KeyError:
  35. self.ignore_list = []
  36. def process(self, data):
  37. if data.args:
  38. try:
  39. number = int(data.args[0])
  40. except ValueError:
  41. self.reply(data, "Argument must be a number.")
  42. return
  43. if number > 5:
  44. msg = "Cannot get more than five submissions at a time."
  45. self.reply(data, msg)
  46. return
  47. else:
  48. number = 3
  49. site = self.bot.wiki.get_site()
  50. category = site.get_category("Pending AfC submissions")
  51. members = category.get_members(limit=number + len(self.ignore_list))
  52. urls = [member.url.encode("utf8") for member in members if member.title not in self.ignore_list]
  53. pages = ", ".join(urls[:number])
  54. self.reply(data, "{0} pending AfC subs: {1}".format(number, pages))