<commit_before>import json
import random
import aiohttp
from discord.ext.commands import bot

from Roxbot import checks
from Roxbot import guild_settings as gs


def tag_blacklist(guild):
	blacklist = ""
	for tag in gs.get(guild).nsfw["blacklist"]:
		blacklist += "-{} ".format(tag)
	return blacklist


class NFSW():
	def __init__(self, bot_client):
		self.bot = bot_client
		self.cache = {}
		for guild in self.bot.guilds:
			self.cache[guild.id] = []

	@checks.is_nfsw_enabled()
	@bot.command(hidden=True)
	async def gelbooru_clone(self, ctx, base_url, post_url, tags):
		limit = 150
		tags = tags + tag_blacklist(ctx.guild)
		url = base_url + tags + '&limit=' + str(limit)

		async with aiohttp.ClientSession() as session:
			async with session.get(url, headers={'User-agent': 'RoxBot Discord Bot'}) as resp:
				req = await resp.read()
		if str(req) == "b''":
			return await ctx.send("Nothing was found. *psst, check the tags you gave me.*")

		post = None
		counter = 0
		while counter < 20:
			post = random.choice(json.loads(req))
			md5 = post.get("md5")
			if not md5:
				md5 = post.get("hash")
			if md5 not in self.cache[ctx.guild.id]:
				self.cache[ctx.guild.id].append(md5)
				if len(self.cache[ctx.guild.id]) > 10:
					self.cache[ctx.guild.id].pop(0)
				break
			counter += 1

		url = post.get("file_url")<commit_msg>made the request a seperate function and did some more smarter variable assignments with the hash.<commit_after>import json
import random
import aiohttp
from discord.ext.commands import bot

from Roxbot import checks
from Roxbot import guild_settings as gs


def tag_blacklist(guild):
	blacklist = ""
	for tag in gs.get(guild).nsfw["blacklist"]:
		blacklist += "-{} ".format(tag)
	return blacklist


async def http_request(url):
	async with aiohttp.ClientSession() as session:
		async with session.get(url, headers={'User-agent': 'RoxBot Discord Bot'}) as resp:
			try:
				return json.loads(await resp.read())
			except json.JSONDecodeError:
				return None


class NFSW():
	def __init__(self, bot_client):
		self.bot = bot_client
		self.cache = {}
		for guild in self.bot.guilds:
			self.cache[guild.id] = []

	@checks.is_nfsw_enabled()
	@bot.command(hidden=True)
	async def gelbooru_clone(self, ctx, base_url, post_url, tags):
		limit = 150
		tags = tags + tag_blacklist(ctx.guild)
		url = base_url + tags + '&limit=' + str(limit)

		posts = await http_request(url)

		if posts is None:
			return await ctx.send("Nothing was found. *psst, check the tags you gave me.*")

		post = None
		counter = 0
		while counter < 20:
			post = random.choice(posts)
			md5 = post.get("md5") or post.get("hash")
			if md5 not in self.cache[ctx.guild.id]:
				self.cache[ctx.guild.id].append(md5)
				if len(self.cache[ctx.guild.id]) > 10:
					self.cache[ctx.guild.id].pop(0)
				break
			counter += 1

		url = post.get("file_url")
{'fraction_non_alphanumeric': 0.13200280112044818, 'fraction_numerical': 0.01050420168067227, 'mean_word_length': 3.7696160267111853, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5857633', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1022, 'n_words': 275}