async def progeny(self, ctx, dragon1, dragon2, multiplier=10): if multiplier > 10: await ctx.send('The maximum multiplier is 10!') return if dragon1.isdigit(): pass else: dragon1 = fr.extract_dragon_id(dragon1) if dragon2.isdigit(): pass else: dragon2 = fr.extract_dragon_id(dragon2) outcomes = await fr.get_progeny(dragon1, dragon2, multiplier) if isinstance(outcomes, str): await ctx.send(outcomes) else: image_data = [] async with aiohttp.ClientSession() as session: # Create an AIOHTTP session for image in outcomes: async with session.get(image) as response: if response.status == 200: content = await response.read() content = io.BytesIO(content) image_data.append(content) image = generate_image(image_data, multiplier) output_buffer = io.BytesIO() # Convert the PIL output into bytes image.save(output_buffer, 'png') # Save the bytes as a PNG format output_buffer.seek(0) await ctx.send(file=discord.File(fp=output_buffer, filename='pet.png'))
async def cprogeny(self, ctx, dragon1, dragon2, element="shadow"): elements = { "earth": "1", "plague": "2", "wind": "3", "water": "4", "lightning": "5", "ice": "6", "shadow": "7", "light": "8", "arcane": "9", "nature": "10", "fire": "11", } element = elements[element.lower()] if dragon1.isdigit(): pass else: dragon1 = fr.extract_dragon_id(dragon1) if dragon2.isdigit(): pass else: dragon2 = fr.extract_dragon_id(dragon2) outcomes = await fr.get_progeny(dragon1, dragon2, 5) image_data = [] async with aiohttp.ClientSession( ) as session: # Create an AIOHTTP session links = [] for dragon in outcomes: components = urlparse(dragon) parameters = dict(parse_qsl(components.query)) del parameters["auth"] del parameters["dummyext"] parameters["age"] = "0" parameters["element"] = element parameters["_token"] = FlightRisingC.token async with session.post(FlightRisingC.cprogeny_url, data=parameters, headers=self.headers) as response: if response.status == 200: content = await response.read() content = json.loads(content) links.append("https://www1.flightrising.com" + content["dragon_url"]) for link in links: async with session.get(link, headers=self.headers) as response: if response.status == 200: content = await response.read() content = io.BytesIO(content) image_data.append(content) image = generate_image(image_data, 5) output_buffer = io.BytesIO() # Convert the PIL output into bytes image.save(output_buffer, "png") # Save the bytes as a PNG format output_buffer.seek(0) await ctx.send(file=discord.File(fp=output_buffer, filename="pet.png"))
def test_valid_link(self): assert (extract_dragon_id( "http://flightrising.com/main.php?p=lair&id=430187&tab=dragon&did=52548928" ) == "52548928")
def test_invalid_link(self): assert (extract_dragon_id( "http://www1.flightrising.com/lair/430187/419524/1") is None)
def test_results(): assert extract_dragon_id('http://flightrising.com/main.php?p=lair&id=430187&tab=dragon&did=52548928') == '52548928'