No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import random
  2. from json import JSONDecodeError
  3. import checks
  4. import requests
  5. from discord.ext.commands import bot
  6. from config.server_config import ServerConfig
  7. class NFSW():
  8. def __init__(self, Bot):
  9. self.bot = Bot
  10. self.con = ServerConfig()
  11. self.servers = self.con.servers
  12. def is_nsfw_enabled(self, server_id):
  13. return self.servers[server_id]["nsfw"]["enabled"] == "1"
  14. def gelbooru_clone(self, base_url, tags):
  15. # Maybe a page randomiser
  16. limit = 100
  17. url = base_url + '/index.php?page=dapi&s=post&q=index&json=1&tags=' + tags + '&limit=' + str(limit)
  18. req = requests.get(url, headers={'User-agent': 'RoxBot Discord Bot'})
  19. if str(req.content) == "b''": # This is to catch any errors if the tags don't return anything because I can't do my own error handling in commands.
  20. post = None
  21. return post
  22. post = random.choice(req.json())
  23. return post
  24. @bot.command(pass_context=True)
  25. @checks.is_nfsw_enabled()
  26. async def e621(self, ctx, *, tags):
  27. """
  28. Returns an image from e621.com and can use tags you provide.
  29. """
  30. base_url = "https://e621.net/"
  31. limit = 150
  32. url = base_url + 'post/index.json?tags=' + tags + '&limit=' + str(limit)
  33. req = requests.get(url, headers = {'User-agent': 'RoxBot Discord Bot'})
  34. if str(req.content) == "b'[]'": # This is to catch any errors if the tags don't return anything because I can't do my own error handling in commands.
  35. return await self.bot.say("Nothing was found. *psst, check the tags you gave me.*")
  36. post = random.choice(req.json())
  37. return await self.bot.say(post["file_url"])
  38. @bot.command(pass_context=True)
  39. @checks.is_nfsw_enabled()
  40. async def rule34(self, ctx, *, tags):
  41. """
  42. Returns an image from rule34.xxx and can use tags you provide.
  43. """
  44. base_url = "https://rule34.xxx"
  45. post = self.gelbooru_clone(base_url, tags)
  46. if not post:
  47. return await self.bot.say("Nothing was found. *psst, check the tags you gave me.*")
  48. url = "https://img.rule34.xxx/images/" + post["directory"] + "/" + post["image"]
  49. return await self.bot.say(url)
  50. @bot.command(pass_context=True)
  51. @checks.is_nfsw_enabled()
  52. async def gelbooru(self, ctx, *, tags):
  53. """
  54. Returns an image from gelbooru.com and can use tags you provide.
  55. """
  56. base_url = "https://gelbooru.com"
  57. post = self.gelbooru_clone(base_url, tags)
  58. if not post:
  59. return await self.bot.say("Nothing was found. *psst, check the tags you gave me.*")
  60. url = "https://simg3.gelbooru.com/images/" + ''.join(post["directory"].split("\\")) + "/" + post["image"]
  61. return await self.bot.say(url)
  62. def setup(Bot):
  63. Bot.add_cog(NFSW(Bot))