Fix pals with multiple element types and also dynamically color the embed

This commit is contained in:
Luke Robles 2024-01-25 16:30:18 -08:00
parent 9e2b513273
commit 1b4dabad6c

View File

@ -52,22 +52,38 @@ class PalWorld(commands.Cog):
response = requests.get(pal_url)
soup = BeautifulSoup(response.text, "html.parser")
color_lookup = {"Fire": discord.Color.red()}
elements = {}
pal_element_badge = soup.find("img", class_="rounded-full w-12 px-2 py-2")
element_text = pal_element_badge.find_next("p").text
element_icon = "https://paldex.io" + pal_element_badge["src"]
pal_elements = soup.find("div", class_="flex flex-row flex-wrap gap-3")
for div in pal_elements:
pal_element_badge = div.find("img", class_="rounded-full w-12 px-2 py-2")
element_type = pal_element_badge.find_next("p").text
element_icon = "https://paldex.io" + pal_element_badge["src"]
elements[element_type] = element_icon
primary_element = list(elements.keys())[0]
color_lookup = {
"Fire": discord.Color.red(),
"Grass": discord.Color.green(),
"Earth": discord.Color.greyple(),
"Water": discord.Color.dark_blue(),
"Ice": discord.Color.blue(),
"Dragon": discord.Color.purple(),
"Neutral": discord.Color.lighter_grey(),
"Electricity": discord.Color.yellow(),
}
embed = discord.Embed(
description="-------",
color=discord.Color.blue(),
color=color_lookup[primary_element],
type="rich",
title=pal,
)
embed.set_author(
name=element_text,
icon_url=element_icon,
name=", ".join(elements.keys()),
icon_url=elements[primary_element],
url=pal_url,
)