From 1b4dabad6c3818e013fd986141f09f6007a56889 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 25 Jan 2024 16:30:18 -0800 Subject: [PATCH] Fix pals with multiple element types and also dynamically color the embed --- app/cogs/palworld.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/app/cogs/palworld.py b/app/cogs/palworld.py index 1ad7814b..66237dad 100755 --- a/app/cogs/palworld.py +++ b/app/cogs/palworld.py @@ -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, )