Additional IRC commands and bot tasks for EarwigBot https://en.wikipedia.org/wiki/User:EarwigBot
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

67 rindas
2.6 KiB

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